1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

C Programming Challeging question..Please Help!! T.T

Discussion in 'C++' started by SamTheGreat, Oct 7, 2010.

  1. SamTheGreat

    SamTheGreat New Member

    Joined:
    Oct 7, 2010
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    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:
     
  2. kranta92

    kranta92 New Member

    Joined:
    Oct 5, 2010
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    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
     
  3. go4expert

    go4expert Moderator

    Joined:
    Aug 3, 2004
    Messages:
    306
    Likes Received:
    7
    Trophy Points:
    0
    Is this some challenge or your homework assignment?
     
  4. SamTheGreat

    SamTheGreat New Member

    Joined:
    Oct 7, 2010
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    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.
     
  5. techgeek.in

    techgeek.in New Member

    Joined:
    Dec 20, 2009
    Messages:
    572
    Likes Received:
    17
    Trophy Points:
    0
    Occupation:
    EOC (exploitation of computers)..i m a Terminator.
    Location:
    Not an alien!! for sure
    Home Page:
    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...
     
  6. go4expert

    go4expert Moderator

    Joined:
    Aug 3, 2004
    Messages:
    306
    Likes Received:
    7
    Trophy Points:
    0
    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 ####
     

Share This Page