#include<iostream>#include<string>usingnamespace std;intmain(){
string name;
cout<<"Enter the string"<<endl;getline(cin,name,'$');//It terminates the//input at the 4 sign and print the full line
cout<<name;return0;}
To see the assignment in pdf form
Practice these questions by yourself then see codecheets😂
********************************
The oval is printed as:********************
The arrow os printted as:***************
The diamond is printted as:****************
Task 2. (Digits of an Integer) Write a program that inputs a five-digit integer, separates the integer into
its digits and prints them separated by three spaces each. [Hint: Use the integer division and
modulus operators.] For example, if the user types in 42339, the program should print:
4 2 3 3 9
(Table) Using the techniques learned in class until now, write a program that calculates the
squares and cubes of the integers from 0 to 5.
Use tabs to print the following neatly formatted table of values:
Integer square cube
0 0 0
1 1 1
2 4 8
3 9 27
4 16 64
5 25 125
#include<iostream>#include<cmath>usingnamespace std;intmain(){//Digits of a numberint num1=0;int rem1=0;/*All values are initialize to zero to overwrite the garbage value*/int rem2=0;int rem3=0;int rem4=0;int rem5=0;
cout<<"Enter the five-digit number:"<<endl;
cin>>num1;
cout<<"The given number is separated as:"<<endl;//Reminder 5
rem5=num1%10;//Reminder 4
num1=num1/10;
rem4=num1%10;//Reminder 3
num1=num1/10;
rem3=num1%10;//Reminder 2
num1=num1/10;
rem2=num1%10;//Reminder 1
num1=num1/10;
rem1=num1%10;//Seaparted numbers are printted as
cout<<rem1<<" "<<rem2<<" "<<rem3<<" "<<rem4<<" "<<rem5<<" "<<endl;//Table from 0 to 5
cout<<endl;
cout<<"Part-2:"<<endl;int num_1=1;int num2=2;int num3=3;int num4=4;int num5=5;
cout<<"Integer"<<"\t"<<"Square"<<"\t"<<"Cube"<<endl;
cout<<"1"<<"\t"<<pow(num_1,2)<<"\t"<<pow(num_1,3)<<endl;
cout<<"2"<<"\t"<<pow(num2,2)<<"\t"<<pow(num2,3)<<endl;
cout<<"3"<<"\t"<<pow(num3,2)<<"\t"<<pow(num3,3)<<endl;
cout<<"4"<<"\t"<<pow(num4,2)<<"\t"<<pow(num4,3)<<endl;
cout<<"5"<<"\t"<<pow(num5,2)<<"\t"<<pow(num5,3)<<endl;return0;}
Task 3.(Car-Pool Savings Calculator) Research several car-pooling websites. Create an application that
calculates your daily driving cost, so that you can estimate how much money could be saved by
car-pooling, which also has other advantages such as reducing carbon emissions and reducing
traffic congestion. The application should input the following information and display the user’s
cost per day of driving to work:
a) Total miles driven per day.
b) Cost per gallon of gasoline
c) Average miles per gallon.
d) Parking fees per day.
e) Tolls per day
#include<iostream>usingnamespace std;intmain(){float total_miles=0.0;float cost_per_gallon=0.0;float average_miles_per_gallon=0.0;int parking_fees=0;int tolls_per_day=0;double cost_per_day_of_driving=0.0;
cout<<"-----------------------------------------------------------------"<<endl;
cout<<"_______________________CAR-POOLING-CALCULATOR____________________"<<endl;
cout<<"-----------------------------------------------------------------"<<endl;
cout<<"Enter Total miles driven per day:"<<endl;
cin>>total_miles;
cout<<"Enter Cost per gallon of gasoline:"<<endl;
cin>>cost_per_gallon;
cout<<"Enter Average miles per gallon:"<<endl;
cin>>average_miles_per_gallon;
cout<<"Enter Parking fees per day:"<<endl;
cin>>parking_fees;
cout<<"Enter Tolls per day:"<<endl;
cin>>tolls_per_day;
cout<<endl;//Now calcualte cost_per_day_of_driving
cost_per_day_of_driving=((total_miles/average_miles_per_gallon)*cost_per_gallon)+parking_fees+tolls_per_day;
cout<<"The cost per day of driving to work = "<<cost_per_day_of_driving<<endl;return0;}
Task 4. Male and Female Percentages) Write a program that asks the user for the number of males and
the number of females registered in a class.
The program should display the percentage of males and females in the class.
#include<iostream>usingnamespace std;intmain(){int male=0;int female=0;int total=0;float male_per=0.0;float female_per=0.0;
cout<<"Class male and female percentage:"<<endl;
cout<<"_________________________________"<<endl;
cout<<"Enter the number of males in your class:"<<endl;
cin>>male;
cout<<"Enter the number of females in your class:"<<endl;
cin>>female;//Percentage Calculation
total=male+female;
male_per=((float)male/total)*100;
female_per=((float)female/total)*100;
cout<<"The total number of students in your classroom = "<<total<<endl;
cout<<"The percentage of males = "<<male_per<<endl;
cout<<"The percentage of females = "<<female_per<<endl;return0;}
Task 5. Ingredient Adjuster) A cookie recipe calls for the following ingredients:
• l.5 cups of sugar
• 1 cup of butter
• 2. 75 cups of flour
The recipe produces 48 cookies with this amount of the ingredients.
Write a program that asks the user how many cookies he or she wants to make, then displays the
number of cups of each ingredient needed for the specified number of cookies.
#include<iostream>#include<iomanip>usingnamespace std;intmain(){float cups_of_sugar=1.5;int cups_of_butter=1;float cups_of_flour=2.75;int total_cookies=48;int cookies=0;
cout<<"Ingrediant_Calculator:"<<endl;
cout<<"______________________"<<endl;
cout<<"Enter the number of cookies that you want to make:"<<endl;
cin>>cookies;//Ingrediants_Calculation
cups_of_sugar=(cups_of_sugar*cookies)/total_cookies;
cups_of_butter=((float)cups_of_butter*cookies)/total_cookies;
cups_of_flour=(cups_of_flour*cookies)/total_cookies;
cout<<"The ingrediants you need to make the "<<cookies<<" number of cookies :"<<endl;
cout<<"You need "<<setprecision(3)<<cups_of_sugar<<" cups_of_sugar"<<endl;
cout<<"You need "<<cups_of_butter<<setprecision(3)<<" cups_of_butter"<<endl;
cout<<"You need "<<cups_of_flour<<setprecision(3)<<" cups_of_flour"<<endl;return0;}
Task 6.(Box Office) A movie cheater only keeps a percentage of the revenue earned from ticket sales.
The remainder goes to the movie distributor.
Write a program that calculates a theater's gross and net box office profit for a night.
The program should ask for the name of the movie, and how many adult and child tickets were
sold.
(The price of an adult ticket is $10.00 and a child's ticket is $6.00.)
It should display a report similar to:
Assume the theater keeps 20 percent of the gross box office profit
.
The output is as follows:
Ingrediant_Calculator:
______________________
Enter the number of cookies that you want to make:700
The ingrediants you need to make the 700 number of cookies :
You need 21.9 cups_of_sugar
You need 14 cups_of_butter
You need 40.1 cups_of_flour
#include<iostream>#include<iomanip>usingnamespace std;intmain(){float cups_of_sugar=1.5;int cups_of_butter=1;float cups_of_flour=2.75;int total_cookies=48;int cookies=0;
cout<<"Ingrediant_Calculator:"<<endl;
cout<<"______________________"<<endl;
cout<<"Enter the number of cookies that you want to make:"<<endl;
cin>>cookies;//Ingrediants_Calculation
cups_of_sugar=(cups_of_sugar*cookies)/total_cookies;
cups_of_butter=((float)cups_of_butter*cookies)/total_cookies;
cups_of_flour=(cups_of_flour*cookies)/total_cookies;
cout<<"The ingrediants you need to make the "<<cookies<<" number of cookies :"<<endl;
cout<<"You need "<<setprecision(3)<<cups_of_sugar<<" cups_of_sugar"<<endl;
cout<<"You need "<<cups_of_butter<<setprecision(3)<<" cups_of_butter"<<endl;
cout<<"You need "<<cups_of_flour<<setprecision(3)<<" cups_of_flour"<<endl;return0;}
Task 7.If you have two fractions, a/b and c/d, their sum can be obtained from the formula
Thier output as:
-----------Fraction_Sum-----------
___________________________________
Enter the fraction 1:1/2
Enter the fraction 2:2/5
The sum of these two fractions =9/10
Write a program that encourages the user to enter two fractions, and then displays their sum in
fractional form.
(You don’t need to reduce it to lowest terms.) The interaction with the user might
look like this:
Enter first fraction: 1/2
Enter second fraction: 2/5
Sum = 9/10
You can take advantage of the fact that the extraction operator (>>) can be chained to read in
more than one quantity at once:
cin >> a >> dummychar >> b;
#include<iostream>usingnamespace std;intmain(){char dummy_char;int num1_N=0;int num1_D=0;int num2_N=0;int num2_D=0;int num1_to=0;int num2_to=0;int denominator=0;int numinator=0;
cout<<"-----------Fraction_Sum-----------"<<endl;
cout<<"___________________________________"<<endl;
cout<<"Enter the fraction 1:"<<endl;
cin>>num1_N>>dummy_char>>num1_D;
cout<<"Enter the fraction 2:"<<endl;
cin>>num2_N>>dummy_char>>num2_D;//calculations
num1_to=num1_N*num2_D;
num2_to=num2_N*num1_D;
numinator=num1_to+num2_to;
denominator=num1_D*num2_D;//Display
cout<<"The sum of these two fractions = "<<numinator<<"/"<<denominator<<endl;return0;}
Task 8. You can convert temperature from degrees Celsius to degrees Fahrenheit by multiplying by 9/5
and adding 32. Write a program that allows the user to enter a floating-point number
representing degrees Celsius, and then displays the corresponding degrees Fahrenheit.
#include<iostream>usingnamespace std;intmain(){constfloat constant=1.8;float celsius=0.0;float farhnheit=0.0;
cout<<"-------------Celsius to farhenheit--------"<<endl;
cout<<"___________________________________________"<<endl;
cout<<"Enter the temparature in celsius:"<<endl;
cin>>celsius;
farhnheit=(celsius*constant)+32;
cout<<"The temperature in the farhenheit = "<<farhnheit<<endl;return0;}
Task 9. By default, output is right-justified in its field. You can left-justify text output using the
manipulator setiosflags(ios::left). (For now, don’t worry about what this new notation means.)
Use this manipulator, along with setw(), to help generate the following output:
last Name First Name Street_Address Town State
-------------------------------------------------------------
Jones Bernard 109 Pine Lance Littletown MI
O'Brian Coleen 42 E.99th Ave. Bigcity NY
Wong Harry 121-A Alabama St.Lakeville IL
#include<iostream>#include<iomanip>usingnamespace std;intmain(){
cout<<setiosflags(ios::left)<<setw(12)<<"last Name"<<setiosflags(ios::right)<<setw(13)<<"First Name"<<setiosflags(ios::right)<<setw(17)<<"Street_Address"<<setiosflags(ios::right)<<setw(7)<<"Town"<<setiosflags(ios::right)<<setw(13)<<"State"<<endl;
cout<<"-------------------------------------------------------------"<<endl;//First
cout<<setiosflags(ios::left)<<setw(0)<<"Jones"<<setiosflags(ios::right)<<setw(17)<<"Bernard"<<setiosflags(ios::right)<<setw(20)<<"109 Pine Lance"<<setiosflags(ios::right)<<setw(13)<<"Littletown"<<setiosflags(ios::right)<<setw(5)<<"MI"<<endl;//Second
cout<<setiosflags(ios::left)<<setw(0)<<"O'Brian"<<setiosflags(ios::right)<<setw(14)<<"Coleen"<<setiosflags(ios::right)<<setw(22)<<"42 E. 99th Ave."<<setiosflags(ios::right)<<setw(9)<<"Bigcity"<<setiosflags(ios::right)<<setw(8)<<"NY"<<endl;//Third
cout<<setiosflags(ios::left)<<setw(0)<<"Wong"<<setiosflags(ios::right)<<setw(16)<<"Harry"<<setiosflags(ios::right)<<setw(25)<<"121-A Alabama St."<<setiosflags(ios::right)<<setw(7)<<"Lakeville"<<setiosflags(ios::right)<<setw(6)<<"IL"<<endl;return0;}
Task 10.A serial transmission line can transmit 960 characters a second. Write a program that will
calculate how long it will take to send a file, given the file's size. Try it on a 400MB (419,430,400
byte) file. Use appropriate units. (A 400MB file takes days.)
#include<iostream>#include<iomanip>usingnamespace std;
iint main(){constint characters_per_second=960;constint sizeOfCharacter_per_byte=1;longlongint file_bytes=419430400;longdouble days=0.0;
cout<<"------------File Sendig Time/400MB--------"<<endl;
cout<<"___________________________________________"<<endl;
cout<<"The size of the file is 400MB and sending speed is 960 characters_per_second:"<<endl;//calculation
days=(double)file_bytes/characters_per_second;//gives seconds
days=days/60;//gives minutes
days=days/60;//gives hours
days=days/24;//gives days//Display
cout<<"The number of days that it would take = "<<setprecision(2)<<days<<" days"<<endl;return0;}