MECH 215 Study Guide - Midterm Guide: Keith Richards, Metic, Switch Statement

158 views7 pages
1
Instructions: Answer ALL questions. Questions 1, 2, and 3 are MULTIPLE CHOICE. You are
asked to write a complete program for Question 4. Provide the output generated by the program
given in Question 5.
Materials Allowed: C++ textbook, course notes, electronic calculators, pencils, pens, erasers.
QUESTION 1: [20 points]
(A) Consider the following innocuous C++ program :
#include <iostream>
#include <string>
using namespace std;
int main()
{
double celsius, fahrenheit;
const double thirty_two_degrees = 32.0;
cout << "Please enter the temperature in degrees Fahrenheit ";
cin >> fahrenheit;
celsius = (5/9) * (fahrenheit - thirty_two_degrees);
cout << "The temperature in degrees Celsius is " << celsius <<
endl;
return 0;
}
If the user types in a value of 120.6 for the value of the variable called fahrenheit, the pro-
gram output will be:
(a) The temperature in degrees Celsius is 49.222222
(b) The temperature in degrees Celsius is 0
(c) Segmentation fault
(d) The program produces no output as it will not compile.
(e) Keith Richards
(f) Brrrrr. it is cold today
(B) Consider the following variation on the introductory "Hello World" program:
#include <iostream>
#include <string>
using namespace std;
int main()
Unlock document

This preview shows pages 1-2 of the document.
Unlock all 7 pages and 3 million more documents.

Already have an account? Log in
2
{
cout << "Keith Richards is" ;
cout << "elegantly wasted" << endl ;
return 0;
}
The output produced by this program is:
(a) Keith Richards is
elegantly wasted
(b) Keith Richards is elegantly wasted
(c) Keith Richards iselegantly wasted
(d) Madonna, Britney Spears, Celine Dionne all have no talent, Mick is a knight.
(e) Why do I have to learn C++ if I want to be a Mechanical Engineer?
(C) Consider the following program:
#include <iostream>
#include <string>
using namespace std;
int main()
{
cout << "Keith Richards is" << endl ;
cout << "elegantly wasted << endl ;
return 0;
}
The output produced by the program is:
(a) Keith Richards is
elegantly wasted
(b) The program does not compile.
(c) A run-time error occurs
(d) Keith Richards is elegantly wasted
Unlock document

This preview shows pages 1-2 of the document.
Unlock all 7 pages and 3 million more documents.

Already have an account? Log in

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers

Related Documents