Hi, I need to solve this question using C++ programming language. Thank you.
Note: I have included Program - 5-23, General Program Format Rules, if you needed.
Program 5-23
// This program tests for file open errors.
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream inputFile;
int number;
// Open the file.
inputFile.open("BadListOfNumbers.txt");
// If the file successfully opened, process it.
if (inputFile)
{
// Read the numbers from the file and
// display them.
while (inputFile >> number)
{
cout << number << endl;
}
// Close the file.
inputFile.close();
}
else
{
// Display an error message.
cout << "Error opening the file.\n";
}
return 0;
}
Pract3.txt
2767 4120 2545 173 -955 2508 -774 1785 -396 4843 4245 1923 4394 2044 3460 866 -46 3167 -889 4415 -484 -785 3187 865 3025 4500 -579 3526 -359 53 2299 -907 -818 3789 571 283 2689 134 3650 1520 -961 4346 1123 3445 1697 1712 1684 4438 2576 4455 1113 2815 145 4815 -621 3677 3355 602 -885 -911 2912 849 510 390 2843 4999 4454 3495 390 -391 375 1919 195 4182 2325 -993 2261 4882 2256 2093 3693 1163 3047 -999 3231 4006 3936 3671 3765 3232 3648 3850 115 2658 4745 752 366 3749 664 -925 3705 2226 4645 4002 -880 1160 -759 4471 3318 1648 -191 4056 591 4651 2424 1868 4845 4404 3091 481 4413 132 4654 2496 4749 159 4821 834 3259 498 4245 1046 3365 3586 1419 4561 1249 2875 -864 -345 -636 3656 403 2154 4038 4986 4738 4152 334 4595 1552 2635 2397 4044 1766 3769 3893 2513 2569 -698 771 4789 1051 2384 843 4265 2238 2739 3379 3829 139 2284 657 2387 1096 2195 3819 203 494 1166 4898 2496 985 3049 -93 3570 4522 1875 2469 3684 3780 345 1334 2895 4683 1545 1601 2551 243 -889 2863 -218 1748 2604 785 -704 2647 1347 -46 891 1972 489 4704 2616 2054 623 4635 676 4876 2501 3040 3815 -918 725 4277 934 1670 284 627 4992 1300 -577 4654 -971 2477 4313 207 1168 974 -884 3939 2520 -526 4523 2702 2497 3349 4578 3941 3231
Transcribed Image Text: General Program Format Rules
Each program should have
1. A heading comment at the top of the program that contains information in this
form:
/*
Programmer
I. Will Ritem
:
Date due
: July 12, 2020
Description : This program will calculate the average
of three integers from the user
*/
A comment above each function (other than main) in this form:
/ *
: getAverage
: 3 integers
: This function will calculate the average
of its three integer parameters
: the average (a double)
Function
Receives
Description
Returns
Preconditions : none
* /
Note: preconditions are what the function is assuming to be true in order to do its job. For instance,
a function that calculates the square root of its parameter can be written one of two ways:
With no preconditions, which means the function itself must check to see if its parameter is not a
negative number, OR
а.
b. Have a precondition that the parameter is non-negative, in which case it's the caller's
responsibility to make sure the parameter is non-negative before calling the function. A
precondition is like a contract in which the function says "Ill do this, but first you're promising my
precondition is met."
3. Variables and constants with descriptive names
"average" instead of "ave", and so on.
– so, "radius" instead of "rad", "area" instead of "ar",
Please don't use global variables unless a program says it's OK. If you don't know what a global
variable is, please learn about them in section 6.10 in the text. Using global constants, on the other
hand, is fine (also in section 6.10).
4.
The order that parts of your program should follow is like this:
Heading comment (#1 above)
b.
а.
#includes section
using namespace std;
d.
C.
global constants (Note: this doesn't say global variables, which aren't allowed)
typedefs and struct declarations
f.
е.
g.
h.
function prototypes
the main () function
other functions, each with its own comment (#2 above)
6.
Please don't "hardcode" array boundaries when using loops, functions, etc. Instead, declare a global
constant (see 5d above) like this:
const int ARRAY SIZE = 25;
then write the loop like this:
for (int x
= 0; x < ARRAY SIZE; x++)
and not like this:
for (int x = 0; x <(25/; x++)
2.
5.
Transcribed Image Text: You will be using Visual Studio to create the following programs. Make sure you
see that these are separate programs.
1.
2.
Make sure that you follow the General Program Format Rules for each program
3.
The closer the form of your output matches that shown in the example
Special instructions
Make sure the input files are in the same folder as your source code! If you don't, you'll be stuck with
entering long pathnames to get to the files.
For instance, if I were working on PA1prog, I
want to put my input file in the PA1prog folder.
Here, the input file is named "pract2.txt".
Local Disk (C:) > VS Projects > PA1prog
Name
Date modified
Туре
Size
.VS
9/2/2020 3:22 PM
File folder
Debug
10/18/2020 10:22 AM
File folder
PA1prog.cpp
10/18/2020 10:21 AM
CPP File
1 KB
PA1prog.sln
A PA1prog.vcxproj
9/2/2020 3:22 PM
Visual Studio Solu...
2 KB
10/7/2020 7:34 PM
VC++ Project
8 KB
The reason: if you use only a filename, the
operating system will automatically look in the
folder where your program exists.
e PA1prog.vcxproj.filters
10/7/2020 7:34 PM
VC ++ Project Filte...
1 KB
PA1prog.vcxproj.user
9/2/2020 3:22 PM
Per-User Project ...
1 KB
pract2.txt
10/18/2020 10:18 AM
Text Document
1 KB
Source.cpp
10/7/2020 4:58 PM
CPP File
4 KB
When you save output to a file using only the filename, the file will be in the same folder as your
program, also.
Question:
Ask the user for a filename that contains an unknown number of integers. Print the numbers one per line
on the screen, then tell which one is the largest.
Note: 1. I'm including a test file named "pract3.txt". Its largest value is 4999.
2. Make sure to test to see if the file actually opened. If not, print an error message and don't
do anything else. If it did open, go ahead with the input, processing, and output.
3. Use the King of the Mountain technique for this program.
4. You will need to use a while loop that checks for when the end of the file is reached.
5. You can declare only two ints in this program. No other number variables are allowed.
扇