59.4k views
1 vote
Consider the following program segment: //include statement(s) //using namespace statement int main() { //variable declaration //executable statements //return statement }

a) Write C11 statements that include the header files iostream and string.
b) Write a C11 statement that allows you to use cin, cout, and endl without the prefix std::.
c) Write C11 statements that declare the following variables: name of type string and studyHours of type double.
d) Write C11 statements that prompt and input a string into name and a double value into studyHours.

User Petrroll
by
6.4k points

2 Answers

4 votes

Final answer:

The answer provides the necessary C11 statements to include headers iostream and string, use namespace std, declare variables of type string and double, and how to prompt and read input.

Step-by-step explanation:

To address the student's question:

  • a) Write C11 statements that include the header files iostream and string.

You can include the necessary header files with the following C11 statements:

#include <iostream>
#include <string>
  • b) Write a C11 statement that allows you to use cin, cout, and endl without the prefix std::.

To use the standard library objects without the std prefix:

using namespace std;
  • c) Write C11 statements that declare the following variables: name of type string and studyHours of type double.

To declare the variables name and studyHours:

string name;
double studyHours;
  • d) Write C11 statements that prompt and input a string into name and a double value into studyHours.

To prompt and input a string and a double value:

cout << "Enter your name: ";
cin >> name;
cout << "Enter study hours: ";
cin >> studyHours;

User Milan Raval
by
6.8k points
2 votes

Answer:

a. Write C++ statements that include the header files iostream and string.

#include <iostream>

#include <string>

b. Write a C++ statement that allows you to use cin, cout, and endl without the prefix std::.

To use cin and cout, one must first declare at least one variable. At this point, I'll assume that the variable has been declared already I'll name my variable "test" without the quotes.

cin>>test;

cout<<test<<endl;

c. Write C++ statements 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.

string name;

double studyHours;

cout>>"What's your name?";

cin<<name;

cout<<"What's your study hours?";

cin>> studyHours;

PS: A full program in C++ that illustrates the above

#include <iostream>

#include <string>

using namespace std

int main()

{

string name;

double studyHours;

cout>>"What's your name?";

cin<<name;

cout<<"What's your study hours?";

cin>> studyHours;

cout<<"Hello "<<name<<", your study hour is "<<studyHours;

return 0;

}

User Dallion
by
5.5k points