又是被费老师折磨的一周,这周自己找了好多视频来看,学了类class,又要开始学STL了
这周交上了程序设计的第二份作业
核酸检测(半成品,还是不大会写,但是还是要记录一下子滴)
代码如下:
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
using namespace std;
class Date
{
int year,month,day;
public:
Date();
Date(int y,int m,int d);
void showDate();
};
Date::Date()
{
year=0;
month=0;
day=0;
}
Date::Date(int y,int m,int d)
{
year=y;
month=m;
day=d;
}
void Date::showDate()
{
cout<<year<<"."<<month<<"."<<day<<endl;
}
class person
{
private:
string id;
string name;
string phone;
int n;
Date time;
bool consequence;
public:
person(string id,string name,string phone,int n,bool consequence);
person();
void setId(string id);
string getId();
void setName(string name);
string getName();
void setPhone(string phone);
string getPhone();
void setN(int n);
int getN();
void setDate(string Date);
string getDate();
void setConsequence(bool consequence);
bool getConsequence();
void shuru();
void shuchu();
};
person::person(string id,string name,string phone,int n,bool consequence){
this->id=id;
this->name=name;
this->phone=phone;
this->n=n;
this->consequence=consequence;
}
person::person(){
id="123";
name="hhh";
phone="1234";
n=1;
consequence=0;
}
void person::setName(string name)
{
this->name=name;
}
string person::getName()
{
return name;
}
void person::setId(string id)
{
this->id=id;
}
string person::getId()
{
return id;
}
void person::setPhone(string phone)
{
this->phone=phone;
}
string person::getPhone()
{
return phone;
}
void person::shuru(){
string mid;
string mname;
string mphone;
int mn;
bool mconsequence;
cin>>mid>>mname>>mphone>>mn>>mconsequence;
id=mid;
name=mname;
phone=mphone;
n=mn;
consequence=mconsequence;
}
void person::shuchu(){
cout<<"身份证号:"<<id<<endl;
cout<<"姓名:"<<name<<endl;
cout<<"电话号:"<<phone<<endl;
cout<<"已检次数"<<n<<endl;
cout<<"结果"<<consequence<<endl;
}
//!!!!!!!!
class use
{
private:
person* p;
int num;
int max;
int n;
public:
use()
{
p=new person[100];
num=0;
max=100;
n=0;
}
use(int n)
{
p=new person[n];
num=0;
max=0;
n=0;
}
int getNum()
{
return num;
}
int getMax()
{
return max;
}
person* getList()
{
return p;
}
void add(person one);
void findOne(string id);
void change(string id);
void deleteOne(string id);
void findName(string name);
void print();
~use();
};
void use::add(person one)
{
if (num < max)
{
p[num+1]=one;
num=num+1;
}
else
{
cout<<"人数已满"<<endl;
}
}
void use::findOne(string id)
{
person* p;
p = p;
}
void use::deleteOne(string id)
{
person* p, * q, * s;
p = p;
int k = 1;
if (k == 1 && p == p)
{
p = q;
num--;
return;
}
else if (k == num)
{
s=p;
int i=0;
delete p;
num--;
return;
}
else
{
int j = 0;
p = p;
while (j < k - 2)
delete q;
num--;
}
}
void use::findName(string name)
{
person* p = p;
int position= -1;
}
void use::change(string mid)
{
for(int j=0;j<num;j++)
{
if(p[j].getId()==mid){
string ppname;
cin>>ppname;
p[j].setName(ppname);
}
}
}
void bubbleSort(int person[],int num)
{
for(int i=num-1;i>0;i--)
for(int j=0;j<i;j++)
if(person[i]>person[i+1])
swap(person[j],person[j+1]);
}
int main(){
Date a_Date(2022,4,29);
a_Date.showDate();
person student[2];
for(int i=0;i<2;i++){
student[i].shuru();
}
for(int i=0;i<2;i++){
student[i].shuchu();
}
cout<<37010203010203<<"宋一"<<1858623576<<5<<0<<endl;
cout<<37011668431533<<"宋二"<<1851256645<<4<<0<<endl;
cout<<37010203058715<<"宋三"<<1851226575<<3<<0<<endl;
cout<<37010158486764<<"宋四"<<1823856765<<2<<0<<endl;
cout<<37017635826552<<"宋五"<<1852856853<<1<<0<<endl;
}