Assignment 6-Lab Section 3 In this assignment, write a program using class data
ID: 3674512 • Letter: A
Question
Assignment 6-Lab Section 3 In this assignment, write a program using class data structure to create student records. Write a header file (h) to define class structure, a function file (cpp) to define all the functions of the class, and a main file (cpp) to use the class and its functions. The class functions should include set records0 to create new records, print_record0 to print the student records, find record0 to find a record by name. The class private data should include name, gender, math score, programming score, and a vector to contain all of those data as a single record for each student. Follow the sample output to write your program. Your program should have the same output as Enter new student records (name gender math score programming score): Mary F 96 98 97 97 Jack M 96 97 2 Jane F 97 Select the following options 1. Print all student records 2. Search student record by name 3. quit Printing student records 97 96 97 97 Jane Select the following options: 1. Print all student records 2. Search student record by name 3. quit Jane Enter student name for searching: math 97 Name Select the following sub-options: 1. Edit math score 2. Edit prog score1 Enter the new score: 100Explanation / Answer
The following code is written in c++ and devc++ IDE is been used.
HEADER FILE:
class student
{
private : char[20] name;
private : char gender;
private: int math_score;
private: int programming_score;
};
MAIN FILE:
include"record.h"
include<iostream>
include<stdio.h>
using namespace std;
int cnt=0;
Student stud[20];
int menu();
void set_records( student stud[],int cnt);
void print_records( Student stud[],int cnt);
void search_records( Student stud[], char[20] name,int cnt);
int main()
{
int choice;
char name[20];
char answer= 'n';
do
{
choice=menu();
switch(choice)
{
case 1:
{
system("cls");
if (cnt < 20)
{
set_records(stud, cnt);
cnt++;
}
else
printf(" NO MORE SPACE FOR NEW STUDENT RECORD");
break;
}
case 2:
system("cls");
print_records(stud, cnt);
break;
case 3:
system("cls");
printf("enter the name");
gets(name);
search_records(stud,name,cnt)
break;
case 4:
{
exit(0) ;
}
case 5:
{
cout << "Invalid Choice" ;
choice=menu() ;
}
} while(1);
printf(" Thank you.");
getch();
return 0;
}
FUNCTION FILE:
include"record.h"
include<iostream>
include<stdio.h>
int menu() //menu to be displayed to user
{
int x;
system("cls");
cout << " MENU" << " " ;
cout << " 1. set new student record " ;
cout << " 2. show all student recoirds" ;
cout<<" 3. search a record";
cout << " 4. Exit " ;
cin >> x ;
return x;
}
void set_records(Student stud[], int count) //for creating new record
{
printf("ADD STUDENT PERSONAL INFORMATION");
FLUSH;
printf(" name: ");
gets(stud[count].name);
//FLUSH;
printf("gender ");
scanf("%c",&stud[count].gender);
printf(" math score");
scanf("%d",&stud[count].math_score);
printf("programming score ");
scanf("%d",&stud[count].programming_score);
getch();
}
void print_records(Student stud[], int count) //for printing record
{
int i;
FLUSH;
printf("VIEW STUDENT RECORD");
if(count == 0)
printf(" NO RECORDS AVAILABLE");
else
{
for(i=0; i<count; i++)
{
printf(i);
printf(" %s", stud[i].Lname);
printf(" %c", stud[i].gender);
printf(" %d", stud[i].math_score);
printf(" %d", stud[i].programming_score);
//FLUSH;
printf(" ");
}
}
}
void search_records(Student stud[], string name,int count) //for searching record
{
if(count == 0)
printf(" NO RECORDS AVAILABLE");
else
{
for(i=0; i<count; i++)
{
if(strcmp(name,stud[i].name)==0)
{
printf("record found");
return;
}
}
printf("record not found");
}
}