Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

C++ Final Exam - Fall 2000, Exams of Programming Languages

14 Multiple Choice Questions and Essay Questions.

Typology: Exams

2021/2022

Uploaded on 02/24/2022

arold
arold 🇺🇸

4.7

(24)

376 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
C++ Final Exam (Fall 2000)
Name:
ID:
Write your answer next to question number. All
other answers will be ignored.
Note that the answers are based on C++ com-
piler on penguin.
True/False: (4 points each)
1. The float type will ”wrap-around” when its
point of overflow occurs.
2. char *msg = ”Hello”; is equivalent to char
*msg = {’H’,’e’,’l’,’l’,’o’,’\0’};
3. The following code
#define SQUARE(X) (X * X)
y=SQUARE(u + v);
is equivalent to y=(u + v)*(u + v).
4. The null pointer, NULL is defined in
<stdio.h>and is guarenteed to be an invalid
address.
5. The string length (strlen()) of the following
is 6.
char txt[] = { ’C’, ’s’, ’\t’, ’7’,
’4’, ’\n’, ’\0’ };
Multiple Choice: (4 points each)
1. What would be printed by the following
statements?
#include <iostream.h>
int f(int &i)
{
i = 10;
return(5 * i);
}
int main()
{
int n = 5;
f(n);
cout << n << "\n";
return 0;
}
(a) 5
(b) 10
(c) 50
(d) Compilation/Linkage Error.
2. What would be printed by the following
statements?
int y[3][3] = {1, 2, 3,
4, 5, 6,
7, 8, 9};
cout << y[1][2];
(a) 5
(b) 6
(c) 2
(d) 4
3. What would be printed by the following
program?
#include <iostream.h>
int sub1(int &n)
{
n--;
return n;
}
int main()
{
int m = 10;
for(int j = 0; j < 10; j++)
m -= sub1(j);
cout << m << "\n";
return 0;
}
(a) 0
(b) 1
(c) 9
(d) 10
(e) None of the above.
4. Which operator has the highest prece-
dence?
(a) .
(b) *
(c) []
(d) &
5. What would be printed by the following
statements?
double *pt;
double a[3]={1.2, 2.3, 3.4};
pt=&a[1];
pt+=1;
cout<<*pt<<endl;
1
pf3
pf4
pf5

Partial preview of the text

Download C++ Final Exam - Fall 2000 and more Exams Programming Languages in PDF only on Docsity!

C++ Final Exam (Fall 2000)

Name: ID:

  • Write your answer next to question number. All other answers will be ignored.
  • Note that the answers are based on C++ com- piler on penguin.

True/False: (4 points each)

  1. The float type will ”wrap-around” when its point of overflow occurs.
  2. char *msg = ”Hello”; is equivalent to char *msg = {’H’,’e’,’l’,’l’,’o’,’\0’};
  3. The following code #define SQUARE(X) (X * X) y=SQUARE(u + v); is equivalent to y=(u + v)*(u + v).
  4. The null pointer, NULL is defined in <stdio.h> and is guarenteed to be an invalid address.
  5. The string length (strlen()) of the following is 6. char txt[] = { ’C’, ’s’, ’\t’, ’7’, ’4’, ’\n’, ’\0’ };

Multiple Choice: (4 points each)

  1. What would be printed by the following statements? #include <iostream.h> int f(int &i) { i = 10; return(5 * i); } int main() { int n = 5; f(n); cout << n << "\n"; return 0; } (a) 5 (b) 10 (c) 50

(d) Compilation/Linkage Error.

  1. What would be printed by the following statements? int y[3][3] = {1, 2, 3, 4, 5, 6, 7, 8, 9}; cout << y[1][2]; (a) 5 (b) 6 (c) 2 (d) 4
  2. What would be printed by the following program?

#include <iostream.h> int sub1(int &n) { n--; return n; } int main() { int m = 10; for(int j = 0; j < 10; j++) m -= sub1(j); cout << m << "\n"; return 0; } (a) 0 (b) 1 (c) 9 (d) 10 (e) None of the above.

  1. Which operator has the highest prece- dence? (a). (b) * (c) [] (d) &
  2. What would be printed by the following statements? double pt; double a[3]={1.2, 2.3, 3.4}; pt=&a[1]; pt+=1; cout<<pt<<endl;

(a) 1. (b) 2. (c) 3. (d) 3. (e) None of the above.

  1. What would be printed by the following statements? int k; double j; k = 2; j = 2.0; if(k == j){ cout << "Okay."; } else cout << "Not okay."; (a) Okay.Not okay. (b) Not okay. (c) Okay. (d) Nothing will be outputed.
  2. Given a program as follows, what would be printed? #include <iostream.h> int myfunc(double); int myfunc(float); int main() { cout << myfunc(3.51) << "\n"; return 0; }

int myfunc(double n) { return n * 2.0; }

int myfunc(float n) { return n * 3.0; } (a) 7 (b) 7. (c) 10 (d) 10. (e) None of the above.

  1. Which statement is equivalent to the fol- lowing statement?

pt->x_center = 10.0; (a) pt.x_center = 10.0; (b) (pt).x_center = 10.0; (c) (*pt.)x_center = 10.0; (d) (pt->)x_center = 10.0; (e) None of the above.

  1. What would be printed by the following statements? class complex { public: double re, im; };

complex x, y; x.re = 4.0; x.im = 5.0; y = x; x.re = 5.0; cout << y.re << endl; (a) 4. (b) 4 (c) 5. (d) 5 (e) None of the above.

  1. What do the following two cout statements print out? { int i = 1; double x = 1.111; cout << i << " " << x << "\n"; { int x = 2; double i = 2.222; cout << i << " " << x << "\n"; } }

(a)

(b)

(c)

  1. What would be printed by the following program? #include <iostream.h>

Short Essay:

  1. (6 points each) How do you dynamically (a) allocate and (b) deallocate a float array X[5] by using new and delete operators?
  2. (14 points each)Please complete the following program (by filling in lines 2, 6, 17, 24, 27, 28, 38) so that it will read data from the file test.dat and print out the data. 1 #include <iostream.h> 2 ____________________ 3 4 #define MAX 10 5 6 _______________________________ 7 public: 8 char name[25]; 9 int Ex1, Ex2; 11 }; 11 12 int main() 13 { 14 Student st[MAX]; 15 int count = 0; 16 17 ________________ 18 if (!in) 19 { 20 cout << "Cannot open test.dat.\n"; 21 return 1; 22 } 23 24 ________________ 25 while(!in.eof()) 26 { 27 ________________ 28 ________________ 29 cout << st[count].name << " " << st[count].Ex1 << 30 " " << st[count].Ex2 << "\n";

31 count++; 32 if (count >= 10) 33 { 34 cout << "Exceed MAX: " << MAX << endl; 35 in.close(); 36 return(-1); 37 } 38 ________________ 39 } 40 41 in.close(); 42 return 0; 43 }

The input file test.dat contains the following data:

Eric 77 87 Scott 90 94 Mary 100 100