My name is James. I am currently taking a c++ class and I have a professor that is less than desirable but is the only one that is teaching the class. I am in need of assistance with some code. At least getting it started anyway.

Here is the assignment:
Write a program for the following problem. You're given a file that contains a collection of IDs and scores(type int) for an exam in your computer course. You're to compute the average of thes scores and assiggn grades to each student according to the following rule:

If a student's score is within 10 points (above or below) of the average, assign a grade of satisfactory. If the score is more than 10 points above average, assign a grade of outstanding. If the score is more than 10 points below average, assign a grade of unsatisfactory.

The output from your program should consist of a labeled three-column list that shows each ID, score, and corresponding grade. As part of the solution, your program should include functions that correspond to the function prototypes that follow.

//reads exam scores into array scores
void readStuData
    (ifstream &rss,      //IN: data file
     int scores[],       //OUT: the scores
     int id[],           //OUT: the IDs
     int &count,         //OUT: Number of students read
     bool &tooMany);     //OUT: A flag to indicate that more
                         //than MAX_SIZE scores items are in
                         //input file.

//computes average of count student scores
float mean(int scores[], int count);

//Displays a table showing each student's ID, score and grade
//on a separate line
//Uses: printGrade
void printTable(int score[], int ID[], int count);

//Prints student grade after comparing oneScore to average
void printGrade(int oneScore, float average);

That is the layout that I have been given by my book. I'm not looking for the entire answer. I am just wondering if somebody can assist me by possibly giving me some pseudo code that I could refer to. I have no clue as to how to start or even where to start. Also, when it comes time to call the functions into the main function I don't know how to do that when it comes to the parameters and calling the function.

The help is greatly appreciated.

Recommended Answers

All 9 Replies

I have no clue as to how to start or even where to start.

Then you're thinking about it the wrong way. Whenever you get overwhelmed with a problem, the problem is too big and needs to be broken down into smaller problems. Instead of doing everything, just open and close the file. Then build on that program by reading and printing one student record. Then build on that program by reading and printing all student records. And so on and so forth.

Keep solving little problems like that and add them to the program. You'll have an easier time writing the program and you'll have more confidence that it's correct.

You have to perform analysis on the data pertinent to an individual after you've processed everyone in the file which means you need to store the information.

Run the list once to find out how many there are!
rewind
create structure array to store the students. One structure each student.
read file again filling in the structures.
crunch the data.
print

How you do it is going to depend on what you know already. Someone who is familiar with classes would use a class. If you haven't used classes, you wouldn't do that. Similarly someone who has used vectors may well use them instead of arrays. Looks like you are required to use arrays.

As Tom Gunn says, a little at a time. I'd say start off by setting up some arrays in main, then writing the printGrade function and calling it. Then write the printTable function. The write the mean function and call that. All of this lets you do things without bothering with ifstream . Then tackle that.

I didn't think of doing it that way. I am still unsure how to call the separate the functions into the main. I have never called functions that have parameters in them.

I appreciate the help from all so far.

We can't do this for you. Start with reading a beginner C book.

Open text file fopen()
read a line (assuming one entry each line
fgets()
loop until end of file.
close file
fclose()
----------
char szBuf[256];

Do it again, this time add a printf( "%s\n", szBuf );
Read the string into szBuf then print it.

and keep adding on from there!
Post your code when you hit a snag and we'll try to help.

I am in C++ we are continuing in a beginner/intermediate book. The book is entitled "Problem Solving, Abstraction, and Design Using C++" by Frank L. Friedman and Elliot B Koffman.

I have never called functions that have parameters in them.

I appreciate the help from all so far.

Then you DO have a less than desirable professor. Programming, like everything else, needs to be taught in stages. Look at this spec:

void readStuData
    (ifstream &rss,      //IN: data file
     int scores[],       //OUT: the scores
     int id[],           //OUT: the IDs
     int &count,         //OUT: Number of students read
     bool &tooMany);     //OUT: A flag to indicate that more
                         //than MAX_SIZE scores items are in
                         //input file.

Not only does it pass several parameters, but one of them is an ifstream, two are arrays, one is an int passed by reference, one is a bool passed by reference.

Now this one:

float mean(int scores[], int count);

Unlike the other one, count here is passed by value, not by reference.

So you've never passed parameters before and you are expected to know:

  1. How to pass an ifstream to a function.
  2. How to pass an array to a function.
  3. How to pass by reference to a function.
  4. How to pass by value to a function.
  5. The difference between passing by reference and by value.

Too much at once. It's all doable, but don't try to understand it all now. I'd suggest putting this assignment aside and finding some tutorials that walk you through the five concepts above individually.

Google each term I listed above and get some sample code and tutorials. When you have the hang of it all, come back to this problem. That'd be my approach.

Thanks again. I will certainly do that. If I hit another snag I shall be sure to ask.

i find it pretty incredible that a professor would dump all this at once to beginners who had never passed arguments to functions before

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.