Question: Type in the hello world program shown on the board, compile it and get it to run. write the program using C. // ------------------------------------------------------------------------------------------ //
- Type in the hello world program shown on the board, compile it and get it to run. write the program using C.
// ------------------------------------------------------------------------------------------
// Name: Your name here
// Class: C++ 1
// Abstract: Homework 1.
// ------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------
// Includes
// ------------------------------------------------------------------------------------------
#include
#include
// ------------------------------------------------------------------------------------------
// Constants
// ------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------
// Prototypes
// ------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------
// Name: main
// Abstract: This is where the program starts
// ------------------------------------------------------------------------------------------
void main( )
{
printf( Hello World );
}
Step 2
- Modify the program in step 1 so that it will print the minimum and maximum values for the following data types:
- short
- integer
- long
- float
- Be sure to:
- Verify that maximum and minimum values by adding or subtracting one and then printing.
- Make your code readable.
- Make the output readable.
- Use the printf statement to output your answers.
- The printf format specifiers match the data type.
- You cannot use the built-in limits if you know what those are.
- Be sure to test the minimum and maximum values for each data type by subtracting 1 and adding 1 and then printing out the variables again. For example:
shtMinimum = shtMinimum 1;
System.out.println( "Short Minimum Confirmation: " + shtMinimum + " " );
- What happens if you go past the minimum or maximum?
Put you answers in comments in the program for each data type.
Minus 25% for missing answers or incorrect answers.
- You must declare and set a variable to hold each value. You cannot simply hardcode the values into the printf statement. For example:
// Bad Code Example
printf( Short Maximum: 32767 ); // This is not allowed. You must use a variable.
// Good Code Example
// Declare variables
short shtMinimum = 0;
short shtMaximum = 0;
// Set to min/max values
shtMinimum = 100 ;
shtMaximum = 100 ;
// Short
printf( Short Minimum and Maximum );
printf( ------------------------------------------------ );
printf( Short Minimum: %hd , shtMinimum );
printf( Short Maximum: %hd , shtMaximum );
printf( );
shtMinimum =1;
shtMaximum +=1;
printf( Confirmation );
printf( Short Minimum: %hd , shtMinimum );
printf( Short Maximum: %hd , shtMaximum );
printf( );
Extra Credit
Make procedures for each data type. For example:
void main( )
{
DisplayShortMinimumAndMaximum( );
DisplayIntegerMinimumAndMaximum( );
...
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
