User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 363,805 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,619 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser:
Views: 147 | Replies: 1
Reply
Join Date: May 2008
Posts: 10
Reputation: c++ newbie is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
c++ newbie c++ newbie is offline Offline
Newbie Poster

i need someone to explain how this works...

  #1  
May 9th, 2008
ok. i'm having trouble understanding how to manipulate my data. this is what i have so far with my program. my input data is coming from two different file. the first file looks like this that has the student ID, last name, first name...

567 white Robert
43 blackBurBn DOnna
etc...

the second file is set up so that the ID number is first with exam(E), number and grade and hw(H), number and score to follow in no particular order and can be dupes for more than once to get all grades. Q signifying end of line...

43 E 1 95 E 2 89 Q
567 E 1 67 H 1 20 H 5 20 Q
43 H 4 15 H 3 14 Q
etc...

this is my program so far...

  1. #include <iostream>
  2. #include <fstream>
  3. #include <cstring>
  4. #include <cctype>
  5. #include <iomanip>
  6.  
  7. using namespace std;
  8.  
  9. const int MAX = 30;
  10. const int MAX_HW = 10;
  11. const int MAX_E = 3;
  12.  
  13.  
  14. struct file1
  15. {
  16. int id;
  17. string fname;
  18. string lname;
  19. int hw_num [MAX_HW];
  20. int exam_num [MAX_E];
  21. double exam_score;
  22. double hw_score;
  23. };
  24.  
  25. void fixstring (string&);
  26. void get_data (file1 [], int&);
  27. void alpha (file1 [], int);
  28. void initial (file1 [], int);
  29. void first (file1 [], int);
  30.  
  31.  
  32. int main ()
  33. {
  34.  
  35.  
  36. string filename1;
  37. string studentinfo;
  38. string filename2;
  39. string gradeinfo;
  40. string filename3;
  41. string results;
  42. char ch;
  43. int x, x1, y, y1, z, z1;
  44.  
  45.  
  46. file1 names [MAX];
  47. //file2 grades [MAX];
  48.  
  49. ifstream inf1;
  50. ifstream inf2;
  51. ofstream outf;
  52. int n = 0;
  53.  
  54. cout << "Please enter name of student information file:" << endl;
  55. cin >> filename1;
  56. cout << "Please enter name of grade information file:" << endl;
  57. cin >> filename2;
  58. cout << "Please enter name of output file:" << endl;
  59. cin >> filename3;
  60.  
  61. inf1.open (filename1.c_str());
  62. inf2.open (filename2.c_str());
  63. outf.open (filename3.c_str());
  64.  
  65. initial (names, n);
  66.  
  67. inf1 >> names[n].id;
  68.  
  69. while (!inf1.eof())
  70. {
  71.  
  72. inf1 >> names[n].lname >> names[n].fname;
  73. fixstring (names[n].lname);
  74. fixstring (names[n].fname);
  75. n++;
  76. inf1 >> names[n].id;
  77. }
  78.  
  79. inf1.close();
  80.  
  81. alpha(names, n);
  82. outf << right << setw (4) << "NAME" << setw (40) << "ID#" << endl;
  83. for ( int x = 0; x < n; x ++)
  84. {
  85. //outf << names[n].fname << ", " << names[n].lname << names[n].id << endl;
  86. outf << names[x].lname << ", " << names[x].fname << right << setw (40 - names [x].lname.length () - names [x].fname.length ()) << names\
  87. [x].id << endl;
  88. }
  89. outf << endl <<endl;
  90. outf << right << setw (44) << "HOMEWORK" << endl;
  91. outf << left << setw (44) << "NAME";
  92. for (int y = 1; y <= 10; y++)
  93. outf << right << setw (5) << y;
  94. outf << endl;
  95.  
  96.  
  97. for ( int x = 0; x < n; x ++)
  98. {
  99. //outf << names[n].fname << ", " << names[n].lname << names[n].id << endl;
  100. outf << names[x].lname << ", " << names[x].fname << left << setw (40 - names [x].lname.length () - names [x].fname.length ()) << " ";
  101. for (int y = 1; y <= 10; y++)
  102.  
  103. outf << right << setw (5) << y;
  104. outf << endl;
  105.  
  106.  
  107.  
  108. }
  109. outf << endl <<endl;
  110.  
  111. outf << right << setw (44) << "EXAM" << endl;
  112. outf << left << setw (44) << "NAME";
  113. for (int y = 1; y <= 3; y++)
  114. outf << right << setw (5) << y;
  115. outf << endl;
  116. for ( int x = 0; x < n; x ++)
  117. {
  118. //outf << names[n].fname << ", " << names[n].lname << names[n].id << endl;
  119. outf << names[x].lname << ", " << names[x].fname << right << endl;
  120. }
  121. outf << endl <<endl;
  122.  
  123.  
  124.  
  125.  
  126. outf.close ();
  127. return 0;
  128. }
  129.  
  130.  
  131. void fixstring (string& names)
  132. {
  133. int wlen = names.length();
  134. names[0] = toupper (names[0]);
  135. for (int i = 1; i < wlen; i++)
  136. names [i] = tolower (names[i]);
  137. }
  138.  
  139. void alpha ( file1 names [], int n)
  140. // Given the string "names", alpha will read in the file and place and arrange the names accordingl \
  141. // y and put them in a particular order. The alphabetized array of strings will then be passed back.
  142. {
  143. int i;// initializing integer datatype to i
  144. int j;// intiializing integer datatype to j
  145. file1 temp;// string datatype being justified for temp to be used within function
  146.  
  147. for (i=0; i < n-1; i++)
  148. {
  149. for (j=0; j < n - (i+1); j++)
  150. {
  151. if (names[j].lname > names [j+1].lname)
  152. {
  153. temp = names[j];
  154. names [j] = names [j+1];
  155. names [j+1] = temp;
  156. }
  157. }
  158. }
  159.  
  160. }
  161. void initial (file1 names[], int n)
  162. {
  163. int x, q;
  164. for (x = 0; x < n; x++)
  165. {
  166. cin >> names[n].id;
  167. for (q = 0; q = 10; q++)
  168. names[n].hw_num[q] = 0;
  169. }
  170. }

i know i have some extra lines and functions here that i just left in but notated that they arent being used at this time. after compiling my program, this is my results...
NAME                                     ID#
Blackburn, Donna                        43
Brown, Jane                             19
Grey, James                            722
White, Robert                          567


                                    HOMEWORK
NAME                                            1    2    3    4    5    6    7    8    9   10
Blackburn, Donna                              1    2    3    4    5    6    7    8    9   10
Brown, Jane                                   1    2    3    4    5    6    7    8    9   10
Grey, James                                   1    2    3    4    5    6    7    8    9   10
White, Robert                                 1    2    3    4    5    6    7    8    9   10


                                        EXAM
NAME                                            1    2    3
Blackburn, Donna
Brown, Jane
Grey, James
White, Robert
i know that even if it compiles and gives back this data, i am doing it wrong. the first thing i'm trying to figure out is how am i supposed to initialze my homework starting grades so that they are zeroes instead of the my number increment count.

the second thing i'm not understanding is how do i set up my program, once i initialize my data, to know when reading from the second input that 43 = Blackburn, Donna, and to start plugging the appropriate grades in the appropriate slot. i know i'm not the best when it comes to syntax so any modifications/suggestions to make my program more efficient would be greatly appreciated.
Last edited by Ancient Dragon : May 9th, 2008 at 5:08 pm. Reason: add code tags
AddThis Social Bookmark Button
Reply With Quote  
Join Date: May 2006
Location: homeworkhelp.co.in
Posts: 798
Reputation: ithelp is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 59
ithelp ithelp is offline Offline
Master Poster

Re: i need someone to explain how this works...

  #2  
May 9th, 2008
  1. names[0] = toupper (names[0]);
Is it not giving any compilation warning /error ?
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb C++ Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 11:24 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC