#include<iostream>
#include<string>
using namespace std;
class Student
{
public:
Student();
Student(char*,char*,double);
void SeInfo(char*,char*,double);//设置属性值
void ShowInfo();//输出
private:
char no[10];
char name[20];
double score;
};
Student::Student()
{
strcpy(no,"NULL");
strcpy(name,"NULL");
score=0;
}
Student::Student(char * no,char * name,double score)
{
strcpy(this->no,no);//this 拷贝
strcpy(this->name,name);
this->score=score;
}
void Student::SeInfo(char *no,char *name,double *score)
{
strcpy(this->no,no);
strcpy(this->name,name);
this->score=score;
}
void ShowInfo()
{
cout<<"no"<<" "<<"name"<<" "<<"score"<<endl;
}
Student stu[1000]={Student("1001","jack",88),
Student("1002","tony",79),
Student("1003","lucy",92),
Student("1004","mary",78),
Student("1005","sary",95),
Student("1006","jane",86),
};
int count=6;//对象数组中元素个数
//函数声明
void ShowAll();//展示所有信息
void InsertScore();
void DeleteScore();
int main()
{
ShowAll();
int choice;//获取用户输入
while(true)//无限循环
{
cout<<"请选择编号 1:插入成绩 2: 删除成绩 3:浏览成绩 0:退出"<<endl;
cin>>choice;
switch(choice)
{
case 1:
InsertScore();
break;
case 2:
DeleteScore();
break;
case 3:
ShowAll();
break;
default:
cout<<"退出系统!"<<endl;
exit(0);
break;
}
}
return 0;
}
void ShowAll()//显示所有成绩
{
cout<<"流水号"<<"********"<<"学号"<<"**********"<<"姓名"<<"*******"<<"成绩"<<endl;
for(int i=0;i<count;i++)
{
cout<<i+1<<" ";
stu[i].ShowInfo();
}
}
void InsertScore()//插入成绩
{
int index;
cout<<"请输入插入位置:";
cin>>index;
char no [10];
char name[20];
double score;
cout<<"请输入学号:";
cin>>no;
cout<<"请输入姓名:";
cin>>name;
cout<<"请输入成绩:";
cin>>score;
Student s;
s.SeInfo(no,name,score);
int i;
for (i=count;i>=index-1;i--)
{
stu[i+1]=stu[i];
}
stu[index-1]=s;
count++;
cout<<"插入成功!"<<endl;
}
void DeleteScore()//删除成绩
{
int index;
cout<<"请输入插入位置:";
cin>>index;
int i;
for(i=index-1;i<count;i++)
{
stu[i]=stu[i+1];
}
count--;
cout<<"删除成功!"<<endl;
}