| | |
Intro and question
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
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.
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.
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.
C++ Syntax (Toggle Plain Text)
//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.
•
•
•
•
I have no clue as to how to start or even where to start.
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.
Last edited by Tom Gunn; Jul 2nd, 2009 at 5:11 pm.
-Tommy (For Great Justice!) Gunn
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
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.
•
•
Join Date: Jan 2008
Posts: 3,810
Reputation:
Solved Threads: 501
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
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. 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.
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.
•
•
Join Date: Jan 2008
Posts: 3,810
Reputation:
Solved Threads: 501
•
•
•
•
I have never called functions that have parameters in them.
I appreciate the help from all so far.
C++ Syntax (Toggle Plain Text)
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:
C++ Syntax (Toggle Plain Text)
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:
- How to pass an ifstream to a function.
- How to pass an array to a function.
- How to pass by reference to a function.
- How to pass by value to a function.
- 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.
Last edited by VernonDozier; Jul 2nd, 2009 at 6:33 pm.
![]() |
Similar Threads
- Inputting values from a different text file (C++)
- C command-line I/O question (C++)
- Perfumedreams w/ Intro and Question (Community Introductions)
- Completely new to C++ and have question about using char (C++)
- Context-sensitive grammar question :( (Computer Science)
- Welcome PC Mod Kingdom peeps! (Geeks' Lounge)
- Laptop LCD built into a car? (Monitors, Displays and Video Cards)
- Changing Network Configuration (*nix Software)
Other Threads in the C++ Forum
- Previous Thread: Saving STL Maps to file as Binary(Possible?)
- Next Thread: How to make a non-blocking socket?
| Thread Tools | Search this Thread |
api array based beginner bitmap c++ c/c++ calculator char class classes code coding compile compiler console conversion count database delete deploy desktop developer directshow dll download dynamic email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number output parameter pointer problem program programming project python random read recursion recursive return sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






