Write C++ program to create a student record include a student ID, first name, nickname, course, subject, and subject marks.
Task:
Create a function to insert a number of students in the record.
Create a function to print all student information by a table.
Create a function to print all student information that they're in a specific course chosen by user input.
Create a function to search for a student by student ID and print student information.
Create a function to search for a student by student ID and edit student marks bu user input.
Create a function to find the Average marks in the specific course chosen by user input.
Create a function to increase student marks 10% for students whose marks is less than marks chosen by user input.
CODE:
OUTPUT:
RAW CODE:
#include<iostream>
using namespace std;
struct student{
string ID;
string first_name;
string nick_name;
string course;
float marks;
student *next;
}*head = NULL;
void insert(string id,string f_name,string n_name,string course,float marks){
struct student *temp = new(struct student);
temp->ID = id;
temp->first_name = f_name;
temp->nick_name = n_name;
temp->course = course;
temp->marks = marks;
temp->next = NULL;
if(head==NULL){
temp->next = head;
head = temp;
}
else{
struct student *trav = head;
while(trav->next!=NULL){
trav = trav->next;
}
trav->next = temp;
}
}
void print_students(){
cout << endl;
struct student *trav = head;
cout << "Students in the Recordes:\n";
if(head==NULL){
cout << "There is no student in the record\n";
}
else{
struct student *trav = head;
cout << "ID\tFirst Name\tNick Name\tcourse\tmarks\n";
while(trav!=NULL){
cout << trav->ID << "\t" << trav->first_name << "\t\t" << trav->nick_name << "\t\t" << trav->course << "\t" << trav->marks << endl;
trav = trav->next;
}
}
}
void course_chosen(string course){
cout << endl;
struct student *trav = head;
cout << "Student information that they're in a specific course:\n";
cout << "ID\tFirst Name\tNick Name\tcourse\tmarks\n";
while(trav!=NULL){
if (trav->course == course){
cout << trav->ID << "\t" << trav->first_name << "\t\t" << trav->nick_name << "\t\t" << trav->course << "\t" << trav->marks << endl;
}
trav = trav->next;
}
}
void search(string id){
cout << endl;
struct student *trav = head;
cout << "Student information with given student id:\n";
cout << "ID\tFirst Name\tNick Name\tcourse\tmarks\n";
while(trav!=NULL){
if (trav->ID == id){
cout << trav->ID << "\t" << trav->first_name << "\t\t" << trav->nick_name << "\t\t" << trav->course << "\t" << trav->marks << endl;
break;
}
trav = trav->next;
}
}
void edit_marks(string id,float marks){
cout << endl;
struct student *trav = head;
while(trav!=NULL){
if (trav->ID == id){
trav->marks = marks;
break;
}
trav = trav->next;
}
}
void average_course(string course){
cout << endl;
struct student *trav = head;
float sum = 0;
int count = 0;
while(trav!=NULL){
if (trav->course == course){
sum += trav->marks;
count += 1;
}
trav = trav->next;
}
float average= sum/count;
cout << "Average of " << course << " course is " << average << "\n";
}
void increase_marks(float marks){
struct student *trav = head;
while(trav!=NULL){
if (trav->marks < marks){
trav->marks += trav->marks * ((float)10/100);
}
trav = trav->next;
}
}
int main()
{
int n;
string id,f_name,n_name,course;
float marks;
cout << "Enter number of students: ";
cin >> n;
cout << "\n";
for (int i = 0; i < n; ++i)
{
cout << "Enter ID:";cin >> id;
cout << "Enter First name: ";cin >> f_name;
cout << "Enter nick name: ";cin >> n_name;
cout << "course: ";cin >> course;
cout << "marks: ";cin >> marks;
cout << "\n";
insert(id,f_name,n_name,course,marks);
}
print_students();
cout << "\n";
cout << "Chose course to print all students: " ;
cin >> course;
course_chosen(course);
cout << "\n";
cout << "Chose ID to print student information: " ;
cin >> id;
search(id);
cout << "\n";
cout << "Chose ID to change marks: " ;
cin >> id;
cout << "Enter marks: ";
cin >> marks;
edit_marks(id,marks);
cout << "\n";
cout << "Chose course to average marks: " ;
cin >> course;
average_course(course);
cout << "\n";
cout << "Chose marks to increase 10% : " ;
cin >> marks;
increase_marks(marks);
cout << "\n";
print_students();
return 0;
}
NOTE:
If You have any doubts feel free to comment in comment
section.
DO VOTE(LIKE).
Get Answers For Free
Most questions answered within 1 hours.