Hi, I just needed help running a program from the cmd prompt as was required by my prof for an assignment question. It basically needs to run after typing a3 file_name in the cmd prompt. a3 is the name of the executable while file_name is the text file. I dont know understand what else to do besides writing those parameters in the main. The following is the question:
Write a program called a3 that can be run from the command line prompt
using the following syntax: a3 file_name, where a3 is the name of the .exe file,
file_name is a text file containing a list of student numbers with their corresponding GPA
separated by a space; one student per line. The text file can contain any number of lines. An
example of file_name containing 3 lines is as follows:
100123456 3.7
100654321 4.0
100246800 2.8
After reading the contents of the file, the program outputs the highest GPA from the list. For
example, from the students in the sample above, the output of your program should be
something like “Highest GPA was 4.0, by student 100654321.” Submit all the source code
and executable (.exe) files.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
int main(int argc, char* argv[])
{
ifstream readFile;
//ofstream writeFile;
readFile.open("file_name.txt");
//writeFile.open("file_name2.txt");
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
readFile.precision();
int firstStudent; double firstGPA; int secondStudent; double secondGPA; int thirdStudent; double thirdGPA;
readFile >> firstStudent >> firstGPA;
readFile >> secondStudent >> secondGPA;
readFile >> thirdStudent >> thirdGPA;
cout << firstStudent << setw(6) << setprecision(1) << firstGPA << endl << secondStudent << setw(6) << secondGPA << endl << thirdStudent << setw(6) << thirdGPA << endl;
if (firstGPA > secondGPA && firstGPA > thirdGPA)
{
cout << "Highest GPA was " << firstGPA << ", by student " << firstStudent << endl;
}
else if (secondGPA > firstGPA && secondGPA > thirdGPA)
{
cout << "Highest GPA was " << secondGPA << ", by student " << secondStudent << endl;
}
else
cout << "Highest GPA was " << thirdGPA << ", by student " << thirdStudent << endl;
readFile.close();
//writeFile.close();
return 0;
}
|