Docstoc

Lab 5 (DOC)

Document Sample
Lab 5 (DOC) Powered By Docstoc
					                                          Lab Assignment 6

                                              CSCI 1480

                                       Due date October 7, 2010




Project Title: Student record processing with array of structures.

Project Description: You are required to read student record file into a structure array and
compute average grade of each student.

Inputs:

           a. StudentRecord.txt with the following initial data

Name       Lastname ID            Grade1       Grade2     Grade3     Test1      Test2      Ave

Chris      Rock        12         89           80         90         78         92

Simone     Bourne      43         78           67         79         80         82

Julie      Gate        178        69           80         72         90         67



Outputs: Display students’ records whose average grade is greater than user given value.

Objective: Learning structures and array of structures to organize related data (variables) in to a
nice and neat package

In this program you are required to implement the following structure and structure
operations.

   1. Use the following StudentRecord structure and do implementation for average() function
      with the given arguments and return type.
        struct StudentRecord{
              char *name;
              char *lastname;
              double grades[3];
              double tests[2];
              double ave;

               double average(float gradeWeight, float testWeight){

                       .
                       .
                  .
                  .
                  .

           return ave;
           }

   }st[10];

2. Read each student’s data from StudentRecord.txt file. Insert each student’s record in to a
   corresponding structure member of the structure array st. For example st[0] will have
   following member values after first row read from the file:

   st[0].name will be Chris

   st[0].lastname will be Rock

   st[0].ID will be 12 etc.



3. gradeWeight and testWeight arguments of the average() function will be given by the
   user. These float values are weights for grades (gradeWeight) and tests (testWeight).

   For instance, a student’s 3 grades are 80,60,70 and his/her 2 test scores are 100, 80.
   Assume grade weight is given 40% and test weight is given 60% by the user. So, overall
   average can be found in three steps:

       a. Grades contribution to overall average
              i. ((80+60+70)/3)*0.4 = 28
       b. Tests contribution to overall average
              i. ((100+80)/2)*0.6 = 54
       c. So, overall average score will be
              i. 28+54 = 82



4. Display all of the student records whose average less than a user given value.

Example Inputs & Outputs:

i. Enter grades weight: 0.5

   Enter test weight : 0.5

   Our students’ all records with calculated overall averages are:
Name        Lastname ID            Grade1     Grade2    Grade3     Test1      Test2      Ave

Chris       Rock        …          …          …         …          …          …          57

Simone      Bourne      …          …          …         …          …          …          89

Julie       Gate        …          …          …         …          …          …          78


         Note: gradeWeight+testWeight = 1.0

                gradeWeight+testWeight cannot be less than or greater than 1.0



         ii. Assume we calculated our students’ overall average scores as shown in the below
table.

Name        Lastname ID            Grade1     Grade2    Grade3     Test1      Test2      Ave

Chris       Rock        …          …          …         …          …          …          57

Simone      Bourne      …          …          …         …          …          …          89

Julie       Gate        …          …          …         …          …          …          78


Enter less than value:        80

Results:

Name        Lastname ID            Grade1     Grade2    Grade3     Test1      Test2      Ave

Chris       Rock        …          …          …         …          …          …          57

Julie       Gate        …          …          …         …          …          …          78




+30 points BONUS for the following questions

    5. Define a structure pointer which points our array of structure. Do all the above given
       operations on that structure pointer instead of st. For example:

         StudentRecord *p = st;//p is pointing st array’s first element now
   cout<<p->average(0.4,0.6)<<endl;
   p++; //p is now pointing st array’s second element
   cout<<p->average(0.4,0.6)<<endl;
   p++; //p is now pointing st array’s third element

   p->name="Julie"; //p change st array’s third element’s name to Julie

   cout<<st[2].name<<endl;//This line displays Julie on the screen

6. Save computed averages inside StudentRecord.txt files’ corresponding columns.



   Structure Definition and Usage

   Example 1:

   #include <iostream>


   using namespace std;
   int main(){
   //    char river1[]="I love UCA";
   //    char word1[]="UCA";
   //    cout << strstr(river1, word1)<<endl;
   //int iNum = atoi("BC1234A");
   //                      cout<<iNum<<endl;

          struct Student{

                 char * name;
                 int ID;
          };

          Student x[2];
          Student *p;

          x[0].name = "Your Name";

          x[1].name = "Your Last Name";

          p=x;
          cout<<x[0].name<<endl;
        cout<<x[1].name<<endl;


          cout<<p->name<<endl;

         cin.get();
   return 1;

   }
Example 2:
Example 3:

Array of Structures and Structure Pointer Example:

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:0
posted:10/26/2011
language:English
pages:6