首页
关于
推荐
Karos'blog
Search
1
晒谷子
165 阅读
2
python初学示例
153 阅读
3
痛
135 阅读
4
爷做的菜
128 阅读
5
欢迎使用 Typecho
124 阅读
默认分类
登录
Search
小杜
累计撰写
28
篇文章
累计收到
3
条评论
首页
栏目
默认分类
页面
关于
推荐
Karos'blog
搜索到
28
篇与
默认分类
的结果
2022-06-22
职员管理系统
main.cpp的内容#include"add.h" #include<iostream> #include<string> #include<algorithm> #include<fstream> #include<stdlib.h> using namespace std; void CreatAdmin(); int main() { char Choice; string UserName,PassWord; string InputUserName,InputPassWord; ifstream fin("admin.dat",ios::in); if(!fin) { cout<<"还未创建admin用户,请创建"; CreatAdmin(); fin.close(); } fin.close(); fin.open("admin.dat",ios::in); fin>>UserName; fin>>PassWord; cout<<"请输入admin用户名"<<endl; cin>>InputUserName; cout<<"请输入admin密码"<<endl; cin>>InputPassWord; if(UserName==InputUserName && InputPassWord==PassWord) { system("cls"); cout<<"已进入系统!"<<endl; PrintWlecome(UserName); cin>>Choice; while (1) { JusticeUsersChoice(Choice); system("color 04"); cout<<"请选择操作\n1.存入信息\n2.删除信息\n3.查找信息\n4.遍历信息\n5.修改信息"<<endl; cin>>Choice; } } else{ cout<<"用户名或者密码不正确"<<endl; exit(0); } system("pause"); } void CreatAdmin() { string UserName,PassWord; ofstream fout("admin.dat",ios::out|ios::binary); cout<<"请输入admin用户名"<<endl; cin>>UserName; cout<<"请输入admin密码"<<endl; cin>>PassWord; fout<<UserName<<" "<<PassWord; fout.close(); system("cls"); }add.h的内容#include<iostream> #include<fstream> #include<ctime> #include<Windows.h> using namespace std; void GetUserInput(); void PrintWlecome(string UserName); void GetUserInput(); void JusticeUsersChoice(char Choice); void PointReadFile(); void ThroughAll(); void ReviseData(); bool DeletInfo(); void LogWrite(); class Person { private: string name; string id; string numbers; string address; char sex; string age; double salary; string diploma; public: void Set_value(string name1,string id1,string number,string address1,char sex1,double salary1,string age1,string diploma1) { name=name1; id=id1; numbers=number; address=address1; sex=sex1; salary=salary1; diploma=diploma1; age=age1; } friend ofstream &operator<<(ofstream &fout,Person &a) { fout<<a.id<<" "<<a.name<<" "<<a.numbers<<" "<<a.address<<" "<<a.sex<<" "<<a.age<<" "<<a.salary<<" "<<a.diploma<<endl; return fout; } void print() { cout<<id<<"\t"<<name<<"\t"<<numbers<<"\t"<<address<<"\t"<<sex<<"\t"<<age<<"\t"<<salary<<"\t"<<diploma<<endl; } int Write() { ofstream fout("num.dat",ios::app); if(!fout) { cout<<"打开文件num.dat失败"<<endl; } fout<<id<<" "<<name<<" "<<numbers<<" "<<address<<" "<<sex<<" "<<age<<" "<<salary<<" "<<diploma<<endl; fout.close(); return 0; } friend ostream &operator<<(ostream &out,Person &a) { out<<a.id<<" "<<a.name<<" "<<a.numbers<<" "<<a.address<<" "<<a.sex<<" "<<a.age<<" "<<a.salary<<" "<<a.diploma<<endl; return out; } friend ifstream &operator>>(ifstream &fin,Person &people) { fin>>people.id; fin>>people.name; fin>>people.address; fin>>people.sex; fin>>people.age; fin>>people.salary; fin>>people.diploma; return fin; } }; void LogWrite(Person people,string operate) { SYSTEMTIME systime={0}; GetSystemTime(&systime); ofstream fout("log.txt",ios::app); fout<<people<<"\t"<<operate<<" "<<systime.wYear<<":"<<systime.wMonth<<":"<<systime.wDay<<":"<<systime.wHour+8<<":"<<systime.wMinute<<":"<<systime.wSecond<<endl; } void PrintWlecome(string UserName) { system("color 04"); SYSTEMTIME systime={0}; GetSystemTime(&systime); cout<<"尊敬的 "<<UserName<<" 欢迎进入进入本系统!"<<endl; cout<<"系统当前时间:"<<systime.wYear<<":"<<systime.wMonth<<":"<<systime.wDay<<":"<<systime.wHour+8<<":"<<systime.wMinute<<":"<<systime.wSecond<<endl; cout<<"请选择操作\n1.存入信息\n2.删除信息\n3.查找信息\n4.遍历信息\n5.修改信息"<<endl; } void GetUserInput() { string name1; string id1; string number1; string address1; char sex1; string age1; double salary1; string diploma1; Person people; cout<<"请输入\nid 名字 number 地址 性别(m/f) 年龄 薪水 学历(中间有空格)"<<endl; cin>>id1>>name1>>number1>>address1>>sex1>>age1>>salary1>>diploma1; people.Set_value(name1,id1,number1,address1,sex1,salary1,age1,diploma1); people.print(); people.Write(); LogWrite(people,"输入"); } void JusticeUsersChoice(char Choice) { if(Choice=='1') { GetUserInput(); } else if(Choice=='2') { DeletInfo(); } else if(Choice=='3') { PointReadFile(); } else if(Choice=='4') { ThroughAll(); } else if(Choice=='5') { ReviseData(); } else{ cout<<"好歹也要选择一个嘛"<<endl; } } void PointReadFile() { bool point=0; char Choice; string FoundName; string Diploma; string name1; string id1; string number1; string address1; char sex1; string age1; double salary1; string diploma1; Person people; ifstream fin("num.dat",ios::in); cout<<"请输入序号\n1.查询id\n2.学历"<<endl; cin>>Choice; if(Choice=='1') { cout<<"请输入id"<<endl; cin>>FoundName; } else { cout<<"请输入学历"<<endl; cin>>Diploma; } if(!fin) { cout<<"打开文件num.dat失败"<<endl; } while(1) { fin>>id1; fin>>name1; fin>>number1; fin>>address1; fin>>sex1; fin>>age1; fin>>salary1; fin>>diploma1; people.Set_value(name1,id1,number1,address1,sex1,salary1,age1,diploma1); if(FoundName==id1) { break; } else if(Diploma==diploma1&&!fin.eof()) { cout<<"id 名字 number 地址 性别 年龄 薪水 学历"<<endl; cout<<people; LogWrite(people,"查找"); point=1; } if(fin.eof()) { if(!point) { cout<<"查无此人"<<endl; } break; } } if(FoundName==id1) { cout<<people; LogWrite(people,"查找"); } } bool DeletInfo() { string FoundId; string name1; string id1; string number1; string address1; char sex1; string age1; double salary1; string diploma1; Person people; int point=1; bool HasFound=0; ofstream fout("mid.dat",ios::app); ifstream fin("num.dat",ios::in); cout<<"输入你想查找的id"<<endl; cin>>FoundId; while (point) { fin>>id1; fin>>name1; fin>>number1; fin>>address1; fin>>sex1; fin>>age1; fin>>salary1; fin>>diploma1; people.Set_value(name1,id1,number1,address1,sex1,salary1,age1,diploma1); point=!fin.eof(); if(point!=1) { break; } if(FoundId!=id1) { fout<<people; } else { HasFound=1; LogWrite(people,"删除"); } } if(HasFound==0) { cout<<"没有这个职工,请输入正确的职工号"<<endl; } else { point=1; fin.clear(); fin.close(); fout.close(); fout.open("num.dat"); fin.open("mid.dat"); while(point) { fin>>id1; fin>>name1; fin>>number1; fin>>address1; fin>>sex1; fin>>age1; fin>>salary1; fin>>diploma1; people.Set_value(name1,id1,number1,address1,sex1,salary1,age1,diploma1); point=!fin.eof(); if(point) { fout<<people; } } fin.clear(); fin.close(); fout.close(); if(remove("mid.dat")) { cout<<"删除中介文件错误"<<endl; } cout<<"删除完成"<<endl; } return 0; } void ReviseData() { string FoundId; string name1; string id1; string number1; string address1; char sex1; string age1; double salary1; string diploma1; Person people; int point=1; bool HasFound=0; ofstream fout("mid.dat",ios::app); ifstream fin("num.dat",ios::in); cout<<"输入你想查找的id"<<endl; cin>>FoundId; while (point) { fin>>id1; fin>>name1; fin>>number1; fin>>address1; fin>>sex1; fin>>age1; fin>>salary1; fin>>diploma1; people.Set_value(name1,id1,number1,address1,sex1,salary1,age1,diploma1); point=!fin.eof(); if(point!=1) { break; } if(FoundId!=id1) { fout<<people; } else { HasFound=1; cout<<"请输入id 名字 number 地址 性别(m/f) 年龄 薪水 学历(中间有空格)"<<endl; cin>>id1>>name1>>number1>>address1>>sex1>>age1>>salary1>>diploma1; people.Set_value(name1,id1,number1,address1,sex1,salary1,age1,diploma1); fout<<people; LogWrite(people,"修改"); } } if(HasFound==0) { cout<<"没有这个职工,请输入正确的职工号"<<endl; } else { point=1; fin.clear(); fin.close(); fout.close(); fout.open("num.dat"); fin.open("mid.dat"); while(point) { fin>>id1; fin>>name1; fin>>number1; fin>>address1; fin>>sex1; fin>>age1; fin>>salary1; fin>>diploma1; people.Set_value(name1,id1,number1,address1,sex1,salary1,age1,diploma1); point=!fin.eof(); if(point) { fout<<people; } } fin.clear(); fin.close(); fout.close(); if(remove("mid.dat")) { cout<<"删除中介文件错误"<<endl; } cout<<"修改完成"<<endl; } } void ThroughAll() { // string name1; // string id1; // string number1; // string address1; // char sex1; // string age1; // double salary1; // string diploma1; ifstream fin("num.dat",ios::in); Person people; int point=1; while(point) { // fin>>id1; // fin>>name1; // fin>>number1; // fin>>address1; // fin>>sex1; // fin>>age1; // fin>>salary1; // fin>>diploma1; fin>>people; point=!fin.eof(); // people.Set_value(name1,id1,number1,address1,sex1,salary1,age1,diploma1); if(point!=1) { break; } cout<<people; } }
2022年06月22日
65 阅读
0 评论
0 点赞
2022-05-21
大数相加
#include<iostream> #include<string> #include<algorithm> using namespace std; int main(){ string a,b,c; int length_a,length_b; cin>>a; cin>>b; length_a=a.length(); length_b=b.length(); reverse(a.begin(),a.end()); reverse(b.begin(),b.end()); if(length_a>=length_b) { for(int i=0;i<(length_a-length_b);i++) { b.append(1,'0'); } } else { for(int i=0;i<(length_b-length_a);i++) { a.append(1,'0'); } } cout<<a<<endl; cout<<b<<endl; if(length_a>=length_b) { for(int i=0;i<length_a;i++) { a[i]-='0'; b[i]-='0'; if((a[i]+b[i])>=10) { c.append(1,(a[i]+b[i])%10); a[i+1]++; c[i]+='0'; } else { c.append(1,a[i]+b[i]); c[i]+='0'; } } } else { for(int i=0;i<length_b;i++) { a[i]-='0'; b[i]-='0'; if((a[i]+b[i])>=10) { c.append(1,(a[i]+b[i])%10); b[i+1]++; c[i]+='0'; } else { c.append(1,a[i]+b[i]); c[i]+='0'; } } } reverse(c.begin(),c.end()); int length_c=c.length(); cout<<c; }
2022年05月21日
58 阅读
0 评论
0 点赞
2022-05-21
线性表
2.设计一个程序,生成两个按值非递减有序排列的线性表LA和LB,再将LA和LB归并为一个新的线性表LC,且LC中的数据仍按值非递减有序排列,输出线性表LA、LB、LC。#include<iostream> using namespace std; struct node { int data; node *next; }; class linklist { private: int length_a; node *first; public: linklist(){ first=new node; first->next=NULL; } linklist(int a[],int len_a); void display();//输出函数 void appendd(int num);//在单链表尾部添加数据 ~linklist(){} friend linklist through(linklist &a,linklist &b);//友元函数,访问两个类,并且将加得的单链表,作为一个类返回; }; linklist::linklist(int a[],int len_a) { first=new node; node *p=first; for(int i=0;i<len_a;i++) { node *s=new node; s->data=a[i]; p->next=s; p=s; } p->next=NULL; } void linklist::appendd(int num){ node *p=first; while(p->next!=NULL) { p=p->next; } node *s=new node; s->data=num; p->next=s; p=s; p->next=NULL; } linklist through(linklist &a,linklist &b) { linklist m; node *p1=a.first->next; node *p2=b.first->next; while(p1!=NULL || p2!=NULL) { if(p1!=NULL && p2!=NULL) { if((p1->data)<=(p2->data)) { m.appendd(p1->data); m.appendd(p2->data); } else { m.appendd(p2->data); m.appendd(p1->data); } p1=p1->next; p2=p2->next; } else if(p1==NULL && p2!=NULL) { m.appendd(p2->data); p2=p2->next; } else { m.appendd(p1->data); p1=p1->next; } } return m; } void linklist::display() { node *p=first->next; while(p!=NULL) { cout<<p->data<<endl; p=p->next; } } int main() { int a[3]={1,3,5},b[5]={2,4,6,7,9}; linklist link_a(a,3),link_b(b,5),link_c; link_c=through(link_a,link_b); link_c.display(); system("pause"); }代码还是有一点有问题的,只能按一对一的大小排序,要真正实现升序,需要对链表进行排序
2022年05月21日
58 阅读
0 评论
0 点赞
2022-05-21
c++乘法器(失踪人口回归)
#include<iostream> #include<string> #include<algorithm> using namespace std; int main() { string a,b; string num; char pp[15][15];//接收乘法运算后的数据 char ch; for(int i=0;i<20;i++) { ch=getchar(); if(ch=='\n') break; else if(ch=='0'||ch=='1') { ch-='0'; a.append(1,ch); } else { } } for(int i=0;i<20;i++)//获取字符串,除0 1 外,其他字符无法输入到运算字符串中 { ch=getchar(); if(ch=='\n') break; else if(ch=='0'||ch=='1') { ch-='0'; b.append(1,ch); } else { } } if(a.length()!=b.length())//判断长度函数 { cout<<"not the same length"; exit(0); } for(int i=0;i<15;i++)//乘法运算块 { for(int j=0;j<15;j++) { pp[i][j]=0; } } int q=0,s=(2*b.length()-1),p=0,l=(2*b.length()-1); for(int i=a.length()-1;i>=0;i--,q++)//a做最下面的数; { s=l; l--; for(int j=b.length()-1;j>=0;j--,s--) { pp[q][s]=a[i]*b[j]; } } char ss=0; for(int i=(2*b.length()-1);i>=0;i--)//a做最下面的数;,累加块 { ss=0; for(int j=0;j<b.length();j++) { ss+=pp[j][i]; if(ss>=2) { if(ss%2==0) { pp[j][i-1]+=ss/2; ss=0; } if(ss%2==1) { pp[j][i-1]+=ss/2; ss=1; } } } ss+='0'; num.append(1,ss); } reverse(num.begin(),num.end());//字符串倒序函数; cout<<num; return 0; }
2022年05月21日
71 阅读
0 评论
0 点赞
2021-12-29
学生成绩统计c语言
`#include<stdio.h>include<string.h>define N 3struct sturec {char id[8]; char name[8]; float e,m,c,sum; };void print(struct sturec *p);void format(struct sturec lei[N]);int research(struct sturec *p4,char id[8]);void input(struct sturec *p1);int main(){char id[8]; int a; struct sturec stu[N],*point=stu; printf("please input student's id name englishscore mathscore chinesescore\n"); input(point); format(stu); print(point); printf("please input id which you want to research\n"); scanf("%s",id); a=research(stu,id); printf("%s %s %f",stu[a].id,stu[a].name,stu[a].sum); return 0;}void print(struct sturec *p){for(int i=0;i<N;i++) { printf("id=%sname=%ssum=%f\n",(p+i)->id,(p+i)->name,(p+i)->sum); }}void input(struct sturec *p2){for(int i=0;i<N;i++) { scanf("%s%s",(*p2).id,(*p2).name); scanf("%f%f%f",&(*p2).e,&(*p2).c,&(*p2).m); p2->sum=p2->c+p2->e+p2->m; p2++; }}void format(struct sturec lei[N]){struct sturec mid; for(int i=0;i<N;i++) { for(int j=0;j<N-1-i;j++) { if(lei[j].sum>lei[j+1].sum) { mid=lei[j]; lei[j]=lei[j+1]; lei[j+1]=mid; } } }}int research(struct sturec *p4,char id[8]){for(int i=0;i<N;i++) { if(stricmp(p4->id,id)==0) { return i; break; } }}`
2021年12月29日
69 阅读
0 评论
0 点赞
1
2
3
...
6