a. Write C++ statements that include the header files iostream and string. b. Wr
ID: 665998 • Letter: A
Question
a. Write C++ statements that include the header files iostream and string.
b. Write a C++ statemtn that allows ou to use cin, cout, and endl without the prefix std::
c. Write C++ sttemetn that declare the following variables: name of type string and studyhours of type double
d. Write C++ statements that prompt and input a string into name and a double value into studyhours
e. Write a C++ statement that outputs the values of name and studyhours with the appropriate text. For example, if the value of name is “Donald” and the value of studyhours is 4.5, the output is:
Hello, Donald! on Saturday, you need to study 4. 5 hours for the exam.
f. Compile and fun your program.
Explanation / Answer
/*a.Write C++ statements that include the header files iostream and string.*/
#include<iostream>
#include<string>
/*b.Write a C++ statement that allows ou to use cin, cout, and endl without the prefix std::*/
using namespace std;
int main()
{
/*c.Write C++ statement that declare the following variables: name of type string and studyhours of type double*/
string name;
double studyhours;
/*d.Write C++ statements that prompt and input a string into name and a double value into studyhours*/
cout<<"enter name:";
cin>>name;
cout<<"enter study hours:";
cin>>studyhours;
/*e.Write a C++ statement that outputs the values of name and studyhours with the appropriate text. For example, if the value of name is “Donald” and the value of studyhours is 4.5*/
cout<<"Hello, "<<name<<"! on Saturday you need to study "<<studyhours<<" hours for the exam";
return 0;
}
Sample Output:
enter name:raghurams
enter study hours:4.5
Hello, raghurams! on Saturday, you need to study 4.5 hours for the exam.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.