Write and display a single C++ program that has BOTH PARTS (PLEASE SHOW ALL OUTP
ID: 3789492 • Letter: W
Question
Write and display a single C++ program that has BOTH PARTS (PLEASE SHOW ALL OUTPUT):
1. Using C++, write the first part of the program to display the following as separate sentences:
• Full name as "John Doe" (Use a string literal)
• The age in years as "32 years old" (Use a variable of data type int)
• The month of birth as "April" (Use a string literal)
• The favorite movie as "Source Code" (Use a string literal)
• The letter "A" grade to hope to earn in the class (use a variable of data type char)
2. Using C++, calculate and display the total amount of money from the coins below (use a variable of data type int):
5 half dollars --- (5 * 50¢)
30 quarters ---- (30 * 25¢)
99 dimes ---- (99 * 10¢)
12 nickels ----- (12 * 5¢)
18 pennies ------ (18 *1¢)
The output must include a banner and be similar to the picture as shown below:
PLEASE SHOW ALL WORK in a reproducible format for Microsoft Visual Studio to receive points
Explanation / Answer
#include <iostream>
using namespace std;
int main()
{
string name = "John Doe";
int age = 32;
string month = "April";
string movie = "Source Code";
char letterGrade = 'A';
cout<<"My Name is "<<name<<"."<<endl;
cout<<"I am "<<age<<" years old."<<endl;
cout<<"I was born in the month of "<<month<<"."<<endl;
cout<<"My favorite movie is "<<movie<<"."<<endl;
cout<<"I would like to earn a grade of "<<letterGrade<<" in this course"<<endl;
int totalAmount = 0;
totalAmount = totalAmount + (5 * 50);
totalAmount = totalAmount + (30 * 25);
totalAmount = totalAmount + (99 * 10);
totalAmount = totalAmount + (12 * 5);
totalAmount = totalAmount + (18 * 1);
cout<<"I have $ "<<totalAmount<<" in coins."<<endl;
return 0;
}
Output:
sh-4.2$ g++ -o main *.cpp
sh-4.2$ main
My Name is John Doe.
I am 32 years old.
I was born in the month of April.
My favorite movie is Source Code.
I would like to earn a grade of A in this course
I have $ 2068 in coins.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.