



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Note: Total points available=240 (40 points bonus). Time per question is our suggestion only.
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
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
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;
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
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; }