Question

10 Exercise 2 We suppose that we have the following dataset on students (GPA: Grade Point Average): ID Name GPA Leila 3.5 7 A
0 0
Add a comment Improve this question Transcribed image text
Answer #1

CONCEPT:

IN THIS PROGRMA WE USE CLASS AND INSTANCE OF IT TO CREATE PROTOTYPE F BINARY SEARCH TREE

MOSTLY WE USED PREORDER FOR SHOWING AND CALCULATIONS..

WE ALSO USED WHILE LOOP MENU BASED SYSTEM TO CALCUATE THE ACCORDINGTO MENU..

ALL FUNCTIONS ARE MEMBER FUNCTIONS OF THE CLASS STUDENT.

CONSTRUCTOR ARE DEFUALT AS WELL AS PARAMETERISED.

//CODE SOLUTION

#include <iostream>
using namespace std;

class student
{
//here is the clas for the student binary search tree. left and right legs are
// there in the treee. id name GPA are attributes of student...

int ID;
string Name;
float GPA;
student *left;
student *right;
  
public:
  

//constructore here to declare the classs
//default
student()
{
ID=0;
Name="";
GPA=0.0;
left=NULL;
right=NULL;
  
}
  

//requierd constructore for initialize....
student(int ID1,string name1,float GPA1)
{
ID=ID1;
Name=name1;
GPA=GPA1;
left=NULL;
right=NULL;

}


//insertstudent here according to the root..in bst order of Id..

student* insertstudent(student *root,int ID1,string name1,float GPA1)
{
//case 1. when root is null we simply assign the newnnode to it...
if(root==NULL)
{
return new student(ID1,name1,GPA1);
  
}
  

//when lesser values go towards the left...
else if(ID1>root->ID)
{
root->right=insertstudent(root->right,ID1, name1, GPA1);
  
}
  
//in case greater values go towards the right...
else
{
root->left=insertstudent(root->left,ID1,name1,GPA1);
  
}
  

//return the root. in the end..
return root;
  
}

//function to show preordername in recursive fashion preorder here ...
//first root..
// then go to left
//then go to right..

void preordername(student *root)
{
if(root==NULL)
return;

cout<<root->Name<<" ";
  
preordername(root->left);
preordername(root->right);


}

//function to find and show the GPA greaterGPAs than specified by the user.
void greaterGPAs(student *root, float z)
{
if(root==NULL)
return;
if(root->GPA > z)
cout<<root->Name<<" ";
greaterGPAs(root->left,z);
greaterGPAs(root->right,z);
  
  
}

//preorderGpas.. shown here ..
void preorderGpas(student *root)
{
if(root==NULL)
return;

cout<<root->GPA<<" ";
//first root.. in subtree..
preorderGpas(root->left);
preorderGpas(root->right);
//then go left nad then go right repeat then//
//same in every subtree...



}

void IncreaseGpa(student *root)
{
if(root==NULL)
return;

root->GPA=(root->GPA)*1.1; //mutable GPA by 110/100....
IncreaseGpa(root->left);
IncreaseGpa(root->right);


}
//showing the modified GPA here ....
void shownewgpas(student *root)
{
if(root==NULL)
return;
cout<<root->GPA<<" ";

shownewgpas(root->left);
shownewgpas(root->right);
}

//numberofnodes of the student ...bst created..
void numberofnodes(student *root,int *count)
{
if(root==NULL)
return;
  
*count=*count+1;
//count each time in preorder mannner.

numberofnodes(root->left,count);
numberofnodes(root->right,count);
}

//find the sum and count of the numberofnodes ...return to the main...by refrence...
void averages(student *root,double *sum,int *count)
{
if(root==NULL)
return;
  
*count=*count+1;
*sum=*sum+(root->GPA);

averages(root->left,sum,count);
averages(root->right,sum,count);
  
}

};


int main() {
  
   student *root=NULL,s1;
root=s1.insertstudent(root,10,"Leila",3.5);
root=s1.insertstudent(root,7,"Adel",4.2);
root=s1.insertstudent(root,20,"Ahmed",3);
root=s1.insertstudent(root,13,"Abir",2.7);
root=s1.insertstudent(root,30,"Iman",3.1);
root=s1.insertstudent(root,21,"Amna",2.7);
root=s1.insertstudent(root,9,"Hedi",4.5);
while(1)
{
int x;
  
cout<<"enter the Menu: below: \n";
cout<<"1.Display the names of student traversing the tree in preorder\n";
cout<<"2.Display the names of student having greater gpa as specified by the the user\n";
cout<<"3.Display the GPAs of all students in preorder manner\n";
cout<<"4.Increase all GPAs by 10% \n";
cout<<"5.Display the new GPAs of students in preorder \n";
cout<<"6.Find and Display the number of nodes in the tree \n";
cout<<"7.Display the averages of all GPAs of students \n";
cout<<"8.Exit\n";
  
cin>>x;
  
if(x==8)
{
break;
}
  
else
if(x==1)
{
s1.preordername(root);
cout<<endl;
}
  
else
if(x==2)
{
cout<<"enter the specified GPA..\n ";
float y;
cin>>y;
s1.greaterGPAs(root,y);
cout<<endl;
}
  
else
if(x==3)
{
s1.preorderGpas(root);
cout<<endl;
}
  
else
if(x==4)
{
s1.IncreaseGpa(root);

}
else
if(x==5)
{
s1.shownewgpas(root);
cout<<endl;
}
else
if(x==6)
{
int count=0;
s1.numberofnodes(root,&count);
cout<<"number of nodes is: "<<count<<endl;
}
  
else if(x==7)
{ double avg,sum=0;
int count=0;
s1.averages(root,&sum,&count);
//cout<<count;
avg=sum/(double)count;
//cout<<sum<<" ";
cout<<"Average is: "<<avg;
cout<<endl;
}
  
}
  
   return 0;
}

INPUT:

1
2
4.1
3
4
5
6
7
8

OUTPUT:

enter the Menu: below:
1.Display the names of student traversing the tree in preorder
2.Display the names of student having greater gpa as specified by the the user
3.Display the GPAs of all students in preorder manner
4.Increase all GPAs by 10%
5.Display the new GPAs of students in preorder
6.Find and Display the number of nodes in the tree
7.Display the averages of all GPAs of students
8.Exit
Leila Adel Hedi Ahmed Abir Iman Amna
enter the Menu: below:
1.Display the names of student traversing the tree in preorder
2.Display the names of student having greater gpa as specified by the the user
3.Display the GPAs of all students in preorder manner
4.Increase all GPAs by 10%
5.Display the new GPAs of students in preorder
6.Find and Display the number of nodes in the tree
7.Display the averages of all GPAs of students
8.Exit
enter the specified GPA..
Adel Hedi
enter the Menu: below:
1.Display the names of student traversing the tree in preorder
2.Display the names of student having greater gpa as specified by the the user
3.Display the GPAs of all students in preorder manner
4.Increase all GPAs by 10%
5.Display the new GPAs of students in preorder
6.Find and Display the number of nodes in the tree
7.Display the averages of all GPAs of students
8.Exit
3.5 4.2 4.5 3 2.7 3.1 2.7
enter the Menu: below:
1.Display the names of student traversing the tree in preorder
2.Display the names of student having greater gpa as specified by the the user
3.Display the GPAs of all students in preorder manner
4.Increase all GPAs by 10%
5.Display the new GPAs of students in preorder
6.Find and Display the number of nodes in the tree
7.Display the averages of all GPAs of students
8.Exit
enter the Menu: below:
1.Display the names of student traversing the tree in preorder
2.Display the names of student having greater gpa as specified by the the user
3.Display the GPAs of all students in preorder manner
4.Increase all GPAs by 10%
5.Display the new GPAs of students in preorder
6.Find and Display the number of nodes in the tree
7.Display the averages of all GPAs of students
8.Exit
3.85 4.62 4.95 3.3 2.97 3.41 2.97
enter the Menu: below:
1.Display the names of student traversing the tree in preorder
2.Display the names of student having greater gpa as specified by the the user
3.Display the GPAs of all students in preorder manner
4.Increase all GPAs by 10%
5.Display the new GPAs of students in preorder
6.Find and Display the number of nodes in the tree
7.Display the averages of all GPAs of students
8.Exit
number of nodes is: 7
enter the Menu: below:
1.Display the names of student traversing the tree in preorder
2.Display the names of student having greater gpa as specified by the the user
3.Display the GPAs of all students in preorder manner
4.Increase all GPAs by 10%
5.Display the new GPAs of students in preorder
6.Find and Display the number of nodes in the tree
7.Display the averages of all GPAs of students
8.Exit
Average is: 3.72429
enter the Menu: below:
1.Display the names of student traversing the tree in preorder
2.Display the names of student having greater gpa as specified by the the user
3.Display the GPAs of all students in preorder manner
4.Increase all GPAs by 10%
5.Display the new GPAs of students in preorder
6.Find and Display the number of nodes in the tree
7.Display the averages of all GPAs of students
8.Exit

SCREENSHOT FOR BETTER UNDERSTANDING

NOTE:

IN CASE OF ANY QUERY PLZ ASK IN COMMENT

THANK YOU

Add a comment
Know the answer?
Add Answer to:
10 Exercise 2 We suppose that we have the following dataset on students (GPA: Grade Point...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a C++ program to store and update students' academic records in a binary search tree....

    Write a C++ program to store and update students' academic records in a binary search tree. Each record (node) in the binary search tree should contain the following information fields:               1) Student name - the key field (string);               2) Credits attempted (integer);               3) Credits earned (integer);               4) Grade point average - GPA (real).                             All student information is to be read from a text file. Each record in the file represents the grade information on...

  • 1. Create a PL/SQL program block that determines the top students with respect to GPA. Assume...

    1. Create a PL/SQL program block that determines the top students with respect to GPA. Assume that the database has four tables. Student(SSN, SName, DOB, Major) , Grade(SSN, CNo, Grade(0,1,2,3,4)) and Course table(CNo,CName, Credit Hour), Prerequisite(CNo, PreCNo); Student and couse data ae given in the following SQL statements a. Accept a number n as user input with SQL*Plus telling top n%. b. In a loop get the SName and GPA of the top n% people with respect to GPA. c....

  • c++ implement a student class Determine the final scores, letter grades, and rankings of all students...

    c++ implement a student class Determine the final scores, letter grades, and rankings of all students in a course. All records of the course will be stored in an input file, and a record of each student will include the first name, id, five quiz scores, two exam scores, and one final exam score. For this project, you will develop a program named cpp to determine the final scores, letter grades, and rankings of all students in a course. All...

  • In C++ Write a menu driven C++ program to read a file containing information for a list of Students, process the data, t...

    In C++ Write a menu driven C++ program to read a file containing information for a list of Students, process the data, then present a menu to the user, and at the end print a final report shown below. You may(should) use the structures you developed for the previous assignment to make it easier to complete this assignment, but it is not required. Required Menu Operations are: Read Students’ data from a file to update the list (refer to sample...

  • This is in C. For this assignment we will write a simple database server. We will...

    This is in C. For this assignment we will write a simple database server. We will be creating a simple database of student records, so let’s describe these first. The format of a student record is as follows: typedef struct student {     char lname[ 10 ], initial, fname[ 10 ];     unsigned long SID;     float GPA; } SREC; Part One – the Server We will create a database server. The job of the server is to accept a...

  • Using C programming For this project, you have been tasked to read a text file with student grade...

    Using C programming For this project, you have been tasked to read a text file with student grades and perform several operations with them. First, you must read the file, loading the student records. Each record (line) contains the student’s identification number and then four of the student’s numerical test grades. Your application should find the average of the four grades and insert them into the same array as the id number and four grades. I suggest using a 5th...

  • PYTHON 3 Object Oriented Programming ***a9q3.py file below*** class GradeItem(object): # A Grade Item is anything...

    PYTHON 3 Object Oriented Programming ***a9q3.py file below*** class GradeItem(object): # A Grade Item is anything a course uses in a grading scheme, # like a test or an assignment. It has a score, which is assessed by # an instructor, and a maximum value, set by the instructor, and a weight, # which defines how much the item counts towards a final grade. def __init__(self, weight, scored=None, out_of=None): """ Purpose: Initialize the GradeItem object. Preconditions: :param weight: the weight...

  • write a C++program to analyze a small subset of the data that has been collected. See...

    write a C++program to analyze a small subset of the data that has been collected. See file universities.txt .Use precisely seven parallel arrays: one for name of university, one for state, one for city, one for yearly tuition, one for enrollment, one for average freshman retention, and one for the percent of students who graduate with in six years. Note that the percentage of student accepted is not stored.An output file is opened in main() and remains open until the...

  • Please!!! need help asap!!!! write a C++program to analyze a small subset of the data that...

    Please!!! need help asap!!!! write a C++program to analyze a small subset of the data that has been collected. See file universities.txt .Use precisely seven parallel arrays: one for name of university, one for state, one for city, one for yearly tuition, one for enrollment, one for average freshman retention, and one for the percent of students who graduate with in six years. Note that the percentage of student accepted is not stored.An output file is opened in main() and...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT