im a chem major and im required to take c++.. i learned some basic stuff (floating point/2s comp systems, basic programming) but im iffy on whether im getting a C or not.. our instructor gave us a bonus assignment but its super complicated and beyond what i understand.. can anybody help me with this??

i need to develop a program that reads from an imput file (studentsGrades.txt) student first name, middle initial, and last name, in addition to his grades in three tests. my program has to calculate the total grades of the three tests for each student and output in an output file (studentResult.txt) the student last name, midille initial and fisrt name, sorted in the alphapatical order of last names, total grade, average and the letter P for pass or F for fail. A student passes if he or she gets more than 60% of the total grade. my program should also produce the avergae grade and the total number of students, the number of those who passed.

my input file (studentsGrades.txt):
Martin A Mason 50 60 50
James P. Thomas 90 70 80
Gary H. Bowman 100 80 70

output file (studentsResult.txt) should look like:

Bowman, H. Gary 250 P
Martin, A. Mason 160 F
Thomas, P. James 240 P

In addition to the output file, it should output to the screen the following:

Number of students processed: 3
Average grade: 216.66
Number of students passed: 2

Please show some effort. We will not do your homework for you. Post your attempt for us to correct.

Please show some effort. We will not do your homework for you. Post your attempt for us to correct.

well id rather learn to do it myself so possibly you could coach me along... might take a lot of coaching though but ill give the effort
===========================================

#include<iostream>
#include<string>
#include<fstream>
 
using namespace std;
 
void main (){
 
string firstName, MidInit, lastName;
int grades;
 
//the following is to open both input and output files (i think!)
fstream studentGradesStream;
fstream studentResultsStream;
 
studentGradesStream.open("a:studentGrades.txt",ios::in);
studentResultsStream.open(a:studentResults.txt",ios::out);
 
//okay this is about where i get hung up
//until the ending which im pretty sure i know how to 
//close the input and output files and end the program
 
studentGradesStream.close();
studentResultsStream.close();
return;
}

1) Use code tags.
2) void main (){ Nope, its int main(){
3) studentResultsStream.open(a:studentResults.txt"... Missing opening quote.

1) Use code tags.
2) void main (){ Nope, its int main(){
3) studentResultsStream.open(a:studentResults.txt"... Missing opening quote.

#include<iostream>
#include<string>
#include<fstream>

using namespace std;

int main (){

string firstName, MidInit, lastName;
int grades;

fstream studentGradesStream;

fstream studentResultsStream;

studentGradesStream.open("a:studentGrades.txt",ios::in);
studentResultsStream.open("a:studentResults.txt",ios:ut);

//okay this is about where i get hung up
//below am i starting to set up the array properly or
//would it be better to use 'double' instead of 'int', i can't
//recognize the difference.. also will i need to have any
//c in or c out code within this problem? i figured i wouldn't

int students [3] 

// again not sure where to go



studentGradesStream.close();
studentResultsStream.close();
return;
}

Now you need to read in the file. You could probably do something along these lines:
- read in a line (I recomment using getline()
- parse that line to get the student's name.
- continue parsing to get a list of scores. Add these together, probably as you read them in.
- compare this to the total score (where are you getting that anyways?) and determine if the student passes.
- do this till you have all of the data read

Then comes the tricky part. You need to sort all the data by students' last name. It would be easiest if you kept the data in an object, but that's not necessary (just a little more hassle without). You need to sort the data by last name, and make sure you keep all associated data together as you do it. This'll be kinda tricky if you just use indepented arrays/vectors of names, scores, etc...

Then output the students info in the new sorted order. As you do this, you could keep track of the number of students, and start averaging their scores. You could also do this in separately, but why put it off till later? Anyways, after you've gone through the list of students you'll have the other statistics you need, so you can output those too.

Good luck ;)

[edit:] oh, and you seem to have missed the part about code tags. Please use them, since it preserves your code formatting and makes it a lot easier for us to read your code and help you.

how exactly do i use code tags.. sorry im totally new on here.. do i just click on the button w/ the quotation above??

example:

int grades;

fstream studentGradesStream;

just put code tags before and after it, like this:

int main(){
  cout << "Hello world" << endl;
  return 0;
}

See how it keeps the indentation? :)

well i won't lie to you the directions you gave me are wayyyy too complicated than what we started to discuss in class.. we got into loops (like a 'while' loop) and simple arrays.. this is an input/output prob.. is there any way you could break it down a little simpler for me so i can keep trying.. we never went over the term parse either..

i really appreciate the help thus far though!!

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.