Ask Computer Engineering Expert

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.

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M91348418
  • Price:- $40

Guranteed 36 Hours Delivery, In Price:- $40

Have any Question?


Related Questions in Computer Engineering

Does bmw have a guided missile corporate culture and

Does BMW have a guided missile corporate culture, and incubator corporate culture, a family corporate culture, or an Eiffel tower corporate culture?

Rebecca borrows 10000 at 18 compounded annually she pays

Rebecca borrows $10,000 at 18% compounded annually. She pays off the loan over a 5-year period with annual payments, starting at year 1. Each successive payment is $700 greater than the previous payment. (a) How much was ...

Jeff decides to start saving some money from this upcoming

Jeff decides to start saving some money from this upcoming month onwards. He decides to save only $500 at first, but each month he will increase the amount invested by $100. He will do it for 60 months (including the fir ...

Suppose you make 30 annual investments in a fund that pays

Suppose you make 30 annual investments in a fund that pays 6% compounded annually. If your first deposit is $7,500 and each successive deposit is 6% greater than the preceding deposit, how much will be in the fund immedi ...

Question -under what circumstances is it ethical if ever to

Question :- Under what circumstances is it ethical, if ever, to use consumer information in marketing research? Explain why you consider it ethical or unethical.

What are the differences between four types of economics

What are the differences between four types of economics evaluations and their differences with other two (budget impact analysis (BIA) and cost of illness (COI) studies)?

What type of economic system does norway have explain some

What type of economic system does Norway have? Explain some of the benefits of this system to the country and some of the drawbacks,

Among the who imf and wto which of these governmental

Among the WHO, IMF, and WTO, which of these governmental institutions do you feel has most profoundly shaped healthcare outcomes in low-income countries and why? Please support your reasons with examples and research/doc ...

A real estate developer will build two different types of

A real estate developer will build two different types of apartments in a residential area: one- bedroom apartments and two-bedroom apartments. In addition, the developer will build either a swimming pool or a tennis cou ...

Question what some of the reasons that evolutionary models

Question : What some of the reasons that evolutionary models are considered by many to be the best approach to software development. The response must be typed, single spaced, must be in times new roman font (size 12) an ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As