Flip over this test on the back of this test write your


Part A

1. Flip over this test. On the back of this test write your name in the upper, left-hand corner.

2. What are the four parts of the compiling process (just give me 4 words, not a paragraph).

3. Which of the four steps of the compiling process occurs only once, regardless of the number of source files your application has?

4. Write a line of code that causes the preprocessor to generate an error.

5. Write a line of code that causes the compiler to generate an error.

6. Describe how you could incorrectly compile the joust project to cause the linker to generate an error.

7. Given:
1 float* fp;
2 //...
3 float pi;
4 pi=*(314 + fp);

Rewrite line 4 using array subscript notation.8. (5 points) Given:
1 float arr[100];
2 for(int x=0; x<100; ++x)
3 arr[x]=100-x;

What does the following expression print out?
cout << *arr << endl;

9. Given:
int a=0;
int b=6;
int x=0;
Circle each if-expression that evaluates to true:
A) if(b)
B) if(x)
C) if(a=b==6)
D) if(a=b==5)
E) if(a=b=5)
F) if(a=x=0)
G) if(a=x==0)

10. Given:
1 #include
2 using namespace std;
3
4 int main()
5 {
6 int x;
7 cout << "Enter a number greater than 10" << endl;
8 while ( x < 10 )
9 {
10 cin >> x;
11 }
12 return 0;
13 }

This program compiles just fine, and sometimes it runs as expected. But sometimes when you run it, it exits immediately after printing "Enter a number greater than 10". That is, the program doesn't pause for you to enter a number. Why are you getting this inconsistent behavior?

11. What is the output of the following:
int x=4;
int y=3;
A) cout << x / y << endl;
B) cout << x % y << endl;
C) cout << x << "%" << y << endl;
D) cout << "x" << '%' << 'y' << endl;

12. What is the type of the expression. That is, what is the kind of thing that each expression evaluates to. For example:
3 + 4 integer
You may assume that the variable a has been declared as an integer.
A. a + 4
B. a = 4
C. 3.14 + 4.49
D. 3 + 3.14
E. 'a'
F. cout << a
G. new float[30]
H. new float

13. Write a for-loop that prints out the numbers between 1 and 100 that are evenly divisible by three.

14. Write a while-loop that prints out the numbers between 1 and 100 that are evenly divisible by three.

15. Given:

1 #include
2
3 class Willow {
4 public:
5 Willow(int g);
6 private:
7 float f;
8 };
9
10 Willow::Willow(int g) : f(g)
11 {
12 }
13
14 void display(int g)
15 {
16 std::cout << g << std::endl;
17 }

Write a main-function that:

A. Creates a Willow object
B. Calls the display function

Part B

1. Write your name on the backside of the last page.

2. Every C++ program begins at the function ____________.

3. What is the difference between these 2 include statements.

#include
#include "iostream"

4. What is the expected output of the following piece of code?

int x = 5.7;
int y = 3.2;
cout << x-y;

5. Assuming we have three C++ file named main.cpp, test.h, and test.cpp, what command could we use to compile our code into an executable?

6. Name the 4 steps that occur when a program is compiled

7. Write the implementation file (person.cpp) for the following person.h file. The file must be complete and should compile.

#include
using namespace std;
class Person {
public:
Person(string, int); //should set private data members
string getName();
int getAge();
private:
string name;
int age;
};

8. What is the output of the following program?
#include
using namespace std;
void figureMeOut(int& x, int y, int& z);
int main( ) {
int a, b, c;
a = 10;
b = 20;
c = 30;
figureMeOut(a, b, c);
cout << a << " " << b << " " << c << endl;
return 0;
}
void figureMeOut(int& x, int y, int& z)
{
cout << x << " " << y << " " << z << endl;
x = 1;
y = 2;
z = 3;
cout << x << " " << y << " " << z << endl;
}

9. What is the purpose of a constructor? When does it run?

10. Why do you use #ifndef, #define, and #endif in a header file?

11. Describe the action of the new operator

12. Suppose you are writing a program the uses a stream called fin, which will be connected to an input file called "stuff1.txt" and a stream called fout, which will be connected to an output file called "stuff2.txt". How do you declare fin and fout? What include directive, if any, do you need to place in the program file?

13. What is wrong with the following piece of code?

int sampleArray[10];
for (int index = 1; index <= 10; index++)
sampleArray[index] = 3*index;

Part C

1. Write your name on the backside of the last page.

2. Given the function: void printMessage(string message); Answer the following questions
What is the function's return type?
List the formal parameter(s) of the function. Include the data type and name of each formal parameter.
Write a call/invocation of the function printMessage with the string "This is so easy!" as the argument.
Is the function decLaration or function definition shown above?

3. Given the statement: float* fp=new float[3];
To release this memory:
a) delete fp;
b) delete [] fp;
c) for(int i=0; i<3; ++i) delete fp[i];
d) delete fp[3]
e) delete float[3];

4. Given:
a=3;
b=4;
expression 1: a -= b;
expression 2: a =- b;
What's the difference between the first and second expressions
a) They are equivalent
b) First is positive and second is negative
c) Second is negative and first is positive
d) The second one doesn't compile
e) None of the above

5. Consider the program below in the test.cpp file
1. #include
2. using namespace std;
3. int main()
4. {
5. do {
6. cout << "give me an int: ";
7. int i;
8. cin >> i;
9. while (i < 0 II i > 10);
10. cout << "Thanks, i is " << i << endl;
11. return 0;
12.
This program has a bug. It will not compile and gives the compiler error of test.cpp:1e:28 error: 'is was not decLared in this scope
Identify what line number the bug is on and propose how to eliminate it. You're welcome to write on or alongside the code itself.

6. Given the statement
string* airpLane[25];
Describe what is created when this statement is executed. Be explicit in your answer.

7. Given an array of integers:
int myArray[20];
open a text file for writing called "arraycontents.txt" and then write a loop that will print all of the contents of the array to the file.

8. Carefully distinguish between the meaning and use of the dot operator "." and the scope resolution operator "::"

9. Suppose your program contains the following class, contained in automobile.h,
class Automobile
public:
Automobile(double prc, double prft); //sets private data members void setPrice(double prc);
void setProfit(double prft);
double getPrice( );
private:
double price;
double profit;
double getProfit( );
;
and suppose the main function of your program contains the following declarations
Automobile hyundai (3999.99, 299.50);
Automobile jaguar (38999.99, 3200.00);
Which of the following statements will compile in the main function of your program? Write YES or NO before each statement.
hyundai.price = 4999.99; jaguar. setPrice(30000.97); double aPrice, aProfit;
aPrice = jaguar.getPrice( );
aProfit = jaguar.getProfit( );
aProfit = hyundai.getProfit( );
hyundai = jaguar;

10. Write the implementation file (automobile.cpp) for the class contained in automobile.h, which is described in the previous question.

Request for Solution File

Ask an Expert for Answer!!
Basic Computer Science: Flip over this test on the back of this test write your
Reference No:- TGS01058688

Expected delivery within 24 Hours