⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 studentinfo.cpp

📁 学生信息管理系统:本程序可以实现输入
💻 CPP
字号:
typedef unsigned long int  ULInt;
typedef unsigned  int      UInt;
#include<iostream.h>
#include<stdlib.h>
#include<iomanip.h>
#include<string.h>
#include"StudentInfo.h"
Student::Student()
	{
		number=0;
		strcpy(name,"no");
		gender='m';
		age=0;
		score=0;
	}


void Student:: InputInfo()
	{
//	int i=0;
//	char number[20],name[80],ch;
		cout<<"请输入某个学生的信息:"<<endl;
		cout<<"学号:";
//		do{
//			cin.get(ch);
//			number[i++]=ch;
//		}while(ch!='\n');
//			number[i-1]='\0';
		cin>>number;


//			i=0;
		cout<<"姓名:";
//		do{
//			cin.get(ch);
//			name[i++]=ch;
//		}while(ch!='\n');
//			name[i-1]='\0';
		cin>>name;



		cout<<"性别:";
		cin>>setw(2)>>gender;
		while(gender!='m'&&gender!='f')
		{
			cout<<"请输入正确的性别(男---'m',女---'f'):"<<endl;
			cout<<"性别:";
			cin>>gender;
		}
		cout<<"年龄:";
		cin>>age;
		while(age<0||age>100){
			cout<<"您输入的年龄不实际,请重新输入!!"<<endl;
			cin>>age;
		}
		cout<<"成绩:";
		cin>>score;
		cout<<endl;
	}
   bool Student::operator < (const Student& s)
	{
		return score<s.score;
	}


   bool Student::operator > (const Student& s)
   {
	   return score>s.score;
   }


  bool Student::operator == (const Student& s)
  {
	  // return score==s.score;
	  return strcmp(name,s.name)==0;
  }

  bool Student::operator != (const Student& s)
  {
	   return score!=s.score;
  }

ostream& operator << (ostream& os,const Student& p)
	{
	    cout<<"*************************************************"<<endl;
		os<<setw(30)<<"学号:"<<p.number<<endl
		  <<setw(30)<<"姓名:"<<p.name<<endl
		  <<setw(30)<<"性别:"<<p.gender<<endl
		  <<setw(30)<<"年龄:"<<p.age<<endl
		  <<setw(30)<<"分数:"<<p.score<<endl;
		cout<<"*************************************************"<<endl;
		return os;
	}
 istream& operator >> (istream& is,Student& p)
 {
	 is>>p.number;
	 is>>p.name;
	 is>>p.gender;
	 is>>p.age;
	 is>>p.score;
	 return is;
 }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -