If you guys can answer one or two questions i will be so happy.
1. (9 points) Given the following variable declarations and assignments, what do the following C++ statements evaluate to? If the answer is an integer, indicate so by writing your answer as an integer (without a decimal point). If your answer is a floating-point number., indicate so by writing the decimal point – for example, if the answer is 2 but it’s a type double, then write 2.0
int i = 5, j = 15;
double x = 45, y = -0.5;
_____ j % i
_____ i % j
_____ x / j
_____ x / i
_____ i / y
_____ i / j
_____ j / i
_____ 1 / i * y
_____ y * 5 / j
2. (4 points) Mark the following statements as true or false.
a. ____ Programs begin execution in a function called iostream
b. ____ You must have one or more function called main in your program
c. ____ The command we use to compile and link our programs is g++
d. ____ The operating system we are using on PSTCC11 is Windows 7.
3. (4 points) List at least four of the five major components of a computer.
4. (2 points) The process that combines the object code of your program with the object code for routines that your program uses (e.gs., for input and output) is called: _______________________.
5. (5 points) Declare variables for the following:
• A constant initialized to 8 that indicates the number of planets in our solar system.
• A variable to hold the number of moons of some planet
• A variable to hold the distance of a planet from the sun in light years.
• A variable to indicate whether a planet is an inner planet or not
• A variable to hold the name of a planet like “Earth”
6. (5 points) Assign values (with assignment statements) to the above variables of problem 4.
7. (6 points) Given the following code, indicate with an X in the appropriate table cell where a variable name is visible (what its scope is).
using namespace std;
const int MAX_STUDENTS = 26;
int i, j;
i = f( i, j );
int f( int i, int& jRef )
8. (5 points) Write a function called bmi that calculates and returns a person’s BMI (Body Mass Index). The function has two parameters: height in meters and weight in kilograms. The formula to compute BMI is listed below where w is weight in kilograms and h is height in meters:
9. (6 points) Write a code segment that computes the sum 1/1 + ½ + … + 1/n where n is an integer that already has a value from the user. (You do not have to write code to declare n or give it a value.)
10. (8 points) Write a C++ code segment that asks the user for a number between 1 and 10, inclusive. If the user enters a number outside this range, print an error message and continue asking the user for a number while they enter one that is outside this range.
11. (7 points) Write a C++ statement to calculate the following formula using C++ library functions.
int a, b;
double x, y, z;
12. (4 points) Assume that the function bmi is overloaded – there is another function called bmi that computes the Big Mac™ Index, an economic index representing the price difference of a Big Mac™ sandwich in two different countries. This function has two integer parameters, the cost in US cents of a Big Mac™ in two different countries. Given the function calls below, indicate which bmi function gets called by writing either “Body Mass” or “Big Mac” next to the call. Assume the declared variables below have valid values by the time of the calls.
int i, height, weight;
double x, y, z;
_________________ x = bmi( 1.89, 82.9 );________________ x = bmi ( 299, 345 );
_________________ x = bmi( height, weight ):_______________ x = bmi( i, y );
13. (10 points) Write a function called swap that has 2 double parameters. This function swaps the values of the actual parameters so that they are changed in the calling function.
14. (25 points) Write a complete C++ program (you don’t have to include comments just for time’s sake, but you do need to include everything else) that gets a planet’s name and distance from the sun in light years. Use the table below to determine what message to print out and print it where ____ is filled in with the planet’s name. (Note: “[“ or “]” means inclusive and “(“ or “)” means exclusive.)
We don't outright give answers to questions, especially ones that appear to be mid-term or final exam questions. Please attempt to do these problems, and show what you have worked out so far. We can help on specifics, but won't just give answers.