I need Help Solving This Homework Problem Please someone help C201 Homework 6 Pr
ID: 3863276 • Letter: I
Question
I need Help Solving This Homework Problem Please someone help
C201 Homework 6
Problem 1. This exercise is based on homework 5. Two types of struct have been defined for you. They are order and customer. The relationship between them can be found by reading the code provided for you. If you have any questions, please ask the instructor.
The main program (order_application.cpp) and the header file (order.h) have been written for you. Your task is to complete one function in order.cpp.
void remove(order * & head, double limit)
o remove all the nodes from the linked list that have order cost greater than or equal to limit
The draft of the program is at
http://www.cs.iusb.edu/~yul/C201/source/hw6/order_application.cpp; http://www.cs.iusb.edu/~yul/C201/source/hw6/order.h; http://www.cs.iusb.edu/~yul/C201/source/hw6/order.cpp;
The executable is at
http://www.cs.iusb.edu/~yul/C201/source/hw6/hw6.ex
Submission: Print the source code of order.cpp and bring it to class
Problem 2. Write a program that manages student score. Your program should contain the definition of node of a linked list, a main function, a function to insert a node to the head of the linked list, a function to display student records, and a function to calculate the average score.
Details about this program is explained below
The node should contain data fields to represent the following student information: student ID (integer), first name, last name, and score (double and in the range of 0 to 100).
The main() function should create the head of the linked listed and ask the user to make the following selections:
Enter a record
Show records
Show average score
Terminate the program
If Option (a) is selected, the program should ask the user to enter the following information: ID, first name, last name, and score. The program should then create a node about the student and insert it to the head of the linked list through calling insert_to_head() function.
If Option (b) is selected, the program should call show_record() function to display all student records.
If Option (c) is selected, the program should call average() function and display the average score of all students.
If Option (d) is selected, the program should terminate.
You should code this program in a way so that it can continue to display the options for the user until the user choose Option (d)
The insert_to_head() function should insert the new node to the head of the linked list
The show_record() function should show all the nodes in the linked list.
The average() function should return the average score of the students in the list. If the list is empty, return 0.
The executable of the program is at http://www.cs.iusb.edu/C201/source/hw6/problem2.ex
Submission: Print the source code and bring it to cla
Problem 1:
Order_Application.cpp file
order.h file
order.cpp file
Explanation / Answer
Please refer below code
1) student.h
#include<iostream>
using namespace std;
//structure for student
typedef struct student
{
int ID;
string first_name;
string last_name;
double score;
student *next;
} student;
//head pointer initialised to NULL
student *head = NULL;
//function decleration
void insert_to_head(student *node);
void show_record(student *head);
double average(student *head);
2) student.cpp
#include "student.h"
//*****Function Definations***************//
void insert_to_head(student *node)
{
node->next = head;
head = node;
}
void show_record(student *head)
{
student *travel = head;
while(travel != NULL)
{
cout<<"ID : "<<travel->ID<<endl;
cout<<"First Name : "<<travel->first_name<<endl;
cout<<"Last Name : "<<travel->last_name<<endl;
cout<<"Score : "<<travel->score<<endl;
cout<<"-----------------------------------------------"<<endl;
travel = travel->next;
}
}
double average(student *head)
{
double avg = 0.0;
int Count = 0;
student *travel = head;
while(travel != NULL)
{
avg += (travel->score);
Count++;
travel = travel->next;
}
return (avg/Count);
}
int main()
{
char choice;
int ID;
string first_name,last_name;
double score;
//this loop always ask about the choice until (d) enters.Once (d) enters program quit
do
{
cout<<" -------------------------------------"<<endl;
cout<<"Choose from below option : "<<endl;
cout<<"(a) Enter Student Information "<<endl;
cout<<"(b) Show record "<<endl;
cout<<"(c) Calculate Average"<<endl;
cout<<"(d) Quit"<<endl;
cout<<" -------------------------------------"<<endl;
cin>>choice;
switch (choice)
{
case 'a':
student *node ;
node = new student;
cout<<"Enter ID : ";
cin>>ID;
cout<<" Enter First Name : ";
cin>>first_name;
cout<<" Enter Last Name : ";
cin>>last_name;
cout<<" Enter Score : ";
cin>>score;
node->ID = ID;
node->first_name = first_name;
node->last_name = last_name;
node->score = score;
node->next = NULL;
insert_to_head(node);
break;
case 'b':
show_record(head);
break;
case 'c':
double avg;
avg = average(head);
cout<<"Average : "<<avg<<endl;
default:
break;
}
}while(choice != 'd');
return 0;
}
Please refer below output
-------------------------------------
Choose from below option :
(a) Enter Student Information
(b) Show record
(c) Calculate Average
(d) Quit
-------------------------------------
a
Enter ID : 1234
Enter First Name : Hillary
Enter Last Name : Clinton
Enter Score : 45.6
-------------------------------------
Choose from below option :
(a) Enter Student Information
(b) Show record
(c) Calculate Average
(d) Quit
-------------------------------------
a
Enter ID : 2345
Enter First Name : Donald
Enter Last Name : Trump
Enter Score : 89.7
-------------------------------------
Choose from below option :
(a) Enter Student Information
(b) Show record
(c) Calculate Average
(d) Quit
-------------------------------------
b
ID : 2345
First Name : Donald
Last Name : Trump
Score : 89.7
-----------------------------------------------
ID : 1234
First Name : Hillary
Last Name : Clinton
Score : 45.6
-----------------------------------------------
-------------------------------------
Choose from below option :
(a) Enter Student Information
(b) Show record
(c) Calculate Average
(d) Quit
-------------------------------------
c
Average : 67.65
-------------------------------------
Choose from below option :
(a) Enter Student Information
(b) Show record
(c) Calculate Average
(d) Quit
-------------------------------------
d
Process returned 0 (0x0) execution time : 60.574 s
Press any key to continue.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.