Docsity

RPI CSCI 1100 Midterm 1 for Fall 2006, Exams of Computer Science

Toggle sidebar
bg1
CSCI 1100 RPI
Problem Solving in C++ Fall 2006
MIDTERM 1
Last Name: Student ID#: Section:
Instructions
โ€“ Fill in your Last Name, RIN# and Section # above.
โ€“ Answer all questions in the space provided.
โ€“ Keep your answers BRIEF!
โ€“ This is a CLOSED book exam.
โ€“ No collaboration or calculating/electronic aids of any kind allowed.
โ€“ Check that your exam has all sheets (including a scratchwork page).
โ€“ The total point value for each question is given in square brackets.
โ€“ Read the entire exam. Start with questions you know.
โ€“ Assume that #include directives are present where necessary.
โ€“ You have 90 MINUTES.
Qn. Time Avl. Your
(min) Pts. Pts.
1 10 40
2 10 20
3 10 20
4 10 30
5 10 20
6 15 30
7 15 40
8 10 40
Total 90 240
Note: Total points available=240 (40 points bonus).
Time per question is our suggestion only.
Questions are graded on a 0โˆ’1
2
โˆ’1scale.
pf3
pf4
pf5

Partial preview of the text

Download RPI CSCI 1100 Midterm 1 for Fall 2006 and more Exams Computer Science in PDF only on Docsity!

CSCI 1100 RPI

Problem Solving in C++ Fall 2006

MIDTERM 1

Last Name: Student ID#: Section:

Instructions

  • Fill in your Last Name, RIN# and Section # above.
  • Answer all questions in the space provided.
  • Keep your answers BRIEF!
  • This is a CLOSED book exam.
  • No collaboration or calculating/electronic aids of any kind allowed.
  • Check that your exam has all sheets (including a scratchwork page).
  • The total point value for each question is given in square brackets.
  • Read the entire exam. Start with questions you know.
  • Assume that #include directives are present where necessary.
  • You have 90 MINUTES.

Qn. Time Avl. Your

(min) Pts. Pts.

Total 90 240

Note: Total points available=240 (40 points bonus). Time per question is our suggestion only.

Questions are graded on a 0 โˆ’

โˆ’ 1 scale.

1. (a) [10]What is the class motto?

If you can pseudo-code,you can code. (b) [10]What is pseudo-code? A ordered set of instructions in โ€œplain englishโ€ which can be followed by anyone to solve a problem. It identifies the data input, the operations needed to solve the problem on the data and how the data will be output. (c) [20]MACs and PCs have different types of processors. I have 2 PCs, one running windows called PCwin, and one running Linux (similar to Cygwin) called PClinux. My supervisor gives me a problem to solve using my computer. I have to write a program in C++. Consider the following tasks in solving the problem: A. Construct problem solution. B. Construct pseudo-code for solution. C. Write C++ program to implement pseudo-code. D. Compile C++ program to obtain machine code using g++ compiler. E. Run program (i.e., execute machine code). F. Obtain and report results to supervisor. Each of the above steps will be done on the three systems: MAC, PCwin, PClinux. Compare the results of each step for the three systems by stating for which systems the results are the same and for which they are different. A: Same on all. B: Same on all. C: Same on all. D: Different on MAC, same on PCwin and PClinux E: Different on MAC, same on PCwin and PClinux F: Same on all

2. [20]You have 4 balls, one which has a different weight to the other three.

You have a balance scale with two sides (A,B). You can place some balls on A and some on B, and the

balance will tell you which side is heavier, or whether they are balanced.

Give pseudo-code to determine which is the odd ball and whether it is heavy or light.

1: Label the Balls 1,2,3,4. 2: Weigh A = { 1 , 2 } against B = { 3 , 4 }. 3: if B is heavier then 4: Relabel the balls: 1 โ†’ 3 , 2 โ†’ 4 , 3 โ†’ 1 , 4 โ†’ 2. 5: end if 6: // Either {1,2} contains a heavy ball or {3,4} a light one 7: Weigh 1 against 2. 8: if 1 is heavier then 9: 1 is the heavy ball. 10: else if 1 is lighter then 11: 2 is the heavy ball. 12: else if balanced then 13: // {3,4} has a light ball 14: Weigh 3 against 4. 15: if 3 is lighter then 16: 3 is the light ball. 17: else 18: 4 is the light ball. 19: end if 20: end if

  1. [30]The file grades.txt contains the grades of 400 students. Each line in the file has the format where is a single string and is a real number between 0 and 100. The students are listed in some arbitrary order. Give C++ code which reads this file and populates two arrays names and scores with the names and scores respec- tively. The program then computes and outputs to the screen: (1) the maximum grade along with a student who has this grade; (2) the minimum grade along with a student who has this grade; (3) the average grade.

double max=-1, min=101, av=0, scores[400]; string maxS,minS,names[400]; ifstream inp("grades.txt"); int i; for(i=0;i<400;i++){ inp>>names[i]>>scores[i]; av+=scores[i]; if(scores[i]>max){ max=scores[i]; maxS=names[i]; } if(scores[i]<min){ min=scores[i]; minS=names[i]; } } cout<<"Max: "<<maxS<<" "<<max<<endl; cout<<"Min: "<<minS<<" "<<min<<endl; cout<<"Average: "<<av/400<<endl; return 0;

  1. [40]This question relates to the arrays names and scores which were constructed in question 6.

The A-grade will be given to 25% of the students. We wish to determine the Ascore, which is the threshold score for the A grade. Specifically, we define the Ascore as a score (not necessarily unique) which satisfies the following properties: (1) at least 25% of students have score โ‰ฅ Ascore; (2) at least 75% of students have score โ‰ค Ascore. Give pseudo-code for an algorithm which will determine the Ascore from the array scores. The algorithm we give is based on the fact that such an Ascore must exist which is equal to one of the scores.

for i = 0 to 400 do tryAscore=scores[i]. //consider scores[i] as a potential Ascore Count the number of scores โ‰ฅ tryAscore using a for loop (numAbove). Count the number of scores โ‰ค tryAscore in the same for loop (numBelow). if numAbove โ‰ฅ 100 && numBelow โ‰ฅ 300 then Ascore โ† tryAscore. end if end for

  1. [40]This question relates to the arrays names and scores which were constructed in question 6.

Write a C++ function which takes as input the two arrays names and scores. The output of the program should be Ascore, the number of students who got an A, and an array (you can call it thegrades) which contains the entries A or notA according to whether the corresponding student got an A or not. The function should also print out the names of all students who got ann A. Note: your pseudo-code from question 7 should be useful here.

double findAscore(string names[],double scores[],string thegrades[],int size,int &numA){ double tryAscore,Ascore; int i,j,numAbove,numBelow; // First find Ascore for(i=0;i<size;i++){ tryAscore=scores[i]; numAbove=0;numBelow=0; for(j=0;j<size;j++){ if(scores[j]>=tryAscore){numAbove++;} if(scores[j]<=tryAscore){numBelow++;} } if(numAbove>=size0.25 && numBelow>= size0.75){ Ascore=tryAscore; } } // Now do the other tasks cout<<"Students with A grade: "<<endl; numA=0; for(i=0;i<size;i++){ if(scores[i]>=Ascore){ cout<<names[i]<<endl; thegrades[i]="A"; numA++; } else{ thegrades[i]="notA"; } } return Ascore; }