Hi, I have never used a forum like this before but I am stuck! I have to write a C++ program that allows the user to enter up to 20 students info. It must include Nem, Exam 1 grade, exam 2 grade, Homework average, final exam average. For each student, the program should first calculate a final grade using the formula:
Final grade = 0.20 * exam 1 grade + 0.20 * exam 2 grade + 0.35 * Home work avearge + 0.25 * final exam grade and then assign a letter grde - All information should then be displayed and written to a file - I have been having a real tough time with programming for some reason - Everyone in my class just seems to get itand I am really struggling - Well anyway this is what I have so far and If anyone knows of soem good resources to help me learn this class better other than the text book I would appreictae the information! Thanks

#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <TCHAR.H>
#include <vector>
#include <algorithm>
using namespace std;
 
class Grade
{
private:
    string name;
    int exam1, exam2, homework, finalExam;
 
public:
    Grade(){setGrade("Tom", 94, 92, 87 ,85);};
    Grade(string name, int ex1, int ex2, int hw, int final){setGrade(name, ex1, ex2, hw,final);}
    void setGrade(string nm, int ex1, int ex2, int hw, int final){name=nm; exam1=ex1; exam2=ex2; homework=hw; finalExam=final;};
    string getName(){return name;};
    int getExam1(){return exam1;};
    int getExam2(){return exam2;};
    int getHomework(){return homework;};
    int getFinalExam(){return finalExam;};
};
 
int _tmain(int argc, _TCHAR* argv[])
{
    const int Grades = 5;
    string filename = "grades.dat";
    string name;
    ofstream outFile;
    int i, exam1, exam2, homework, finalExam;
    Grade g;
    vector<Grade> gTable;
 
    outFile.open(filename.c_str());
    if(outFile.fail())
    {
        cout << "The file was not successfully opened."<<endl;
        exit(1);
    }
 
    outFile << setiosflags(ios::fixed)
            << setiosflags(ios::showpoint)
            << setprecision(2);
 
    for(i=0; i<Grades; i++)
    {
        cout <<"\nEnter students name, 1st exam grade, 2nd exam grade, homework average, and final exam grade (type done to exit): \n";
        cin >> name>>exam1>>exam2>>homework>>finalExam;
        if(name=="exit")
            break;


        cout <<"\nFor the students the following data has been written to the file: \n";
        cout <<name<<" "<<exam1<<" "<<exam2<<" "<<homework<<" "<<finalExam<<endl;
 
        g=Grade(name, exam1, exam2, homework, finalExam);
        gTable.push_back(g);
    }
 
    for(i=0; i<gTable.size(); i++)
    {
        outFile <<gTable[i].getName()<<" "
                <<gTable[i].getExam1()<<" "
                <<gTable[i].getExam2()<<" "
                <<gTable[i].getHomework()<<" "
                <<gTable[i].getFinalExam()<<endl;
    }
    outFile.close();
    cout << "The file " << filename
         << " has been successfully written." << endl;
 
    cin.ignore();cin.ignore();
 
    return 0;
}

Once we cot CODE tags in your post, you have some very nicely formatted code!

I don't see where your equation has been implemented. Can you figure out where it should go?

I believe it needs to go around line 21 or so - But really I am not sure - i have written a code to just calculate grades before but since I had to get into the writing to a file - I have completely confused myself!

What's the purpose of the equation? What function is responsible for this feature? That's where it goes... Somewhere around 21 is correct.

I do not appreciate the last two comments and I have not seen any code similar to mine - If I were cheating I would at least pick one that is done - I am very new to this programming and the forum but i thought comments like that were not allowed - Also, I did take portions of my code from my text book if that is what you are referring to but i thought that was the point of having a text book for the class. If you cannot be helpful then why are you even replying?

>I do not appreciate the last two comments
Don't worry. Others will appreciate them. :)

>and I have not seen any code similar to mine
Here's one: http://www.daniweb.com/forums/thread95911.html

>If I were cheating I would at least pick one that is done
I don't know, I've seen some pretty lame attempts to cheat over the years.

>If you cannot be helpful then why are you even replying?
I also can't be helpful because you really haven't asked a proper question yet. You've mentioned a formula, said you're having trouble finishing the program, and posted the code. This suggests you want the work done for you, which we won't do. Walt pushed you in the right direction as much as he could without giving you code for the solution, so where's your updated attempt?

>I do not appreciate the last two comments
Don't worry. Others will appreciate them. :)

>and I have not seen any code similar to mine
Here's one: http://www.daniweb.com/forums/thread95911.html

>If I were cheating I would at least pick one that is done
I don't know, I've seen some pretty lame attempts to cheat over the years.

LOL Narue you are my new idol. <3 and yes i appreciate it.
bums who want everything done for them are lose. This site helps out, a lot i might add. It a give take situation. They do not do the work for you. Read the stickys before posting and you will understand.

If you must know where my attempt is - it has not been done yet - I am checking this at work - I havenot worked on it since last night with the other guy and I have two children who had me tied up after I started with him -I planned on inputing the formula tonight but I can se that i won't get any assistence here - I will go back to winging it on my own like I was. And I suggest you find out situations before you accuse - If you notice I have not asked another question since Walt had responded becauses I have not gotten to it yet - Instead I am wasting time at my job replying to this junk

>but I can se that i won't get any assistence here
If you keep failing to ask a smart question, that's probably an accurate observation.

>I will go back to winging it on my own like I was.
That's actually the best way to learn. Unlike you, I didn't have the internet. I didn't have ready access to all kinds of wonderful resources or experts willing to help. I like to think that the experimenting I had to do at the time is why I'm that much better than I would be if I were spoonfed everything like most of the beginners these days.

>And I suggest you find out situations before you accuse
I call it like I see it. If you don't like that, change how it looks.

>If you notice I have not asked another question since
>Walt had responded becauses I have not gotten to it yet
Okay, then I suggest you follow your own advice. If you can't be helpful (in helping us help you), why are you even replying?

>Instead I am wasting time at my job replying to this junk
It seems we have something in common then. :D

You really are ridiculous - i hope you are happy that you have discouraging someone from trying to get help - Everything int taht code was my own and I got stuck _ i asked for help - i though that the was the point - I can't do it at work where I was repling - I don't have my compiler there - And maybe I do have internet acces buT it certainly has not taught me how to do this class - i am trying to learn as much as I can and i do not believe I asked a stupid question - I asked what the next step might be or did anybody know of any additional resources where I could look to help teach me this stuff since I know taking peices from the text bookis not the best way to learn -Obvioulsy this isn't either if I cannot ask a question without getting all this back instead of advice like Walk gave - And I don't get to sit infrom of a computer all day and reply crule things to peopeles posts - I have a job and A family as well as full time school - And i really think you making a whole lot more out of a post of me asking for assistnece than anything I ahve ever seen - like I said - I can see this is not a friendly forum and I will just take stuff out of the text like I was and get no explanation for what I am doing.

Sometimes misspelling a word can effect the outcome of your coding

IE

char peoples = 'Narue';
count << peopeles;

It can also help you make your point come across a bit clearer

IE

I asked what the next step might be or did(if) anybody know(knew) of any additional resources where I could look to help teach me(myself) this stuff since I know taking peices(pieces) from the text bookis(book is) not the best way to learn-(.)

>If you notice I have not asked another question since
>Walt had responded becauses I have not gotten to it yet
Okay, then I suggest you follow your own advice. If you can't be helpful (in helping us help you), why are you even replying?

word.

>You really are ridiculous <snip>
I'd recommend that you review the use of punctuation in written English. A dash isn't acceptable punctuation for correcting run-on sentences.

>I can see this is not a friendly forum and I will just take stuff out
>of the text like I was and get no explanation for what I am doing.
Okay. Bye bye. Oh wait, you were trying to martyr yourself, weren't you? Otherwise you would simply have left without making a big stink about how you've been slighted, we're all evil people, and you're going to run off to suffer, all alone with your book that doesn't teach anything.

Boo-hoo, cry me a river, play me a tune on the violin, then shut the hell up and go away already. You clearly aren't going to ask a smart question (look, I even linked you to it again), and it seems you're only interested in being a whiney baby. So shoo; go away and grow up a bit.

Jeez! C'mon. Stop the mud slinging.

mandsmom, if you don't like an answer, say thanks and ignore it. Narue is one of the best programmers here, but she's also one of the most annoying if she thinks you're not listening or she believes you aren't trying. Sorry, you have to deal with it.

If you liked what I said, try it and move on.

As for the post of Narue's that pissed you off, she was right on all counts. We all have seen lame attempts at cheating. But if you didn't cheat, the statement doesn't apply to you. Ignore it. Etc.

So change your code and try it again. Post if it still doesn't work, and ignore everyone but me! :cool:

This article has been dead for over six months. Start a new discussion instead.