






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
A c++ program that processes customer credit data from two text files. The first file, junecreditcustomers2008.dat, is loaded into a vector and the second file, julycredittransactions2008.dat, is processed line by line to update the customer data in the vector. The updated vector is then saved to a new file, julycreditcustomers2008.dat. The program also displays the customer ids of those who have exceeded their credit limit.
Typology: Exams
1 / 11
This page cannot be seen from the preview
Don't miss anything!
Answer Question 1 and 2 other questions. Examiners : 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?
#include
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
#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]
character, □ is the space character and ∇ is the end of file marker)
What is values are output by the code below? What do these values signify?
#include
fin.close(); fin.clear(); //------------------------------------ fin.open("a:\hill.txt"); z = 0; for(;;) { fin >> s; if(fin.eof())break; z++; } fin.close(); //----------------------------------- cout << " x: " << x << endl << " y: " << y << endl << " z: " << z << endl; }
a:\hill.txt Jack □ and □ Jill □□ ↵ □↵ Went □ up □ the □ hill↵ □□↵ to□fetch□a□pail□of□water□↵ □□□↵ □□□□↵ □□□□□□↵ □□□□□□□↵
∇
Q2 ends
Q2 [25 marks]
The VeryBest department store has a list of customers to whom it allows credit. It keeps on file the details of what each customer owes at the end of each month.
For the end of June this file is called juneCreditCustomers2008.dat. This is a text file which on each line, holds the Customer Number , balance (amount owed in €), credit limit ( in € ) for a customer availing of the stores credit e.g. 1000 55 200 1001 0 500 1002 999 1000 1003 650 500 1004 678 2000 1005 1234 3000 so that customer 1005 owes the store €1234 but is still within the credit limit of €3000 allowed This file is sorted by Customer Number and is kept in increasing order. The credit limit is set at the start of each year.
A file called julyCreditTransactions2008.dat stores the details of all credit transactions during the month of July. This, also, is a text file and on each line, holds the detail Customer Number , credit purchase , payment for each credit transaction during the month e.g.
1234 0.00 100.00 records customer 1234 paying £100 off the account; or 1234 50.00 0.00 records customer 1234 buying £50 of goods on credit; or 1234 75.00 50.00 records customer 1234 buying £75 of goods and making a payment of £50;
If customer 1234 has no transaction during the month, there will be no entry for 1234 in the file. This file is NOT sorted in any way.
Write a C++ program which
Q3 ends
d) (12.5 marks) (i)[9.5 marks] Write the C++ definition for the function LinearSearch ( ) that uses a linear search to find the position of a target number within a vector array of unsorted numbers. The function prototype/declaration is void LinearSearch(vector
(ii)[3 marks] Modify the function LinearSearch ( ) in (i) to give a function
void LinearSearchForSorted(vector
which would be a more efficient, but still linear, when the vector array is sorted.
e) (12.5 marks) Write a C++ function that accepts a single string parameter which would analyse the string, character-by-character, to determine if it contains an embedded apostrophe or double quote mark and display an appropriate message. For example
String input Message displayed
A double quote was found in position 16.
f) (12.5 marks) Write a C++ function that takes an input file stream in and a char target as parameters and returns the number of occurrences of target in the file connected through in.
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]