?? gradelist.cpp
字號(hào):
#include"gradelist.h"
#include<iostream>
#include<iomanip>
#include<cstddef> //For NULL
using namespace std;
//*******************************
GradeList::GradeList()
{
head=NULL;
}
//************************************************
bool GradeList::IsEmpty()const
{
return (head==NULL);
}
//********************************************8
GradeList::~GradeList()
{
componentType temp;
while(!IsEmpty())
RemoveFirst(temp);
}
//**********************************************
void GradeList::RemoveFirst(/* out */ componentType& item)
{
GradePtr temPtr=head;
item=head->component;
head=head->link;
delete temPtr;
}
//*********************************************
void GradeList::Insert(componentType item)
{
GradePtr currPtr, prevPtr;
GradePtr newGradePtr;
newGradePtr=new GradeType;
newGradePtr->component=item;
prevPtr=NULL;
currPtr=head;
while(currPtr!=NULL && item.Average<(currPtr->component).Average)
{
prevPtr=currPtr;
currPtr=currPtr->link;
}
newGradePtr->link=currPtr;
if(prevPtr==NULL)
head=newGradePtr;
else
prevPtr->link=newGradePtr;
}
//***********************************************************************
void GradeList::Print()const
{
GradePtr currPtr=head;
cout<<setw(12)<<"Id"<<setw(12)<<"Math"<<setw(12)<<"English"
<<setw(12)<<"Chinese"<<setw(12)<<"Total"<<setw(12)<<"Average"<<endl<<endl;
cout<<fixed<<setprecision(2);
while(currPtr->link !=NULL)
{
cout<<setw(12)<<(currPtr->component).Id
<<setw(12)<<(currPtr->component).Math
<<setw(12)<<(currPtr->component).English
<<setw(12)<<(currPtr->component).Chinese
<<setw(12)<<(currPtr->component).Total
<<setw(12)<<(currPtr->component).Average<<endl;
currPtr=currPtr->link;
cout<<endl;
}
}
//*************************************************************8
void GradeList::Research()
{
int i;
int a=0,b=0,c=0,d=0,e=0;
GradePtr currPtr=head;
while(currPtr!=NULL)
{
if((currPtr->component).Average>=90)
a++;
else
if((currPtr->component).Average>=80)
b++;
else
if((currPtr->component).Average>=70)
c++;
else
if((currPtr->component).Average>=60)
d++;
else
e++;
currPtr=currPtr->link;
}
cout<<"各個(gè)學(xué)生的平均成績分配情況如圖 : "<<endl<<endl;
cout<<setw(10)<<"90~100 : ";
for(i=0;i<a;i++)
cout<<"* ";
cout<<endl;
cout<<setw(10)<<"80~90 : ";
for(i=0;i<b;i++)
cout<<"* ";
cout<<endl;
cout<<setw(10)<<"70~80 : ";
for(i=0;i<c;i++)
cout<<"* ";
cout<<endl;
cout<<setw(10)<<"60~70 : ";
for(i=0;i<d;i++)
cout<<"* ";
cout<<endl;
cout<<setw(10)<<"0~60 : ";
for(i=0;i<e;i++)
cout<<"* ";
cout<<endl;
}
//*****************************************************
void GradeList::Search()
{
char cha;
int ID;
GradePtr currPtr=head;
float TotalAverage=0;
int i=0;
while(currPtr->link !=NULL)
{
TotalAverage=TotalAverage+(currPtr->component).Average;
currPtr=currPtr->link;
i++;
}
TotalAverage=TotalAverage/i;
cout<<fixed<<setprecision(2);
cout<<"The TotalAverage is : "<<TotalAverage<<endl;
cout<<"Do you want to search sb's grade? If you want put in 'y' ."<<endl<<endl;
cin>>cha;
while(cha=='y')
{
cout<<"Cin a ID number which is between 1001--1015 : "<<endl;
cin>>ID;
cout<<endl;
if( ID>=1001 && ID<=1015 )
{
currPtr=head;
cout<<setw(12)<<"Id"<<setw(12)<<"Math"
<<setw(12)<<"English"
<<setw(12)<<"Chinese"<<setw(12)
<<"Total"<<setw(12)<<"Average"<<endl<<endl;
while(currPtr->link !=NULL)
{
if((currPtr->component).Id==ID)
cout<<setw(12)<<(currPtr->component).Id
<<setw(12)<<(currPtr->component).Math
<<setw(12)<<(currPtr->component).English
<<setw(12)<<(currPtr->component).Chinese
<<setw(12)<<(currPtr->component).Total
<<setw(12)<<(currPtr->component).Average<<endl;
currPtr=currPtr->link;
}
}
cout<<"Do you want to search another student's grade? If you want put in 'y' ."<<endl<<endl;
cin>>cha;
cout<<endl;
}
}
//***********************************************************
/* void GradeList::Delete( /* in *//* componentType item )
{
GradePtr delPtr; // Pointer to grade to be deleted
GradePtr currPtr; // Loop control pointer
GradePtr prePtr;
// Check if item is in first node
if (item.Id == (head->component).Id)
{
// Delete first node
delPtr = head;
head = head->link;
}
else
{
// Search for node in rest of list
prePtr=head;
currPtr = head->link;
while ((currPtr->component).Id != item.Id)
{
prePtr=currPtr;
currPtr = currPtr->link;
}
// Delete *(currPtr)
delPtr = currPtr;
prePtr->link = currPtr->link;
}
delete delPtr;
}
//********************************************************
GradeList::GradeList( const GradeList& otherList )
{
GradePtr fromPtr; // Pointer into list being copied from
GradePtr toPtr; // Pointer into new list being built
if (otherList.head == NULL)
{
head = NULL;
return;
}
// Copy first node
fromPtr = otherList.head;
head = new GradeType;
head->component = fromPtr->component;
// Copy remaining nodes
toPtr = head;
fromPtr = fromPtr->link;
while (fromPtr != NULL)
{
toPtr->link = new GradeType;
toPtr = toPtr->link;
toPtr->component = fromPtr->component;
fromPtr = fromPtr->link;
}
toPtr->link = NULL;
}
//************************************************8888
void GradeList::InsertAsFirst( /* in */ /*componentType item )
{
GradePtr newGradePtr = new GradeType;
newGradePtr->component = item;
newGradePtr->link = head;
head = newGradePtr;
}
//********************************************* */
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -