Topic: Basics of C++ Programming Language "ARRAY IN C++"
Codes discussed will be posted here. Write your conclusion on the File stream discussion.
Filename: Ch8_SecretCodeData.txt
Code:
7 9 2 7 8 3 5 6 7 9 2 7 8 3 5 6
*Note need proper codes and conclusion on how it's done and about the results. And please give the proper solution and explanation.
Note: Place your conclusion on why did it turn out like that and give your reasons why the results turned like that, one paragraph will do for the explanation and conclusion.
Note: Please place the proper conclusion and explanations and results of the codes which were given.
This function compares the secret code with its copy. Therefore, it must have access to the array containing the secret code and the length of the secret code. The copy of the secret code and it's length are stored in the input file. Thus, the input file stream variable corresponding to the input file must be passed as a parameter to this function. Also, the compareCode function compares the secret the secret code with the copy and prints an appropriate message. Because the output will be stored in a file, the output stream variable corresponding to the output file must also be passed as a parameter to this function. Therefore, the function has four parameters: an input file stream variable, an output file stream variable, the array containing the secret code, and the length of the secret code. This discussion translates into the following algorithm for the function compareCode:
a) Declare the varialbes.
b) Set a bool variable codeOk to true.
c) Read the length of the copy of the secret code.
d) If the length of the secret code and its copy are not the same, output an appropriate error message and terminate the function.
e) For each digit in the input file:
e.1. Read the next digit of the copy of the secret code.
e.2. Output the corresponding digits from the secret code and its copy.
e.3. If the corresponding digits are not the same, output an error message and set the bool variable codeOk to false.
f). It the bool variable codeOk is true
Output a messahe indicating that the secret code was transmitted correctly.
else
Output an error message.
Comments
Leave a comment