1、简易学生信息库(结构体)
# include# include using namespace std; struct Student { int num; float score; struct Student *next;//指向自己类型 };// ;容易掉 int main() { struct Student a, b, c, *head, *p;//定义一个头指针和一个移动指针 a.num = 1; a.score = 90; b.num = 2; b.score = 80; c.num = 3; c.score = 70; head = &c; // a.next = &b; // b.next = &c; c.next = NULL;//最后一个学生指向空 p = head; while(p!=NULL)//等价于while(p) { cout< num<<" "< score< num,p->score);//C p=p->next; } return 0; }
2、简易学生信息库(类)
//简易学生信息库(类) # includeusing namespace std; # define MAX 10000 class student{ private: int num; char name[10]; char sex; float Math; float Chinese; float English; public: void input(); void sum(); void aval(); };//;容易掉 void student::input(){ cout<<"请输入学生学号:"; cin>>num; cout<<"请输入学生姓名:"; cin>>name; cout<<"请输入学生性别:"; cin>>sex; cout<<"请输入数学成绩:"; cin>>Math; cout<<"请输入语文成绩:"; cin>>Chinese; cout<<"请输英语学成绩:"; cin>>English; } void student::sum(){ float S = Math+ Chinese+ English; cout< 3、简易职工信息库(类)
# includeusing namespace std; class Employee{ private: char name[10]; char sex; int num;//工龄 float gongzi; float jingtie; float xiaoyi; public: void input(); void sum1(); void sum2(); void sum3(); }; void Employee::input(){ cout<<"请输入你的名字:" < >name; cout<<"请输入你的性别:" < >sex; cout<<"请输入你的工号:" < >num; cout<<"请输入你的基础工资:" < >gongzi; cout<<"请输入你的岗位津贴:" < >jingtie; cout<<"请输入你的效应工资:" < >xiaoyi; } void Employee::sum1(){ cout< 4、链表的创建和输出
# include# include # include //exit using namespace std; #define OK 1 #define ERRPR 0 #define OVERFLOW -2 typedef int Status; typedef int ElemType; typedef struct LNode { ElemType data; struct LNode *next; }LNode, *linkList; //后插法创建单链表 void CreateList_R(linkList &L, int n)//引用 { linkList p, r; int i; L = new LNode; L->next = NULL; r = L; for(i = 0; i < n; ++i) { p = new LNode;//每一次循环都会生成一个新节点*p cin>>p->data; p->next = NULL; r->next = p; r = p; //p的地址赋给r;相当于让r坐p的凳子上 } } void ShowList(linkList L) { linkList p; p = L->next; while(p) { printf("%dt", p->data); p = p->next; } printf("n"); } int main() { linkList kk; int n; cin>>n; CreateList_R(kk, n); ShowList(kk); return 0; }



