English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I need a program that gets the data of 5 students and puts it in a record named "student" that contains: INT id, CHAR * name, FLOAT average..and then stores them in a file.the output of the program should be the list of the students.

2006-10-29 04:29:59 · 3 answers · asked by Kourosh 1 in Computers & Internet Programming & Design

3 answers

I guess that's why you take the course.

You have to define a new type or class for your record format, create a small write function for it and finally call that function from main to write the 5 records.

2006-10-29 04:39:23 · answer #1 · answered by juliepelletier 7 · 2 0

Don't be lazy. Read your programming book and figure it out. In one file, write a class for the student record. Add a "toString" method that creates a string that has the student info. In another file, you'll need a loop in the main program that can iterate 5 times, each time creating a new student record. You can "get the data" using "cin" to read from the command line and put each item into the appropriate field of the data type. Open a file and write the record string out to it.

2006-10-29 04:57:01 · answer #2 · answered by Mike 1 · 2 0

properly you ought to study up approximately document dealing with in C as for the struct it quite is an precis documents style so which you cna outline it to do something - as you're wanting the information of 10 pupils you ought to use an array, a linked record could be greater ideal yet i believe that your programming potential does no longer be up for it even though it would help with deleting. So right it rather is a coarse and arranged theory of what you will be able to desire to do attempt this code to initiate with after which advance on it #contain #contain #contain int age (int date, int month, int 3 hundred and sixty 5 days); int important (void) { document *infile, *outfile1, *outfile2; /* attempt and make this a struct */ int recno, birthdate, birthmonth, birthyear, ageyears; char intercourse; if ((infile=fopen("pupils.txt","r")) == NULL) { printf("errors: enter document pupils.txt can't be opened"); equipment("pause"); return a million; } if ((outfile1=fopen("M.txt","w")) == NULL) { printf("errors: output document M.txt can't be opened"); equipment("pause"); return a million; } if ((outfile2=fopen("F.dat","w")) == NULL) { printf("errors: output document F.dat can't be opened"); equipment("pause"); return a million; } jointly as ( fscanf(infile, "%d %*s %c %d %d %d", &recno, &intercourse, &birthdate, &birthmonth, &birthyear) > 0 ) { ageyears = age ( birthdate, birthmonth, birthyear ); if ( intercourse == 'M' ) fprintf ( outfile1, "%-8dpercent2dn", recno, ageyears ); else if (intercourse == 'F' ) fprintf ( outfile2, "%-8dpercent2dn", recno, ageyears ); }; fclose(infile); fclose(outfile1); fclose(outfile2); equipment("pause"); return 0; } int age (int date, int month, int 3 hundred and sixty 5 days) { int startdate = a million; int startmonth = eleven; int startyear = 2005; int ageinyears; ageinyears = startyear - 3 hundred and sixty 5 days; if (month > startmonth || (month == startmonth && date > startdate)) ageinyears--; return ageinyears; }

2016-12-28 07:46:03 · answer #3 · answered by bruss 3 · 0 0

fedest.com, questions and answers