You will create 3 files:
"main.cpp" , "printme.h" and "printme.cpp"
In "printme.cpp" include the header files "iostream" and "printme.h" . Also include the line:
using namespace std ;
Write a function
void printme()
that uses "cout" to print "Hello World" to the screen.
The file "printme.h" will contain the declaration of this function "printme" .
In the file "main.cpp" include this file "printme.h" and call the function "printme" . Compile the 2 files "main.cpp" and "printme.cpp" to produce a single executable.
You may compile using the "make" utility or the command:
g++ -o hello.exe main.cpp printme.cpp
After the execution command run the command:
whoami
on the console. Take the source code for the 3 files and paste in a word document.
Take the snapshot of the compilation, execution and "whoami" output and paste in the
same word document. Submit the word document to canvas.
Run the executable to make sure the programming is running properly.
An oil barrel contains 42 gallons . A gallon contains 4 quarts. One quart contains 2 pints. Write a program that asks the user for an input in pints and then prints the number of barrels, gallons , quarts and pints.
If you need to you can use the modulus operator in C++ ( It gives you the remainder ). The operator is "%" .
Ex: 8 % 3 will give you 2
Run your program multiple times with the following inputs( 0 , 347, 8, 50 )
[amittal@hills hw2]$ ./a.out
Please enter the number of pints to convert:0
Number Of barrels: 0
Number Of gallons: 0
Number Of quarts: 0
Number Of pints: 0
[amittal@hills hw2]$ ./a.out
Please enter the number of pints to convert:347
Number Of barrels: 1
Number Of gallons: 1
Number Of quarts: 1
Number Of pints: 1
[amittal@hills hw2]$ ./a.out
Please enter the number of pints to convert:8
Number Of barrels: 0
Number Of gallons: 1
Number Of quarts: 0
Number Of pints: 0
[amittal@hills hw2]$ ./a.out
Please enter the number of pints to convert:50
Number Of barrels: 0
Number Of gallons: 6
Number Of quarts: 1
Number Of pints: 0
Fill out the missing code in the below program. Do not hardcode the output ( Do not hard code the length of the strings but use C++ functions to compute the length ) .
//-------------------------------------------------------------
#include <iostream>
using namespace std ;
int main()
{
string str1 = "This is hw 3." ;
char str2[] = "I can do this." ;
//To do Use the length function of the string object and the function
// strlen for the character array. Include appropriate header files.
//To do
//Print 2 to the power 4 Use the pow function
}
//-------------------------------------------------------------
The output should be:
[amittal@hills hw3]$ ./a.out
This is hw 3. The length of str1 is:13
I can do this. The length of str2 is:14
2 to the power 4 is:16