943,851 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 1657
  • C RSS
Aug 6th, 2007
0

file and multidimensional array

Expand Post »
Hi,

I need help for this C Program very urgent. please find the attachment below
Attached Files
File Type: doc q2[1].doc (92.5 KB, 19 views)
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kgbalaji1980 is offline Offline
1 posts
since Aug 2007
Aug 6th, 2007
0

Re: file and multidimensional array

> I need help for this C Program very urgent
http://www.catb.org/~esr/faqs/smart-...ns.html#urgent
Urgency is your problem, not mine.

> please find the attachment below
http://www.catb.org/~esr/faqs/smart-...s.html#formats
I'm not interested in even risking downloading a non-portable file format which is prone to all sorts of virus infections.
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Aug 6th, 2007
0

Re: file and multidimensional array

>>I'm not interested in even risking downloading a non-portable file format which is prone to all sorts of virus infections

Absolutely agree with that -- *.doc files have been known to contains viruses, worms and other kinds of animals. Kg: save your program as *.c and either post it or attach it if its too big to post.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,951 posts
since Aug 2005
Aug 6th, 2007
0

Re: file and multidimensional array

Hi,

I need help for this C Program very urgent. please find the attachment below
Post what the program is suppose to do, and what is not doing correctly. Post any error messages you are getting at compile time, in essence tell us what's the problem that you are having with it.

And then, maybe we could help.
Last edited by Aia; Aug 6th, 2007 at 6:28 pm.
Aia
Reputation Points: 2224
Solved Threads: 218
Nearly a Posting Maven
Aia is offline Offline
2,304 posts
since Dec 2006
Aug 8th, 2007
0

Re: file and multidimensional array

Hi There,
Here you go. Please find your requsted program below.
  1. /******************************************************************************\
  2.  * QUESTION #2 *
  3.  * Create a program that will keep track of 5 students and their grades. *
  4.  * The grades will be kept in an array of up to 10 grades. *
  5.  * To do this, you will need to create a multi-dimensional array of grades *
  6.  * where each column (or row) is assigned to each student. *
  7. \******************************************************************************/
  8.  
  9.  
  10.  
  11. #include <stdio.h>
  12. #include <conio.h>
  13. #include <stdlib.h>
  14. #include <string.h>
  15.  
  16. float grade[5][10];
  17. char *StudentNames[5]= {0};
  18. int totalStudent=0;
  19.  
  20. int AddStudentName(void);
  21. int EnterGrades(void);
  22. int DisplayData(void);
  23.  
  24. int main(int argc, char* argv[])
  25. {
  26. int i=0,j=0;
  27. for(i=0;i<5;i++)
  28. for(j=0;j<10;j++)
  29. grade[i][j] = -1;
  30.  
  31.  
  32. while(1)
  33. {
  34. char choice;
  35. printf("\n\n\n\n");
  36. printf("\n/**********************************************************\\");
  37. printf("\n * Chioce Function *");
  38. printf("\n ********************************************************* ");
  39. printf("\n * 1 Add student name. *");
  40. printf("\n * 2 Enter Grades. *");
  41. printf("\n * 3 Display student-grade data. *");
  42. printf("\n * Any othey key Exit program. *");
  43. printf("\n\\**********************************************************/");
  44. printf("\nEnter Chioce:..");
  45. choice=getche();
  46. switch(choice)
  47. {
  48. case '1':
  49. AddStudentName();
  50. break;
  51. case '2':
  52. EnterGrades();
  53. break;
  54. case '3':
  55. DisplayData();
  56. break;
  57. default:
  58. return 0;
  59. }
  60.  
  61. }
  62.  
  63.  
  64. return 0;
  65. } //end main
  66.  
  67. int AddStudentName(void)
  68. {
  69. if(totalStudent < 5)
  70. {
  71. char sName[50]={0};
  72. totalStudent++;
  73. printf("\nEnter Student %d name(default-Student%d) : ",totalStudent,totalStudent);
  74. flushall();
  75. gets(sName);
  76. if(strlen(sName)==0)
  77. sprintf(sName,"Student%d",totalStudent);
  78.  
  79. StudentNames[totalStudent-1] = (char *)calloc(strlen(sName)+1,sizeof(char));
  80. strncpy(StudentNames[totalStudent-1],sName,strlen(sName));
  81.  
  82. }
  83. else
  84. {
  85. printf("\n **** Maximum 5 student can be entered. Press any key to continue.");
  86. getch();
  87. }
  88. return 0;
  89. }
  90. int EnterGrades(void)
  91. {
  92. if(totalStudent != 0)
  93. {
  94. int studentNo=0, j=0;
  95. int choice;
  96. printf("\nChoice - Student Name");
  97. for(;studentNo<totalStudent;studentNo++)
  98. printf("\n%4d - %s",studentNo+1,StudentNames[studentNo]);
  99.  
  100. printf("\n\nSelect student for whom you want to enter grade. Enter chioce...");
  101. choice = getche();
  102. studentNo = choice-1-'0';
  103.  
  104. while(j<10 && grade[studentNo][j]!=-1) j++;
  105.  
  106. if(j==10)
  107. printf("\n10 grades already entered for the selected student. No more grade can be entered.");
  108. else
  109. {
  110. printf("\n Enter Grade : ");
  111. scanf("%f",&grade[studentNo][j]);
  112. }
  113. }
  114. else
  115. {
  116. printf("\nPlease Enter student Names first. Press any key to continue.");
  117. getch();
  118. }
  119.  
  120. return 0;
  121. }
  122. int DisplayData(void)
  123. {
  124. if(totalStudent != 0)
  125. {
  126. int i=0,j=0;
  127. for(i=0;i<totalStudent;i++)
  128. {
  129. if(StudentNames[i]!=0)
  130. printf("\n Student Name : %s",StudentNames[i]);
  131.  
  132. for(j=0;j<10;j++)
  133. {
  134. if(grade[i][j]!=-1)
  135. printf("\n\t\t - Grade %d = %d", j+1, grade[i][j]);
  136. else if(j==0)
  137. {
  138. printf("\n\t** No Grade entered for the student..\n");
  139. break;
  140. }
  141. else
  142. {
  143. printf("\n");
  144. break;
  145. }
  146.  
  147. }
  148. }
  149. printf("\n == End of data.. == \n");
  150. }
  151. else
  152. {
  153. printf("\n======== No data to Display. ========= Press any key to continue.");
  154. getch();
  155. }
  156. getch();
  157. return 0;
  158. }
Reputation Points: 13
Solved Threads: 2
Newbie Poster
ashishtrivedi is offline Offline
12 posts
since Jul 2005
Aug 9th, 2007
0

Re: file and multidimensional array

  1. gets(sName);

Definitely a show stopper. Do yourself a favor and don't
use gets() anymore. Forget that it exists. Here's why.

  1. #include <conio.h>
  2.  
  3. flushall();
  4. getch();

These are not C standards. Best to not use them, specially
to help other people.
Aia
Reputation Points: 2224
Solved Threads: 218
Nearly a Posting Maven
Aia is offline Offline
2,304 posts
since Dec 2006
Aug 9th, 2007
0

Re: file and multidimensional array

>>These are not C standards
you are right -- getch() is non-standard, but flushall() is. Its declared in stdio.h.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,951 posts
since Aug 2005

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: Need Help -- Database connectivity in C
Next Thread in C Forum Timeline: typedef or a multidimensional array?





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


Follow us on Twitter


© 2011 DaniWeb® LLC