Hi experts, This is my college project..i have tried it a lot of times but compilation keeps failing and i have run out of idea...please somebody if u see this..please give a helping hand...i appreciate very very much if someone could help...the question is as follows: • Define a structure with the following data members: • studid (use char array of 10 elements to store the Student ID) • lectatt (use int array of 14 elements to store 14 weeks of lecture attendance). • Use the preprocessor directive to define constants for elements in both arrays. • In main() function : • Declare an array of structure variable mystudents with 7 elements. Use the preprocessor directive to define the constant for this array also. • Declare a pointer to a file called input_file. • Declare and initialize the following arrays of variable. o hours_attended (total hours attended for each students) o att_percentage (the percentage of attendance based on the assumption that students need to attend 2 hours of lecture every week) • Use the fopen() function call to open a file named attendance.dat for read only and assign the return value the pointer of the input_file. • Check whether the attendance.dat can be open or not. • If the file can be opened, use a nested for loop the insert data in the array of structure mystudents. o Use the outer for loop to read the Student ID and insert the data into the structure array. o Use the inner for loop to read the attendance where each number represent the number of hours attended. • Close the input file. • Create another nested for loop just like the first nested loop to get the total hours attended and get the percentage (assuming that students need to attend 2 hours every week for 14 weeks). • Use the last for loop to display the Student ID and the attendance percentage for each student. Thanking you in advanced, and best regards, C programming Student:pinch:
i think it's something like this... #include <stdio.h> #include <iostream.h> typedef struct //Define a structure with the following data members: { char studid[10]; //studid (use char array of 10 elements to store the Student ID) int lectatt[14]; //lectatt (use int array of 14 elements to store 14 weeks of lecture attendance) } mystruct; int main () //In main() function : { mystruct mystudents[7]; //Declare an array of structure variable mystudents with 7 elements. FILE *input_file; //Declare a pointer to a file called input_file //Declare and initialize the following arrays of variable: unsigned hours_attended[7]={0,0,0,0,0,0,0}; //hours_attended (total hours attended for each students) double att_percentage[7]={0,0,0,0,0,0,0}; //att_percentage input_file=fopen("attendance.dat","rb"); //Use the fopen() function call to... if (input_file==NULL) return 1; unsigned i; for (i=0;i<7;i++) //Use the outer for loop to read the Student ID ... fread (&mystudents.studid,sizeof(mystudents.studid),1,input_file); for (i=0;i<7;i++) //Use the inner for loop to read the attendance where... fread (&hours_attended,sizeof(hours_attended),1,input_file); fclose (input_file); //Close the input file. //Create another nested for loop just like the first nested loop to get ... //use your head... for (i=0;i<7;i++) cout << "Student " << i+1 << '\t' << mystudents.studid << '\t' << att_percentage << endl; return 0; } not sure what are "inner" and "outer" loops though and "Use the preprocessor directive to define constants for elements" ... no idea :P
hi, thanks alot kranta 92 for your big help in my programming question..It helps big time >.< Thanks once again..Thousands thanks! Coderzone: yeah this is my college project..im sorry but i've tried it many times using my own way. Thanks to kranta, i've get it done. anyway thanks to u too. take care.
What u have to do with this...? one person has already tried so if u know then try it out if u dnt know then dnt waste ur time...
I am not sure why you are saying such rude words and I guess I am fine wasting my time and if you think you are wasting your time here just ####