Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Answer the following questions WRITTEN and scanned to a PDF. If you type the cod

ID: 3883168 • Letter: A

Question

Answer the following questions WRITTEN and scanned to a PDF. If you type the code, you will lose

points. The reason is you will need to write code on exams and need to be used to handwriting syntax.

Make sure you write legibly. If we cannot decipher what you have written, we may deduct points.

Total points for the assignment: 50 points

1. (5 points) What #include is needed in order to use the function std::sort?

2. (5 points) What #include is needed in order to use the function std::getline?

3. (5 points) What #include is needed in order to use the class std::ifstream?

4. (5 points) What #include is needed in order to use the function std::stoi?

5. (5 points) Suppose you have a variable of type std::ifstream named inFile. Write the line

of code to call the method open on inFile that opens the input file named input.txt in

binary mode.

6. (15 points) Consider the following code:

1. #include <string>

2. #include <iostream>

3.

4. int main() {

5. std::string line;

6. double temperature;

7. // ---- CODE HERE ----

8.

9.

10.

11. // -------------------

12. }

Write 3 lines of code to do the following:

(6a) Write line 7 of the code that would print out the message "Enter the temperature:" in

the above example. You should have a new line follow the message.

(6b) Write line 8 of the code that would use the std::getline function with std::cin to

store a line in the string line.

(6c) Write line 9 of the code that would convert the text stored in the string line to a

number of type double and store it in variable temperature.

CSE 250 Fall 2017

7. (10 points) Consider the following code:

1. #include <iostream>

2.

3. int main() {

4. // ---- CODE HERE ----

5.

6.

7.

8. // -------------------

9. }

Complete the body of the main function above (not necessarily 3 lines of code) to print out the

following using a for loop:

The countdown:

T-10 seconds

T-9 seconds

T-8 seconds

--- (continue the pattern)

T-2 seconds

T-1 second

Blast off!

The output would be 12 lines total, but you should write at most 10 lines of code.

Explanation / Answer

Hi, I have answered first 6 questions.

Please let me know in case of any issue.

Please repost other questions in separate post.

1.What #include is needed in order to use the function std::sort?

Ans: #include <algorithm>

2. What #include is needed in order to use the function std::getline?

Ans: #include <iostream>

3. What #include is needed in order to use the class std::ifstream?

Ans: #include <fstream>

4. What #include is needed in order to use the function std::stoi?

Ans: #include <string>

5. Suppose you have a variable of type std::ifstream named inFile. Write the line

of code to call the method open on inFile that opens the input file named input.txt in

binary mode.

Ans: inFile.open("input.txt", ios::binary);

6. (15 points) Consider the following code:

#include <string>

#include <iostream>

int main() {

std::string line;

double temperature;

// ---- CODE HERE ----

//(6a)

cout<<"Enter the temperature:"<<endl;

//(6b)

getline(cin, line);

//6c

temperature = stod(line);

// -------------------

}