this is my program of fee management i want to show the highest fee data first how is this possible:
#include <iostream>
#include <string>
#include <list>// library for List used in student storing
using namespace std;
class StudentList;
class Student{
private:
//every student properties
string name;
string rollno;
string classroom;
double fee;
public:
//function names from every menu
void selectionSheet();
void manageData();
void search();
void Reports();
//this funtion returns a new student object
Student addData(){
system("cls");
cout<<"\n\n\t\tEnter the Name of student"<<endl;
string name;
cin>>name;
system("cls");
cout<<"\n\n\t\tEnter the RollNo of student"<<endl;
string rollno;
cin>>rollno;
system("cls");
cout<<"\n\n\t\tEnter the classroom of student"<<endl;
string classroom;
cin>>classroom;
system("cls");
cout<<"\n\n\t\tEnter the fee of student"<<endl;
double fee;
cin>>fee;
return Student(name,rollno,classroom,fee);
};
//constructor
Student(string n,string roll,string cl,double f){
name=n;
rollno=roll;
classroom=cl;
fee=f;
}
//no arguiment constructor
Student(){
}
//Disctructor
~Student(){
}
//setters and getters
string getName(){return name;}
string getRollNo(){return rollno;}
string getClassRoom(){return classroom;}
double getFee(){return fee;}
void setName(string n){name=n;}
void setRollNo(string r){rollno=r;}
void setClassRoom(string c){classroom=c;}
void setFee(double f){fee=f;}
};
void Student::selectionSheet(){
cout<<"\n\n\t\t1- Manage Data\t"<<"\n\t\t2- Search \n"<<"\t\t3- Reports\t"<<"\n\t\t4- Exit\n"
<<"-----------------------------------\n";
}
void Student::manageData(){
cout<<"\t\t1- Add Data\t"<<"\n\t\t2- Update Data\n"<<"\t\t3- Display Data\t"<<"\n\t\t4- Delete Data\t"<<"\n\t\t 5- Exit\n"
<<"-----------------------------------\n";
}
void Student::search(){
cout<<"\n\n\t\tSearch Student via\n"<<"------------------\n"<<"\n\t\t1- Name\t\t"<<"\n\t\t2- RollNo\n"<<"\t\t3- Class\t"<<"\n\t\t4- exit\n"
<<"----------------------------------------\n";
}
void Student::Reports(){
cout<<"\n\n\t\t1- Top positions\t"<<"\n\t\t2- Result Report\t"<<"\n\t\t3- Exit\n"
<<"------------------------------------------------\n";
}
//inheriting the student class with StudentList Class
class StudentList : public Student{
private:
list<Student> studentlist={};//list to store students
list<Student> topStudentList={};
list<Student>::iterator it;//iterator used to go through list
public:
Student s;
void addStudent()
{
studentlist.push_back(s.addData());//push_back adds a new student in student list
}
void getStudentList()//this function prints all of the students in the list
{
int i=0;
for(Student S:studentlist){//for each loop to get each student one by one
cout<<"\n-----"<<i<<"-----\nName: "<<S.getName()<<"\nRollNo: "
<<S.getRollNo()<<"\nClassRoom: "<<S.getClassRoom()<<"\nFee: "<<S.getFee()
<<endl;
cout<<"------------------------\n";
cout<<"\n\n";
i++;
}
}
void getStudentListReport()//report list for all of the students
{
system("cls");
int i=0;
cout<<" Name:\t"<<"Rollno:\t"<<"ClassRoom:\t"<<"Fee:\t\t"
<<"\n----------------------------------------------\n";
for(Student S:studentlist){//for each loop used to get each student one by one
cout<<i<<":"<<S.getName()<<"\t"
<<S.getRollNo()<<" \t"
<<S.getClassRoom()<<"\t\t"
<<S.getFee()<<endl;
cout<<"------------------------\n";
i++;
}
}
void updateData()//function for updating an existing student information
{
int x;
if(studentlist.size()>=1){//if checking if there is atleast 1 student in list
system("cls");
cout<<"Which student would you like to update?\n";
getStudentList();//shows the list of all the students to choose from
cin>>x;
it=studentlist.begin();//iterator it....begin sets the 'it' to the first object in list
advance(it,x);//'it' is moved to x(entered by user) position
studentlist.insert(it,s.addData());//inserts a new updated student at 'it'position
x++;
}
else
cout<<"no Students added\n";
it=studentlist.begin();
advance(it,x);
studentlist.erase(it);//deletes the previous not updated student
}
void deleteData()//funtion used to delete a student
{
int x;
if(studentlist.size()>=1){
cout<<"Which student would you like to remove?\n";
getStudentList();//displays student list
again:
cin>>x;
if(x>=0 && x<studentlist.size()){
it=studentlist.begin();//moves 'it' to start
advance(it,x);//moves 'it' to user selected postion
studentlist.erase(it);//deletes the student
}
else //if student selects a invalid option it goes back to selection again:
{cout<<"Select a valid option\n";
goto again;}
}
else
cout<<"No students added\n";
}
void searchByName()//search a student by name;
{
bool f=true;
string name;
system("cls");
cout<<"Enter name of student\n";
cin>>name;//user enters a name
for(Student S:studentlist){//loop to go through each student
if(S.getName().compare(name)==0){//checks if the name entered and student is same and displays
f=false;
cout<<"'\nName: "<<S.getName()<<"\nRollNo: "<<S.getRollNo()<<"\nClassRoom: \n"
<<S.getClassRoom()<<"\nFee: "<<S.getFee()<<endl;
cout<<"------------------------\n";
}
}
if(f==true) //f is set to true if sudent is is found it becomes false if not this statement is printed
{
cout<<"No student with name "<<name<<" found:\n\n";
}
}
void searchByRollNo(){//search by roll no
bool f=true;
string RollNo;
system("cls");
cout<<"Enter RollNo of student\n";
cin>>RollNo;
for(Student t:studentlist){
if(RollNo==t.getRollNo()){//check if entered rollnumber matches a student and displays it
f=false;
cout<<"\nName: "<<t.getName()<<"\nRollNo: "<<t.getRollNo()<<"\nClassRoom: \n"
<<t.getClassRoom()<<"\nFee: "<<t.getFee()<<endl;
cout<<"------------------------\n";
}
}
if(f==true){//same as before
cout<<"No student with name "<<RollNo<<" found:\n\n";
}
}
void searchByClassRoom(){//search by classroom
bool f=true;
string cls;
cout<<"Enter Classroom of student\n";
cin>>cls;
for(Student t:studentlist){
if(cls==t.getClassRoom()){//checks if entered classroom is same as student and displays
f=false;
cout<<"\nName: "<<t.getName()<<"\nRollNo: "<<t.getRollNo()<<"\nClassRoom: \n"
<<t.getClassRoom()<<"\n Fee: "<<t.getFee()<<endl;
cout<<"------------------------\n";
}
}
if(f==true){//same as before
cout<<"No student in Classroom "<<cls<<" found:\n\n";
}
}
};
int main(){
StudentList s,st;//an object of studentlist class
// Student st;//an object of student class
int selection;
while(true){ //used for always being in a menu
back:
system("cls");
cout << "\n\n\n\n\t\t\t\t\tWelcome To The Fee Managtment system\t\t\t\t\n\n\n\n";
cout<<"\n\nSelect an option\n------------------"<<endl;
st.selectionSheet();
cin>>selection;
switch(selection){//used for different cases
case 1:
while(true){//this loop used to being in case1 menu untill exit by user
here:
int selection;
st.manageData();//shows the managedata menu
cin>>selection;
switch(selection){//managedata menu list
case 1:
s.addStudent();//for addin student
break;
case 2:
s.updateData();//for updating student
break;
case 3:
s.getStudentList();//for getting studentlist
break;
case 4:
s.deleteData();//deleting student
break;
case 5:
goto back;//exits this menu and goes to back in main menu
break;
default:
cout<<"Select a proper option\n";//this is run if different case is selected
}
}
case 2:
while(true){//same as above
int selection;
st.search();//shows search menu
cin>>selection;
switch(selection){
case 1:
s.searchByName();//calls by name function
break;
case 2:
s.searchByRollNo();//calls by rollno function
break;
case 3:
s.searchByClassRoom();//calls by classroom function
break;
case 4:
goto back;//exits this menu back to main menu
break;
}
}
case 3:
while(true){//same as above
int selection;
st.Reports();//shows reports menu
cin>>selection;
switch(selection){
case 1:
s.getStudentListReport();//shows the report of students
break;
case 2:
s.getStudentListReport();
break;
case 3:
goto back;//exits this menu
break;
default:
cout<<"Select a valid option\n";
}
}
case 4://case4 of main menu
goto out;//exits the main menu and ends the program
break;
default:
cout<<"Select a valid option\n";
goto out;//exits the main menu and ends the program
}
if(selection==-1){
out:
cout<<"The program ended:";
break;
}
}
return 0;
}
displaying method start from line 34 in this code. I only want to show the data of student who have highest fees stored in list or all the student data but in that order where higest fee student comes first
Aucun commentaire:
Enregistrer un commentaire