Problems with class grade average program.

This is what I am supposed to do for my program:

You will write a program that takes the number of tests, assignments, labs, and
quizzes taken in a given class and calculates the student’s class average. The program
will read the number of tests, assignments, labs and quizzes as command line input,
and then read the specific number of grades for each by prompting the user for the
correct number of items.
You do not need to supply a number with the final option in the command line
arguments because there is only one final, but you do need to supply the –f option if you
want to prompt the user for a final exam score. If the –f option is omitted, then you
would calculate the class average without having a final exam grade, i.e. out of 85%.
The user can supply these arguments in any order, and therefore you need to preface
each argument with an option to know what the argument is. For example:
class_average –q 5 –a 8 –l 10 –t 2 -f
This would mean that there are 5 quizzes, 8 assignments, 10 labs, and 2 tests. Next,
you have to prompt the user for the specific number of scores for each item. As with
our class, labs are graded on a 10 point scale, and these labs are added together
to determine your overall lab grade, whereas the other scores are out of 100 and
averaged to give you your overall quiz, assignment, and test grade.
Quiz 1:
Quiz 2:

Quiz 5:
Assignment 1:
Assignment 2:

Assignment 8:

Final Exam:
Class Average Calculator:
Your program should determine the overall class average based on the following
weights for each item, which should be declared as constants/macros for ease of
Labs – 10%
Quizzes – 10%
Assignments – 40%
Exams – 25%
Final – 15%

You need to try to make your main function as small as possible by decomposing the
problem into smaller subtasks. To do this, you need to define and use functions in this
assignment. The number of functions is not specified, but you must make each
function, including main, contain under 20 lines of code. This will help you properly
decompose you program. Remember, each function should only do one thing
Example functions: Some example functions to include are check_arguments(),
set_scores(), get_scores(), calculate_avg(), print_invalid_mssg(), print_class_avg().
***Note: You will use a 1-D array to store your quizzes, labs, tests, and assignments.
Do not use global variables in your program. You will be penalized if you do!!!
Error Handling:
 Print an error message if the user doesn’t supply all the command line arguments,
excluding the –f option, which is optional
 Print an error message if the user doesn’t supply a number value for any one of the
options, this excludes the –f option, which doesn’t have a number value
 Print an error message if the user enters a zero for any of the command line
 Print an error message if the user doesn’t enter an integer value for the command
line arguments.
 Print an error message if the user doesn’t supply a number for the scores for the
Program Input:
- Command line options for tests, quizzes, assignments, labs, and a final (optional), in
any order
- Score for each number of items.
- If the –f option is supplied, then read a score for final exam
Program Output:
- Proper error message for each case listed above.
- Class average for the student

So far here is my program:

using namespace std;
void check_arguments(int argc, char *args[]) {
int argt , argl , argq , argf , lloc , qloc , tloc , floc , t , l , q , f;
for (int narg = 0 ; narg < argc ; narg++ ) {
string valuef = "-f";
string valuel = "-l";
string valueq = "-q";
string valuet = "-t";
if (args[narg] == valuet){
//if (atoi(args[narg +1]) < 1)
tloc = narg; //location of the test argument.
t = atoi(args[narg + 1]);}
else if (args[narg] == valuel){
lloc = narg;
l = atoi(args[narg + 1]);}
else if (args[narg] == valueq){
qloc = narg;
q = atoi(args[narg + 1]);}
else if (args[narg] == valuef){
floc = narg;
f = 1;}}
cout << "reached end of check_arguments\n";}

int main(int argc, char *argv[]) {

int floc , lloc , qloc , tloc , f , t , q , l , ngradt , ngradl , ngradq , *tgrades , lgrades , qgrades;

check_arguments( argc , argv);

//set_scores(lloc , tloc , qloc , floc )
/* tgrades = new int[atoi(argv[t])];

for ( int ngradt = 0 ; ngradt <= t ; ngradt++ )

cout << "t is: " << t << "\n";
cout << "ngradt is: " << ngradt << "\n";
cout << "Enter test " << (ngradt + 1) << " grade: ";

cin >> tgrades[ngradt];

cout << "\n";
cout << "f: " << floc << ", " << f << "\n"
<< "l: " << lloc << ", " << l << "\n"
<< "q: " << qloc << ", " << q << "\n"
<< "t: " << tloc << ", " << t << "\n";

return 0;


for some reason I am getting floc as 32767 and f as 59, lloc as 4198229 and l as 0, qloc as 0 and q as 0, tloc as -264176760 and t as 4198160.

wy is this happening and also could I get some insight on what else I can do to get this to work the way I need it to?
Topic archived. No new replies allowed.