I need help please

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

Join Date: Dec 2007
Posts: 2
Reputation: ahmedusa2005 is an unknown quantity at this point 
Solved Threads: 0
ahmedusa2005 ahmedusa2005 is offline Offline
Newbie Poster

I need help please

 
0
  #1
Dec 17th, 2007
Dear Members
I have started the following program, and I do not know how to solve the issue to store names in an array and retrieve them again, and how tos tore the names in a file in the Hard drive. If somebody could help me with my issue. Thanks so much
Ahmed.

Source Code

  1. #include <iostream.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4. main()
  5. {
  6.  
  7. float grade[25][2]={0,0,0};//first grade, second grade
  8. char studentsname[25][13];//students' names
  9. char name;
  10. int num =0;
  11. int test;
  12. char yesorno = 'y';
  13.  
  14. for (int i=0; i<5 ; i++)
  15. {
  16. cout<<"Enter name of student number "<<i+1<<'\n';
  17. cin>>studentsname[i][];
  18.  
  19.  
  20. for (int j=0; j<2; j++)
  21. {
  22.  
  23. cout<<"Enter grade of test "<<j+1<<" for student "<<studentsname[i+1][13]<<" : ";
  24. cin>>grade[i][j];
  25. cout<<'\n';
  26. }
  27.  
  28. }
  29.  
  30. while (yesorno =='y')
  31. {
  32.  
  33.  
  34. cout<<"Enter a student's name : ";
  35. cin>>name;
  36. for (i=0; i<25; i++)
  37. {
  38. if (name == studentsname[i][13])
  39. {
  40.  
  41. cout<<"Which score woudl like to see 1 or 2 : ";
  42. cin>>test;
  43. cout<<'\n';
  44.  
  45. cout<<"student "<<name<<"] got "<<grade[num-1][13]<<" in test "<<test<<'\n';
  46. cout<<"Would you like to continue : (y/n) ?\n";
  47. cin>>yesorno ;
  48. }
  49. else
  50. cout<<"This student is not among the class ";
  51.  
  52. }
  53. }
  54.  
  55. return 0;
  56. }
Last edited by cscgal; Dec 18th, 2007 at 5:05 pm. Reason: Added code tags
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 37
Reputation: neosomosis is an unknown quantity at this point 
Solved Threads: 0
neosomosis's Avatar
neosomosis neosomosis is offline Offline
Light Poster

Re: I need help please

 
0
  #2
Dec 17th, 2007
Ok...firstly, u really should learn about <fstream>
Declaration:

#include <fstream>

..
...

//in your main()

ofstream fout;
fout.open("NEW.txt");

fout<<name; //this goes after user inputs @ after you stored students' names into -> name
..
...
..
//once done, close the file
fout.close();
Last edited by neosomosis; Dec 17th, 2007 at 3:37 pm. Reason: typo
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 37
Reputation: neosomosis is an unknown quantity at this point 
Solved Threads: 0
neosomosis's Avatar
neosomosis neosomosis is offline Offline
Light Poster

Re: I need help please

 
0
  #3
Dec 17th, 2007
This is how to store something into an array:

for(int i=0;i<25;i++){
string name[i];
cout<<"Enter student's name: ";
cin>>name[i];
}

for(i=0;i<25;i++)
cout<<name[i];

These should work....The rest, is up to you
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 2
Reputation: ahmedusa2005 is an unknown quantity at this point 
Solved Threads: 0
ahmedusa2005 ahmedusa2005 is offline Offline
Newbie Poster

Re: I need help please

 
0
  #4
Dec 17th, 2007
Tahnk you so much


Originally Posted by neosomosis View Post
This is how to store something into an array:

for(int i=0;i<25;i++){
string name[i];
cout<<"Enter student's name: ";
cin>>name[i];
}

for(i=0;i<25;i++)
cout<<name[i];

These should work....The rest, is up to you
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 37
Reputation: neosomosis is an unknown quantity at this point 
Solved Threads: 0
neosomosis's Avatar
neosomosis neosomosis is offline Offline
Light Poster

Re: I need help please

 
0
  #5
Dec 18th, 2007
no problem, dude....u just got to code & research more...hohoho...no offense
Reply With Quote Quick reply to this message  
Reply

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



Other Threads in the C++ Forum
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC