Please Help! Using C++, give code, thanks! 3. Using cout, the endl Manipulator,
ID: 3691050 • Letter: P
Question
Please Help! Using C++, give code, thanks!
3. Using cout, the endl Manipulator, and Common Escape Sequences
1. Describe what is displayed when the program processes each of the following lines of code: const double PI = 3.1416; double radius = 2.5; cout << “The area of the circle is ” << PI * radius * radius << endl;
2. Write the appropriate C++ statement to match the description in each of the following comments:
// declare an integer variable for the width of a rectangle
// declare an integer variable for the length of a rectangle
// prompt the user for the width and length
// input the width and length values
// output the area of the rectangle found by multiplying length times width
3. Write the appropriate C++ statement to match the description in each of the following comments:
// declare three double variables called num1, num2, num3
// declare a variable called average
// ask the user to input values separated by a space for 3 values
// input the values into num1, num2, num3
// assign average the value of num1, num2, and num3 divided by 3
// output a statement with a message describing the values input and the average
4. Write the appropriate C++ statements to match the descriptions in the following comments:
// declare two integer variables feet and inches
// ask the user how many feet and inches tall they are (no fraction)
// input the feet and inches
// assign inches the value of inches plus feet times 12
// output with an appropriate message the number of inches the person is tall 5. Write the output of the following code. int x = 2, y = 3, z = 5; cout << “This is my report in columns ” << ‘ ’ << x << ‘ ’<< x * x << endl << ‘ ’ << y << ‘ ’ << y * y << endl << ‘ ’ << z << ‘ ’ << z * z << endl;
Explanation / Answer
#include<iostream>
using namespace std;
int main(){
//1
const double PI = 3.1416;
double radius = 2.5;
cout << "The area of the circle is " << PI * radius * radius << endl;
//2
int width;
int length;
cout<<"Enter length and width: ";
cin>>width>>length;
cout<<"Area of rectangle is "<<width*length<<endl;
//3
double num1, num2, num3;
double average;
cout<<"Enter three values: ";
cin>>num1>>num2>>num3;
average = (num1+num2+num3)/3;
cout<<"Average of "<<num1<<", "<<num2<<", and "<<num3<<" is "<<average<<endl;
//4
int feet, inch;
cout<<"how many feet and inches tall they are (no fraction): ";
cin>>feet>>inch;
inch = inch + 12*feet;
cout<<"Number of inches you are tall is "<<inch<<endl;
//5
int x = 2, y = 3, z = 5;
cout << "This is my report in columns " << ' ' << x << ' '<< x * x << endl << ' ' << y << ' ' << y * y << endl
<< ' ' << z << ' ' << z * z << endl;
return 0;
}
/*
Output:
The area of the circle is 19.635
Enter length and width: 12
15
Area of rectangle is 180
Enter three values: 23.23
34.43
54
Average of 23.23, 34.43, and 54 is 37.22
how many feet and inches tall they are (no fraction): 23
13
Number of inches you are tall is 289
This is my report in columns
2 4
3 9
5 25
*/