Develop a flowchart and then write a C++ program using the operators shown and t
ID: 3671077 • Letter: D
Question
Develop a flowchart and then write a C++ program using the operators shown and the if statements to solve the following program.
a. Upon execution of the program, your first name and the last name will be displayed at the top of the screen, properly centered. Your name will appear as in John Doe and not J. D. and it is not in block letters.
b. The program will then prompt the user for two integer inputs and the program will then compute the sum and the quotient of the two numbers and produce the results of both operations with appropriate labels. See sample output for the addition operation below. The output assumes a = 3, and b = 6. Part b requires no if statements. Sum of a and b is equal to a + b or 3 + 6 and the result is 9 Quotient of a and b is equal to a / b or 3 / 6 and the result is 0
c. The program will then use the same two integer numbers and perform the following operations. The program uses if statements and displays the relations between the two numbers for the following relational operators: Each of these operators requires two operands: use the first integer number as the first operand and the second integer number as the second operand. See sample of output desired below. a <= b is 3 <= 6 and the result is true where a is the first number and b is the second number. Your solution will work for any two integer numbers. The same format is used for the other two relational operators. The state of the result is reported via strings true or false. Part c requires if statements.
(d) The program will then use the same two integer numbers and computes different operations using the following arithmetic and logical operators: +=, *=, || The result of these operations is stored in the first operand. See example below. a += b is 3 += 6 and the result is a = 9 Note that a = 9 is used in the next operation. or a *= b is 9 *= 6 and the result is a = 54 Note that a new value of a is used after each operation (i.e. a is rippled to other operations).
Explanation / Answer
/**C++ program that prompts user to enter two values
and performs the calculations
part-a, part-b, part-c and part-d on two values of a and b
variables */
#include<iostream>
#include<string>
using namespace std;
int main()
{
//declare two integer variables
int a;
int b;
//part-a
string firstName="John";
string lastName="Doe";
//print name
cout<<"Name : "<<firstName<<" "<<lastName<<endl;
//part-b
cout<<"Enter a value: ";
//read a vlaue
cin>>a;
cout<<"Enter b value: ";
//read b value
cin>>b;
//prit sum
cout<<"Sum "<<a<<"+"<<b<<"="<<(a+b)<<endl;
//print quotient
cout<<"Quotient "<<a<<"/"<<b<<"="<<a/b<<endl;
//part-c
//Check if a is less than or equal to b
if(a<=b)
cout<<a<<"<="<<b<<endl;
//Check if a is greater than or equal to b
else if(a>=b)
cout<<a<<">="<<b<<endl;
//otherwise equal
else
cout<<a<<" == "<<b<<endl;
//part-d
cout<<a<<" += "<<b<<"= ";
//Add value of b to a and assign to a
a+=b;
cout<<a<<endl;
cout<<a<<" *= "<<b<<"= ";
//Multiplye value of b to a and assign to a
a*=b;
cout<<a<<endl;
//|| is logical or operation
//54 is the result of a=3 and b=6 sample values
//54 is greater than 1 and 6 is greater than 1 and result
//of the 54 || 6 operation is true
cout<<a<<"||"<<b<<" = "<<(a||b)<<endl;
//pause the program output on console until user enters a value
system("pause");
return 0;
}
------------------------------------------------------------------------------------------------------------------------------
Sample Output:
Name : John Doe
Enter a value: 3
Enter b value: 6
Sum 3+6=9
Quotient 3/6=0
3<=6
3 += 6= 9
9 *= 6= 54
54||6 = 1
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.