Write two short c programs and solve four exam-style

Assignment Help C/C++ Programming
Reference no: EM13346954

Write two short C programs and solve four exam-style problems.

Details on the programs are as follows.

Program : builddbl.c

This program takes four inputs representing the sign, exponent, and integer and fractional parts of the significand of a double. The significand M will look like d.xxxxxxxxxxxxx where each x is a hexadecimal digit. The digit d left of the "decimal point" is the integer part of the M. It is 1 for normalized doubles and 0 for denormalized doubles. It will not appear directly in the double you build, but it will affect the exponent. The thirteen x's represent the fractional part of the double. Your program should use the four parts to construct a double and print it both as a double (using %.17g format) and its 16-digit hexadecimal representation. Your program need not deal with infinity or NaN (not a number), but it should deal properly with both normalized and denormalized doubles. Here are some sample outputs to show the behavior of this program:

As with assignment #1 I want you to write both programs with main functions that take care of command line inputs and printing the output. The main funcitons will call auxiliary functions to do the work of assembling or disassembling the double's. These auxiliary functions will use a C structure to hold the parts of adouble. The definition of the structure and the declarations of the auxiliary functions are given in hw2.h. You should include it in your programs with the following statement: #include "hw2.h". Note the change in punctuation. Library headers are written <stdio.h> , while headers from your own directory are written"hw2.h".

Also included in hw2.h are declarations for two functions d2ll and ll2d given below. These functions convert double to long long int and back again without changing the bit pattern. You will use them to convert your double's to long long int's before taking them apart using integer arithmetic. You will build yourdouble's using integer arithmetic to make a long long int with the desired bit pattern. Then you convert it to a double as a last step. If the inputs are invalid and you cannot build the double, your auxiliary function should return NaN (Not a Number) which I have defined in hw2.h.

When your auxiliary functions compile successfully and run correctly on a few test inputs you should submit them to the grading server just as you did with functions h2d and d2h in assignment #1.

Instructions are given below.

> builddbl
Usage: builddbl sign, E, intpart, fracpart (parts of a double)
> builddbl + 1023 1 fffffffffffff
value = 1.7976931348623157e+308 (7fefffffffffffff)
> builddbl - 0 1 0000000010000
value = -1.0000000000145519 (bff0000000010000)
> builddbl + -2 1 e62433b79890d
value = 0.47474747474747475 (3fde62433b79890d)
> builddbl - -1022 0 0000000314159
value = -1.594840446316023e-317 (8000000000314159)
> builddbl - -1022 1 0000000314159
value = -2.220738601020418e-308 (8010000000314159)
> builddbl + 10 2 fffff00000ddd
Usage: sign(+ or -), E(-1022 to +1023), d(0 or 1), f(13 hex digits)
Build failed
> builddbl + -1023 1 0000000000000
Usage: sign(+ or -), E(-1022 to +1023), d(0 or 1), f(13 hex digits)
Build failed
> builddbl + -1021 0 7777777777777
Invalid parts for normalized double
Build failed
> builddbl + 1024 1 0000020000000
Usage: sign(+ or -), E(-1022 to +1023), d(0 or 1), f(13 hex digits)
Build failed

Your code should always print an error message if a command line input is not of the proper form or a value is out of the proper range. If f is given with more than 13 hex digits, you may just use the last 13 digits.

Program #2 : dblparts.c

This program is roughly the inverse of Program #1. It takes a list of doubles and prints out the parts: sign, exponent, and integer and fractional parts of the significand. Here are some sample outputs:

>dblparts
Usage: dblparts f1 f2 f3 ... (list of floating point numbers)

>dblparts .47474747474747475 -1.594840446316023e-317 -1.7976931348623157e308
input 1 = .47474747474747475
sign = +, E = -2 intpart = 1 fracpart = e62433b79890d

input 2 = -1.594840446316023e-317
sign = -, E = -1022 intpart = 0 fracpart = 0000000314159

input 3 = -1.7976931348623157e308
sign = -, E = 1023 intpart = 1 fracpart = fffffffffffff

Try to make your output look as close to these sample outputs as possible.

Here are two functions that you might find useful. The function ll2d turns a long long int into a double with the same bit pattern. The function d2ll turns a double into an long long int with the same bit pattern. This is a different result than you get with a cast: ll2d(x) != (double)x . Try to figure out how they work, but that is not part of this homework:

double ll2d(unsigned long long int l)

/* convert 64-bit integer to double with same bit pattern */

{
union {
double dd;
unsigned long long int ll;
} a;
a.ll = l;
return a.dd;
}

unsigned long long int d2ll(double d)

/* convert double to 64-bit integer with same bit pattern */

{
union {
double dd;
unsigned long long int ll;
} a;
a.dd = d;
return a.ll;
}

The problems that go with this assignment are the Piazza Resources page: Problems_2.rtf. Fill in the answers and put it in your drop box.

Reference no: EM13346954

Questions Cloud

Note use visual basic 2010visual basicassignment1 nbsp : note use visual basic 2010visual basicassignment1 nbsp nbspticketsellerthis assignment will contain two 2 parts event
National securitynbsp please respond to the followingselect : national securitynbsp please respond to the followingselect any two of the four basic strategies used to preserve
1 consider that on a certain day 495 passengers want to fly : 1 consider that on a certain day 495 passengers want to fly from honolulu hnl to new york jfk 605 passengers want to
The two major modifications are the instruction of pointers : the two major modifications are the instruction of pointers and the calculation of mortgage interest rates.requirements
Write two short c programs and solve four exam-style : write two short c programs and solve four exam-style problems. details on the programs are as follows.program
Wal-mart company financial analysisthe company should be : wal-mart company financial analysisthe company should be traded on nasdaq or nyse. big us companies have data widely
Prepare a report of on state bank of india sbi after going : prepare a report of on state bank of india sbi after going through the harvard business school case study.task
Leadership resources effective leaders stay up to date on : leadership resources effective leaders stay up to date on leadership research and theory while taking a critical eye to
Can social media be used as a marketing tool to influence : can social media be used as a marketing tool to influence consumer buyer behaviours in london?introductionresearch

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd