






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Main points of this past exam are: Partial Credit, Compile, Longer Commented Out, Namespace, Table Printed, Above-Average Numbers, Artistic Impression, Technical Merit, Standard Program, Appropriate Checks
Typology: Exams
1 / 11
This page cannot be seen from the preview
Don't miss anything!
Q1 continues…
(Time : 3 Hours)
Answer Question 1 and 2 other questions. Examiners : Dr. M. Ó Cinnéide Mr. M. Donnelly Dr. J. Buckley Dr. A. Kinsella Dr. M.G.Murphy
Q1 continues…
Q1 [50 marks] Answer each of the following questions: Q1a (9 marks) What is the output from the following piece of code? (NOTE: Trace your workings so partial credit may be given for incomplete work): 5 marks This code will not compile when the line marked // 2 is no longer commented out- why not? 2 marks This code will get locked into an infinite loop when the line marked //1 is no longer commented out
#include
void main ( void ) { int r = 9, s = 4; for ( int t = r ; t >= s ; t-- ) { int u = t; for ( int v = r ; v > u ; v-- ) { cout << u << '-' << t * v ; //u-- ; //----------> } cout << '+' << endl; } //cout << u << endl ; //----------> } //---------------------------------------------------------
Q1 continues…
Q1 continued Q1c (8 marks)
What is the output from the following piece of code? (NOTE: Trace all your workings so marks can be given for partial credit.)
#include
Q1 continues…
Q1 continued Q1d (8 marks) The following C++ code correctly computes the average of doubles which it reads from the keyboard: But the result is of little use in analyzing the numbers entered. Modify the code so that the numbers are read as before but stored in a C-array of capacity 100, the average calculated and displayed as before but then a table printed displaying the “above-average numbers” (i.e. each and every number which is greater than average) and their location within the array.
#include
double sum, average;
cout << "\n how many numbers do you want to average?";
for(;;) { cin >> howMany; if(howMany > 0 )break; cout << " must be >0. Try again."; }
sum = 0; for(int k = 0; k < howMany; k++) { cout << "\n a[" << setw(3) << right << k << "] = "; cin >> holdIt; sum += holdIt; } average = sum / howMany; cout << "\n The average is : ... " << average; cout << endl << "---> q1d output <---" << endl; } //---------------------------------------------------------
Q1 ends
Q1 continued Q1f [8 marks] What is the output from the following code? (NOTE: Trace your workings so partial credit may be given for incomplete work)
#include
for(a = limit; a >= 0; a--) { for(b = limit; b >= 0; b--) { if( (0 == a) || (limit == a) ) { cout << setw(2) << a; } else if( (limit == a + b) || (a == b)) { cout << "-*"; } else if(a < b) { cout << setw(2) << a; } else { cout << setw(2) << b; } } cout << endl; } } //---------------------------------------------------------
Q2 ends
Q2 [25 marks]
In competitive skating, each skater completes two programs. The first program for each skater is a ‘standard’ program specified by the judges. The second program for each skater is a ‘free-style’ program where the content is specified by the skater his/herself.
For each of these programs, nine judges score the program twice from 0 to 6, inclusive, in steps of 0.1. The first score is for technical merit. The second score is for artistic impression. These scores are stored on successive lines of the file s C:\StandardProgramScores.data and C:\FreeProgramScores.data as appropriate and as shown below.
The score for technical merit is obtained by discarding the lowest and highest scores and then adding the remaining scores. The score for artistic impression is obtained similarly. The total score for the program is the sum of the scores for technical merit and for artistic impression
The skaters skate the standard program first in order and then, in the same order, they skate the free program, When the competition is finished they are ranked according to their overall score which is the sum of the scores for the standard and for the free programs.
Write a C++ program to compute skating scores using the following I/O specifications:
Input: Taken from the text files C:\StandardProgramScores.data. and then C:\FreeProgramScores.data Each pair of lines contains the following details: · skater’s competition entry number,· judges’ scores for technical merit · skater’s competition entry number,· judges’ scores for artistic impression
Consider the following sample input data:
C:\StandardProgramScores.data 1234 4.5 4.7 4.3 4.9 4.6 4.5 5.1 4.8 4. 1234 5.2 5.1 5.5 5.0 4.9 5.5 5.3 5.7 5. 2345 5.8 5.5 5.0 5.3 4.5 5.8 5.2 5.5 5. 2345 5.0 4.8 5.8 5.4 5.3 4.8 5.0 5.1 5. 3456 5.5 5.5 5.5 5.0 5.0 5.0 5.5 5.5 5. 3456 5.7 5.5 5.3 5.9 5.2 5.4 4.6 4.9 3. 4567 5.2............... etc etc
C:\FreeProgramScores.data 1234 5.5 5.7 5.3 5.9 5.6 5.5 5.1 5.8 5. 1234 5.9 5.4 5.1 5.4 5.9 5.8 5.7 5.4 5. 2345 5.4 5.7 5.4 5.7 4.9 5.2 5.5 5.0 5. 2345 5.5 4.2 5.5 5.8 5.9 4.6 5.9 5.4 5. 3456 5.9 5.9 5.8 5.8 5.7 5.7 5.6 5.6 5. 3456 5.5 5.6 5.6 5.7 5.7 5.8 5.8 5.9 5. 4567 4.2............... etc etc Process: process the data from each file to generate the scores for all competitors. Make appropriate checks throughout.
Output: Publish the detailed results as a table containing the following details in the output file called c:\skate_results.rpt
Competition Standard Free Total Number Technical Artistic Technical Artistic 1234 32.9 37.1 39.3 39.8 149. 2345 3456 etc etc
Q3 ends
e) (13 marks) Given again the declarations struct Results { string name; char grade; int mark; }; ... ... vector
write a C++ function AverageForTheGrade() which will accept the vector myClass and a char theGrade and then return the average of the student scores earning that grade.
f) (13 marks) Write a C++ function called toOctal() which will accept as value parameter an int n and will return its octal (base 8) equivalent. Thus toOctal(17) returns 21, toOctal(197) returns 305, toOctal(20) returns 24,. toOctal(47) returns 57, toOctal(48) returns 60 toOctal(49) returns 61,.
Q4[25 marks]
A “ Text Concordance ” is an alphabetical listing of all the distinct words in a piece of text; e.g. the Text Concordance for “It was the best of times, it was the worst of times.” is “best it of the times was worst”.
A C++ function is required to perform such a Text Concordance on the text contained in a file and store it in another report file. The function parameters are one input file stream fin and one output file stream fout. It may be assumed that the required files have been opened in main() and connected through fin and fout.
Please write two versions of the C++ function: TextConcordance_0(ifstream & fin, ofstream & fout); TextConcordance_1(ifstream & fin, ofstream & fout); Both versions will store successive words, from the fin stream, in a vector but a) version1 will (i) add each word only if it is NOT already in the vector, (ii) use an appropriate function template from the
NOTE: It should be convenient to convert all words to lower case so code the function void LowerTheCase(string & aWord); [4 marks] and don’t forget to strip any punctuation from the end of a word(assume there is at most one) when you code the function void DropAnyPunctuation(string & aWord);. [4 marks]