C++ program write and display to file

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2007
Posts: 5
Reputation: mandsmom is an unknown quantity at this point 
Solved Threads: 0
mandsmom mandsmom is offline Offline
Newbie Poster

C++ program write and display to file

 
0
  #1
Nov 7th, 2007
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
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <cstdlib>
  5. #include <iomanip>
  6. #include <cmath>
  7. #include <TCHAR.H>
  8. #include <vector>
  9. #include <algorithm>
  10. using namespace std;
  11.  
  12. class Grade
  13. {
  14. private:
  15. string name;
  16. int exam1, exam2, homework, finalExam;
  17.  
  18. public:
  19. Grade(){setGrade("Tom", 94, 92, 87 ,85);};
  20. Grade(string name, int ex1, int ex2, int hw, int final){setGrade(name, ex1, ex2, hw,final);}
  21. void setGrade(string nm, int ex1, int ex2, int hw, int final){name=nm; exam1=ex1; exam2=ex2; homework=hw; finalExam=final;};
  22. string getName(){return name;};
  23. int getExam1(){return exam1;};
  24. int getExam2(){return exam2;};
  25. int getHomework(){return homework;};
  26. int getFinalExam(){return finalExam;};
  27. };
  28.  
  29. int _tmain(int argc, _TCHAR* argv[])
  30. {
  31. const int Grades = 5;
  32. string filename = "grades.dat";
  33. string name;
  34. ofstream outFile;
  35. int i, exam1, exam2, homework, finalExam;
  36. Grade g;
  37. vector<Grade> gTable;
  38.  
  39. outFile.open(filename.c_str());
  40. if(outFile.fail())
  41. {
  42. cout << "The file was not successfully opened."<<endl;
  43. exit(1);
  44. }
  45.  
  46. outFile << setiosflags(ios::fixed)
  47. << setiosflags(ios::showpoint)
  48. << setprecision(2);
  49.  
  50. for(i=0; i<Grades; i++)
  51. {
  52. cout <<"\nEnter students name, 1st exam grade, 2nd exam grade, homework average, and final exam grade (type done to exit): \n";
  53. cin >> name>>exam1>>exam2>>homework>>finalExam;
  54. if(name=="exit")
  55. break;
  56.  
  57.  
  58. cout <<"\nFor the students the following data has been written to the file: \n";
  59. cout <<name<<" "<<exam1<<" "<<exam2<<" "<<homework<<" "<<finalExam<<endl;
  60.  
  61. g=Grade(name, exam1, exam2, homework, finalExam);
  62. gTable.push_back(g);
  63. }
  64.  
  65. for(i=0; i<gTable.size(); i++)
  66. {
  67. outFile <<gTable[i].getName()<<" "
  68. <<gTable[i].getExam1()<<" "
  69. <<gTable[i].getExam2()<<" "
  70. <<gTable[i].getHomework()<<" "
  71. <<gTable[i].getFinalExam()<<endl;
  72. }
  73. outFile.close();
  74. cout << "The file " << filename
  75. << " has been successfully written." << endl;
  76.  
  77. cin.ignore();cin.ignore();
  78.  
  79. return 0;
  80. }
Last edited by WaltP; Nov 7th, 2007 at 10:40 pm. Reason: Added CODE tags -- you actually typed right over how to use them when you entered this post...
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: C++ program write and display to file

 
0
  #2
Nov 7th, 2007
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?
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 5
Reputation: mandsmom is an unknown quantity at this point 
Solved Threads: 0
mandsmom mandsmom is offline Offline
Newbie Poster

Re: C++ program write and display to file

 
0
  #3
Nov 7th, 2007
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!
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: C++ program write and display to file

 
0
  #4
Nov 8th, 2007
What's the purpose of the equation? What function is responsible for this feature? That's where it goes... Somewhere around 21 is correct.
Last edited by WaltP; Nov 8th, 2007 at 12:03 am.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,679
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 727
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: C++ program write and display to file

 
0
  #5
Nov 8th, 2007
I'm seeing a lot of the same code from supposedly different people.
Last edited by Narue; Nov 8th, 2007 at 10:28 am.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 2
Reputation: Vallelente_82 is an unknown quantity at this point 
Solved Threads: 0
Vallelente_82 Vallelente_82 is offline Offline
Newbie Poster

Re: C++ program write and display to file

 
0
  #6
Nov 8th, 2007
If they are cheating, at least, they could cheat together
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 5
Reputation: mandsmom is an unknown quantity at this point 
Solved Threads: 0
mandsmom mandsmom is offline Offline
Newbie Poster

Re: C++ program write and display to file

 
0
  #7
Nov 8th, 2007
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?
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 2
Reputation: Vallelente_82 is an unknown quantity at this point 
Solved Threads: 0
Vallelente_82 Vallelente_82 is offline Offline
Newbie Poster

Re: C++ program write and display to file

 
0
  #8
Nov 8th, 2007
calm down, why beeing so seriously? smile and you will see the world WILL smile back at you.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,679
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 727
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: C++ program write and display to file

 
0
  #9
Nov 8th, 2007
>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'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 49
Reputation: helixkod is an unknown quantity at this point 
Solved Threads: 1
helixkod helixkod is offline Offline
Light Poster

Re: C++ program write and display to file

 
0
  #10
Nov 8th, 2007
Originally Posted by Narue View Post
>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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC