944,120 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1592
  • C++ RSS
Apr 9th, 2005
0

what is the problem

Expand Post »
Write program that reads some information of 10 students (name [max 15] , level number , #of points , #of hours , GPA , student id ). These fields should be filled for each student by user except GPA. The GPA (max: 5) should be calculate it by function that takes #of points , #of hours as arguments and return the value of GPA.
Using small menu, the user can done some operations:
1. print all information for specific name
2. print all students names and ids that their GPA more than 4
3. sort the students information using student name
4. exit


here is the code
C++ Syntax (Toggle Plain Text)
  1. #include<iostream.h>
  2. #include<string.h>
  3. float fun(float arr[][1],float arr[][3]){
  4.  
  5. arr[i][5]=(arr[i][1]/arr[i][2]);
  6. return arr[i][5];}
  7. int main(){
  8. char ch,temp;
  9. int i,b,a,num;
  10. char arr_name[10];
  11. float arr[10][5];
  12. cout<<"this is a small menu to show what this program do\n";
  13. cout<<"to use this program you should use the same order of \n";
  14. cout<<"the menu......\n";
  15. cout<<" *^*^*^*****^*^*^*\n";
  16. do{
  17. cout<<"1. print all information for specific name.\n";
  18. cout<<"2. prints all student's names and id's that their GPA more than 4.\n";
  19. cout<<"3. sort the student information using the student's name.\n";
  20. cout<<"4. exit.\n";
  21. cin>>num;
  22.  
  23. switch(num){
  24. case 1 :for(i=0;i<10;i++){
  25.  
  26. cout<<"enter the name for student "<<i<<endl;
  27. gets(arr_name[ch]);
  28. cout<<"enter the student's level number: ";
  29. cin>>arr[i][0];
  30. cout<<"enter the student;s points of all classes: ";
  31. cin>>arr[i][1];
  32. cout<<"enter the students hours of all classes: ";
  33. cin>>arr[i][2];
  34. cout<<"enter the student's id number: ";
  35. cin>>arr[i][3];
  36. arr[i][5]=fun(arr[][1],arr[][2]);
  37. cout<<"the GPA for student number "<<i<<" is "<<arr[i][5]<<endl;
  38. }
  39. break;
  40. case 2 :for(i=0;i<10;i++){
  41. if(arr[i][5]>4)
  42. cout<<"the student's name is : "<<arr_name[i]<<" id number: "<<arr[i][4]<<"\n";
  43. }
  44. break;
  45. case 3 :for(i=0;i<10;i++){
  46. for(a=0;a<10;a++){
  47. for(b=9;b<=a;b--){
  48. if (arr_name[b-1]>arr_name[b]){
  49. temp=arr_name[b-1];
  50. arr_name[b-1]=arr_name[b];
  51. arr_name[b]=temp;}
  52. }
  53. }
  54. cout<<arr_name[i];
  55. }
  56. break;
  57. case 4 :cout<<"thank you for visiting this program\n";
  58. break;
  59. }while(num!=4);
  60. return 0;
  61. }
  62. }
<< moderator edit: added [code][/code] tags -- start doing this yourself >>
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster
some one is offline Offline
129 posts
since Apr 2005
Apr 9th, 2005
0

Re: what is the problem

float fun(float arr[][1],float arr[][3]){

	arr[i][5]=(arr[i][1]/arr[i][2]);
	return arr[i][5];}
Which is who?

Proper formatting such as indenting and whitespace can also make it a whole lot easier to read your own code to find mistakes.
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Apr 9th, 2005
0

Re: what is the problem

please some one help me with this code
Reputation Points: 10
Solved Threads: 0
Junior Poster
some one is offline Offline
129 posts
since Apr 2005
Apr 9th, 2005
0

Re: what is the problem

>what is the problem
What are the symptoms? I can point out a lot of stuff that could be considered a "problem", but since we can't read your mind, we don't know which of them you're referring to.

Dave also asked you a question and suggested a way to improve your chances of finding the problem on your own. You post here often, and I can't help but notice that your formatting style is inconsistent and doesn't promote readability.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Apr 10th, 2005
0

Re: what is the problem

>>Dave also asked you a question and suggested a way to improve your chances of finding the problem on your own

sorry Dave but I did not Know what you mean because the english is not my native language

>>You post here often

is this buther you ??
I post here cause I do not have any one to teach me but if you notice that I always try and post my trying also

any way thanks dave,narue

your sis
some one
Reputation Points: 10
Solved Threads: 0
Junior Poster
some one is offline Offline
129 posts
since Apr 2005
Apr 10th, 2005
0

Re: what is the problem

>is this buther you ??
Not at all. I like activity on my forums. However, if you wrote code so that it's easier to read and easier to debug, you would be able to solve most of your problems. Making code work is a more important skill that writing code from scratch, because you do it more often. If you're always asking for help then you're not building that skill as you should be.

>sorry Dave but I did not Know what you mean
He meant that you have two arrays, both called arr. That won't work, and since we don't know which array goes where in your expression, we can't help you fix it.

And you still haven't told us the problem that you're having. You just said you have a problem, posted the program requirements, and a bunch of code that's hard to read.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Apr 10th, 2005
0

Re: what is the problem

okay thanks but the problam was that the code did not work
Reputation Points: 10
Solved Threads: 0
Junior Poster
some one is offline Offline
129 posts
since Apr 2005
Apr 10th, 2005
0

Re: what is the problem

>but the problam was that the code did not work
*sigh*

You seem to have trouble with this concept. "It doesn't work" is about as helpful as just posting your code with no explanation at all. There are degrees of "not working". Does it compile? Do you get errors? When it runs, does it crash? If not, how far does it get before doing something other than you expected? What did you expect? What did it do that differs from that?

Nobody likes debugging, and nobody is going to help you unless you make it as easy as possible to solve your problem.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: help me in this home work please
Next Thread in C++ Forum Timeline: Unexpected output when program exucuted





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC