•
•
•
•
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
![]() |
•
•
Join Date: May 2008
Posts: 10
Reputation:
Rep Power: 1
Solved Threads: 0
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...
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...
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.
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...
cplusplus Syntax (Toggle Plain Text)
#include <iostream> #include <fstream> #include <cstring> #include <cctype> #include <iomanip> using namespace std; const int MAX = 30; const int MAX_HW = 10; const int MAX_E = 3; struct file1 { int id; string fname; string lname; int hw_num [MAX_HW]; int exam_num [MAX_E]; double exam_score; double hw_score; }; void fixstring (string&); void get_data (file1 [], int&); void alpha (file1 [], int); void initial (file1 [], int); void first (file1 [], int); int main () { string filename1; string studentinfo; string filename2; string gradeinfo; string filename3; string results; char ch; int x, x1, y, y1, z, z1; file1 names [MAX]; //file2 grades [MAX]; ifstream inf1; ifstream inf2; ofstream outf; int n = 0; cout << "Please enter name of student information file:" << endl; cin >> filename1; cout << "Please enter name of grade information file:" << endl; cin >> filename2; cout << "Please enter name of output file:" << endl; cin >> filename3; inf1.open (filename1.c_str()); inf2.open (filename2.c_str()); outf.open (filename3.c_str()); initial (names, n); inf1 >> names[n].id; while (!inf1.eof()) { inf1 >> names[n].lname >> names[n].fname; fixstring (names[n].lname); fixstring (names[n].fname); n++; inf1 >> names[n].id; } inf1.close(); alpha(names, n); outf << right << setw (4) << "NAME" << setw (40) << "ID#" << endl; for ( int x = 0; x < n; x ++) { //outf << names[n].fname << ", " << names[n].lname << names[n].id << endl; outf << names[x].lname << ", " << names[x].fname << right << setw (40 - names [x].lname.length () - names [x].fname.length ()) << names\ [x].id << endl; } outf << endl <<endl; outf << right << setw (44) << "HOMEWORK" << endl; outf << left << setw (44) << "NAME"; for (int y = 1; y <= 10; y++) outf << right << setw (5) << y; outf << endl; for ( int x = 0; x < n; x ++) { //outf << names[n].fname << ", " << names[n].lname << names[n].id << endl; outf << names[x].lname << ", " << names[x].fname << left << setw (40 - names [x].lname.length () - names [x].fname.length ()) << " "; for (int y = 1; y <= 10; y++) outf << right << setw (5) << y; outf << endl; } outf << endl <<endl; outf << right << setw (44) << "EXAM" << endl; outf << left << setw (44) << "NAME"; for (int y = 1; y <= 3; y++) outf << right << setw (5) << y; outf << endl; for ( int x = 0; x < n; x ++) { //outf << names[n].fname << ", " << names[n].lname << names[n].id << endl; outf << names[x].lname << ", " << names[x].fname << right << endl; } outf << endl <<endl; outf.close (); return 0; } void fixstring (string& names) { int wlen = names.length(); names[0] = toupper (names[0]); for (int i = 1; i < wlen; i++) names [i] = tolower (names[i]); } void alpha ( file1 names [], int n) // Given the string "names", alpha will read in the file and place and arrange the names accordingl \ // y and put them in a particular order. The alphabetized array of strings will then be passed back. { int i;// initializing integer datatype to i int j;// intiializing integer datatype to j file1 temp;// string datatype being justified for temp to be used within function for (i=0; i < n-1; i++) { for (j=0; j < n - (i+1); j++) { if (names[j].lname > names [j+1].lname) { temp = names[j]; names [j] = names [j+1]; names [j+1] = temp; } } } } void initial (file1 names[], int n) { int x, q; for (x = 0; x < n; x++) { cin >> names[n].id; for (q = 0; q = 10; q++) names[n].hw_num[q] = 0; } }
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
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
•
•
Join Date: May 2006
Location: homeworkhelp.co.in
Posts: 798
Reputation:
Rep Power: 4
Solved Threads: 59
c++ Syntax (Toggle Plain Text)
names[0] = toupper (names[0]);
cout << Homework Help << Freelance Services << Top 10 Web Host;
cout << Build A Website << Interview Question And Answer << Tax Filing;
cout << Build A Website << Interview Question And Answer << Tax Filing;
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
Similar Threads
- errors in my file but not sure whats wrong file attatched (Visual Basic 4 / 5 / 6)
- Googles Patent is out (Search Engine Optimization)
- Would someone please explain what folding means? (Geeks' Lounge)
- WHo can explain this code to me?? (C)
- Will somebody please explain value parameters to me!!! (C)
- Scientists explain why santa doesn't exist (Geeks' Lounge)
- Factorial program (Java)
- don't understand (C++)
- my IE has been hijacked by res://mbnuq.dll/index.html#96676 (Viruses, Spyware and other Nasties)
Other Threads in the C++ Forum
- Previous Thread: output missing data
- Next Thread: Brainteaser codes


Linear Mode