Question

In: Computer Science

Assignment Description: Write a C++ program for keeping a course list for each student in a...

Assignment Description:

Write a C++ program for keeping a course list for each student in a college. Information about each student should be kept in an object that contains the student id (four digit integer), name (string), and a list of courses completed by the student.

The course taken by a student are stored as a linked list in which each node contain course name (string such as CS41, MATH10), course unit (1 to 4) and the course grade (A,B,C,D,F).

The program provides a MENU with choices that include adding a student record, deleting a student record, adding a single course record to a student’s record, deleting a single course record from a student’s record, and print a student’s record to a screen.

A student record should include a GPA (Grade Point Average) when display on the screen. The GPA is calculated by following formula:

When the user is through with the program, the program should store the records in a file. The next time the program is run, the records should be read back out of the file and the list should be reconstructed

You will need to implement a List container to hold a list of student records, each of which has a List container as its member. Note that no duplicate items should be permitted in either (student and course) List container.

Develop a test driver program that allow options to add, remove, and display student records and the course list of each student.

Use the class template technique (in C++) to implement a List ADT that could be used for both student list and the course list..

To calculate G.P.A. for one term:

Multiply the point value of the letter grade (A=4, B=3, C=2, D=1, F=0) by the number of credit hours. The result is the grade points (quality points) earned.

Total the credit hours for the student; total the quality points for the student.

Divide the total quality points by the total credit hours.

Solutions

Expert Solution


#include<stdio.h>
struct student
{
    int rollno;
    char name[30];
    float mark;
}stud;
//    FUNCTION TO INSERT RECORDS TO THE FILE
void insert()
{
    FILE *fp;
    fp=fopen("Record","a");
    printf("Enter the Roll no :");
    scanf("%d",&stud.rollno);
    printf("Enter the Name      :");
    scanf("%s"&stud.name);
    printf("Enter the mark      :");
    scanf("%f",&stud.mark);
    fwrite(&stud,sizeof(stud),1,fp);
    fclose(fp);
}
//    FUNCTION TO DISPLAY RECORDS
void disp()
{
    FILE *fp1;
    fp1=fopen("Record","r");
    printf("\nRoll Number\tname\tMark\n\n");
    while(fread(&stud,sizeof(stud),1,fp1));
    printf("%d\t\t%s\t%.2f\n",stud.rollno,stud.name,stud.mark);
    fclose(fp1);
}
//    FUNCTION TO SEARCH THE GIVEN RECORD
void search()
{
    FILE *fp2;
    int r,s,avl;
    printf("\nEnter the Roll no you want to search :");
    scanf("%d",&r);
    avl=avlrollno(r);
    if(avl==0)
    printf("Roll No %d is not avilable in the file\n");
    else
    {
        fp2=fopen("Record","r");
        while(fread(&stud,sizeof(stud),1,fp2))
        {
            s=stud.rollno;
            if(a==r)
            {
                printf("\nRoll no = %d",stud.rollno);
                printf("\nName    = %s"stud.name);
                printf("\nMark    = %.2f",stud.mark);
            }
        }
        fclose(fp2);
    }
}
//    FUNCTION TO DELETE A RECORD


void deletef()
{
    FILE *fp;
    FILE *fpt;
    int r,s;
    printf("Enter the Roll no you want to delete :");
    scanf("%d",&r);
    if(avlrollno(r)==0)
    printf("Roll no %d is not available in the file\n");
    else
    {
        fpo=fopen("Record","r");
        fpt=fopen("TempFile","w");
        while(fread(&stud,sizeof(stud),1,fpo))
        {
            a=stud.rollno;
            if(s!=r)
            fwrite(&stud,sizeof(stud),1,fpt);
        }
        fclose(fpo);
        fclose(fpt);
        fpo=fopen("Record","w");
        fpt=fopen("TempFile","r");
        while(fread(&)stud,sizeof(stud),1,fpt)
        fwrite(&stud,sizeof(stud),1,fpo);
        printf("\nRECORD DELETE\n");
    }
    fclose(fpo);
    fclose(fpt);
}
//    FUNCTION TO UPDATE THE RECORD
void update()
{
    int avl;
    FILE *fpt;
    FILE *fpo;
    int s,r,ch;
    printf("enter roll number to update");
    scanf("%d",&r);
    avl=avlrollno(r);
    if(avl==0)
     {
        printf("roll number %d is not Available in the file",r);
     }
    else
     {
        fpo=fopen("Record","r");
        fpt=fopen("TempFile","w");
        while(fread(&stud,sizeof(stud),1,fpo))
        {
            s=stud.rollno;
            if(s!=r)
            fwrite(&stud,sizeof(stud),1,fpt);
            else
             {
                printf("\n\t1_UPDATE THE NAME OF ROLL NUMBER %d",r);
                printf("\n\t1_UPDATE THE MARK OF ROLL NUMBER %d",r);
                printf("\n\t1_UPDATE BOTH NAME AND MARK OF ROLL NUMBER %d",r);
                PRINTF("\N\N eNTER YOUR CHOICE");
                scanf("%d",&ch);
                switch(ch)
                {
                    case 1:
                    printf("Enter Name : ");
                    scanf("%d",stud.name);
    `                break;
                    case 2:
                    printf("Enter Mark : ");
                    scanf("%d",&stud.mark);
                    break;
                    case 3:
                    printf("Enter Name and Mark: ");
                    scanf("%d",stud.name,&stud.mark );
                    break;
                    default:
                    printf("Invalid Selection");
                    break;
                }
                fwrite(&stud,sizeof(stud),1,fpt);
            }
        }   
        fclose(fpo);
        fclose(fpt);
        fpo=fopen("Record","w");
        fpt=fopen("TempFile","r");
        while(fread(&stud,sizeof(stud),1,fpt))
        {
            fwrite(&stud,sizeof(stud),1,fpo);
        }
        fclose(fpo);
        fclose(fpt);
        printf("RECORD UPDATED");
    }
}
/* FUNCTION TO SORT THE RECORD */
void sort()
    {
        int a[20],count=0,i,j,t,c;
        FILE *fpo;
        fpo=fopen("Record","r");
        while(fread(&stud,sizeof(stud),1,fpo))
        {
            a[count]=stud.rollno;
            count++;
        }
        c=count;
        for(i=0;i<count-1;i++)
        {
            for(j=i+1;j<count;j++)
            {
                if(a[i]>a[j])
                {
                    t=a[i];
                    a[i]=a[j];
                    a[j]=t;
                }
            }
        }
        printf("Roll no.\tName\t\tMar\n\n");
        count=c;
        for(i=0;i<count;i++)
        {
            rewind(fpo);
            while(fread(&stud,sizeof(stud),1,fpo))
            {
                if(a[i]==stud.rollno)
                printf("\n %d\t\t %s \t\t %2f",stud.name,stud.mark);
            }
//    FUNCTION TO CHECK GIVEN ROLL NO IS AVAILABLE //
int avLrollno(int rno)
{
    FILE *fp;
    int c=0;
    fp=fopen("Record","r");
    while(!feof(fp))
    {
        fread(& NAME   :shahul rollno:46 stud,sizeof(stud),1,fp);
        if(rno==stud.rollno)
        {
            fclose(fp);
            return 1;
        }
    }
    fclose(fp);
        return 0;
}
//FUNCTION TO CHECK THE FILE IS EMPTY OR NOT
int empty()
{
int c=0;
FILE *fp;
fp=fopen("Record","r");
while(fread(&stud,sizeof(stud),1,fp))
c=1;
fclose(fp);
return c;
}
// MAIN PROGRAM
{
int c,emp,empty();
do
{
printf("\n\t---Select your choice---------\n");
printf("\n\t1. INSERT\n\t2.DISPLAY\n\t3. SEARCH");
printf("\n\t4. DELETE\n\t5.UPDATE\n\t6.SORT");
printf("\n\t7. EXIT");
printf("\n\n------------------------------------------\n");
printf("\nEnter your choice:"0;
    scanf("%d",&c);
    printf("\n");
    switch(c)
    {
        case 1:
            insert();
            break;
        case 2
            emp=empty();
            if(emp==0)
            printf("\nThe file is EMPTY\n");
            else
            disp();
            break;
        case 3:
            search();
            break;
        case 4:
            delete();
            break;
        case 5:
            update();
            break;
        case 6:
            emp=empty();
            ifemp==0()
            printf("\n The file is EMPTY\n");
            else
            sort();
            break;
        case 7:
            exit(0);
        default:
            printf("\nYour choice is wrong\nPlease try again...\n");
            break;

        }
    }while(c!=7);
}


Related Solutions

Please code in C# - (C - Sharp) Assignment Description Write out a program that will...
Please code in C# - (C - Sharp) Assignment Description Write out a program that will ask the user for their name; the length and width of a rectangle; and the length of a square. The program will then output the input name; the area and perimeter of a rectangle with the dimensions they input; and the area and perimeter of a square with the length they input. Tasks The program needs to contain the following A comment header containing...
For this assignment, write a program that will calculate the quiz average for a student in...
For this assignment, write a program that will calculate the quiz average for a student in the CSCI 240 course. The student's quiz information will be needed for later processing, so it will be stored in an array. For the assignment, declare one array that will hold a maximum of 12 integer elements (ie. the quiz scores). It is recommended that this program be written in two versions. The first version of the program will read a set of quiz...
For this assignment, write a program that will calculate the quiz average for a student in...
For this assignment, write a program that will calculate the quiz average for a student in the CSCI 240 course. The student's quiz information will be needed for later processing, so it will be stored in an array. For the assignment, declare one array that will hold a maximum of 12 integer elements (ie. the quiz scores). It is recommended that this program be written in two versions. The first version of the program will read a set of quiz...
Overview For this assignment, write a program that will calculate the quiz average for a student...
Overview For this assignment, write a program that will calculate the quiz average for a student in the CSCI 240 course. The student's quiz information will be needed for later processing, so it will be stored in an array. For the assignment, declare one array that will hold a maximum of 12 integer elements (ie. the quiz scores). It is recommended that this program be written in two versions. The first version of the program will read a set of...
Overview For this assignment, write a program that will calculate the quiz average for a student...
Overview For this assignment, write a program that will calculate the quiz average for a student in the CSCI course. The student's quiz information will be needed for later processing, so it will be stored in an array. For the assignment, declare one array that will hold a maximum of 12 integer elements (ie. the quiz scores). It is recommended that this program be written in two versions. The first version of the program will read a set of quiz...
Overview For this assignment, write a program that will calculate the quiz average for a student...
Overview For this assignment, write a program that will calculate the quiz average for a student in the CSCI 240 course. The student's quiz information will be needed for later processing, so it will be stored in an array. For the assignment, declare one array that will hold a maximum of 12 integer elements (ie. the quiz scores). It is recommended that this program be written in two versions. The first version of the program will read a set of...
Overview For this assignment, write a program that will calculate the quiz average for a student...
Overview For this assignment, write a program that will calculate the quiz average for a student in the CSCI 240 course. The student's quiz information will be needed for later processing, so it will be stored in an array. For the assignment, declare one array that will hold a maximum of 12 integer elements (ie. the quiz scores). It is recommended that this program be written in two versions. The first version of the program will read a set of...
OverviewFor this assignment, write a program that will calculate the quiz average for a student in...
OverviewFor this assignment, write a program that will calculate the quiz average for a student in the CSCI 240 course. The student's quiz information will be needed for later processing, so it will be stored in an array.For the assignment, declare one array that will hold a maximum of 12 integer elements (ie. the quiz scores).It is recommended that this program be written in two versions. The first version of the program will read a set of quiz scores from...
Description of the Assignment: Write a Python program to (a) create a new empty stack. Then,...
Description of the Assignment: Write a Python program to (a) create a new empty stack. Then, (b) add items onto the stack. (c) Print the stack contents. (d) Remove an item off the stack, and (e) print the removed item. At the end, (f) print the new stack contents: Please use the following comments in your python script: # ************************************************* # COP3375 # Student's full name ( <<< your name goes here) # Week 8: Assignment 1 # ************************************************* #...
*****For C++ Program***** Overview For this assignment, write a program that uses functions to simulate a...
*****For C++ Program***** Overview For this assignment, write a program that uses functions to simulate a game of Craps. Craps is a game of chance where a player (the shooter) will roll 2 six-sided dice. The sum of the dice will determine whether the player (and anyone that has placed a bet) wins immediately, loses immediately, or if the game continues. If the sum of the first roll of the dice (known as the come-out roll) is equal to 7...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT