Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Sample Problems (Final Exam) CS1428 Foundations of Computer Science I 1. True or

ID: 3570115 • Letter: S

Question

Sample Problems (Final Exam)

CS1428 Foundations of Computer Science I

1. True or False?
(1) ______ You cannot use a float type as the switch variable in a switch statement.
(2) ______ In C++, although it is possible to declare an array of structs, it is not possible to
declare a struct that contains an array.
(3) ______ The compiler will warn you of an out of range array index.
(4) ______ When you include the <fstream> library, the file variable fout is automatically created.
(5) ______ To be treated as a C-style string, an array of characters must end with a NULL
terminator

Explanation / Answer

1.
(1). True

(2). False, struct of arrays is possible

(3). False, out of range array index is a runtime error

(4). False

(5). True


2.
(1). cmath

(2). d. cin.getline( str1, 81 );

(3). None of these. As we start entrying into the file, it will start replacing the data from the beginneing.

(4). d. 5, 5

(5). a. int data[20][6];


3.
(1).
(a) Value = 1.25, type = float
(b) Value = 2.5, type = float
(c) Value = 2, type = int
(d) Value = 13, type = int
(e) Value = 1, type = float

(2).
1) 5
2) 6
3) 40
4) 40
5) 18


4.
1)
j = 100;
do{
   cout << "T minus " << j << " seconds to launch." << endl;
   j--;
}while(j >= 1);


3)
// declare and initialize
int arr[4][4];
for(int i = 0; i < 4; ++i){
   for(int j = 0; j < 4; j++){
       arr[i][j] = i + j;
   }
}

// print the upper diagonal
for(int i = 0; i < 4; ++i){
   for(int j = 0; j < 4; j++){
       if(i == j) cout << arr[i][j] << " ";
   }
}

4)
when choice = 0
=> Invalid choice!

when choice = 1
=> Welcome toDisney Land

when choice = 2
=> Disney Land

when choice = 3
=> Don't make an invalid choice!

when choice = 4
=> Invalid choice!


5)
int factorial(int n){
   if(n < 0) return 0;
   else if(n == 1 || n == 0) return 1;
   else return n * factorial(n - 1);
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote