選択システムc++設計と実現
102787 ワード
著者の自叙伝
このコードはあまり注釈を付けていませんが、難易度係数は高くありません.設計面での最適化と複数回の呼び出しが難しいだけです.墨跡はなく、直接コードをつけて、選択システムを設計する時に多くの先輩たちに聞いて、ここでも彼らの強力な支持に感謝します.
コード#コード#
おい!写さないで、参考にしてください!自分のコードにもっと高い突破をしなければなりません!
このコードはあまり注釈を付けていませんが、難易度係数は高くありません.設計面での最適化と複数回の呼び出しが難しいだけです.墨跡はなく、直接コードをつけて、選択システムを設計する時に多くの先輩たちに聞いて、ここでも彼らの強力な支持に感謝します.
コード#コード#
#include
#include
#include
#include
#include
#include
using namespace std;
void menu();
void student1();
void student2();
void student3();
void student4();
void teacher();
void teacher1();
void teacher2();
void teacher3();
int tpassword();
int spassword();
void save();
void turn();
int u,d;
class course
{
public:
char cname[10];
course * next;
}*chead=NULL;
class student
{
public:
int number;
char name[10];
char password[7];
int cnumber;
char course[6][20];
student * next;
}*head=NULL;
void menu()//
{
menu:
system("cls");
cout<<endl<<endl;
cout<<"*******************************************
"
<<"* *
"
<<"* *
"
<<"* *
"
<<"* *
"
<<"* : *
"
<<"* 1. *
"
<<"* *
"
<<"* 2. *
"
<<"* *
"
<<"* 3. *
"
<<"*******************************************
"<<endl;
while(1)
{
int a;
cout<<"
\t\t : ";
cin>>a;
if(a==1) {
student1();goto menu;}
else if(a==2) {
teacher();goto menu;}
else if(a==3) {
save(); break;}
else cout<<"\t\t\t\t\t !";
}
}
void teacher() //
{
int m;
m=tpassword();
if(m==1)
{
teacher1:
system("cls");
cout<<"
"
<<"※※※※※※※※※※※※※※※※※※※※※※※※※
"
<<"※ ※
"
<<"※ ※
"
<<"※ ※
"
<<"※ : ※
"
<<"※ 1. 2. ※
"
<<"※ 3. 4. ※
"
<<"※ ※
"
<<"※※※※※※※※※※※※※※※※※※※※※※※※※
"<<endl;
while(1)
{
cout<<"\t\t\t : ";
int a;cin>>a;
if(a==1)
{
teacher1();
cout<<" (y/n)";
char q;cin>>q;
if(q=='y')goto teacher1;
else if(q=='n')break;
}
else if(a==2)
{
teacher2();
cout<<" (y/n)";
char q;cin>>q;
if(q=='y')goto teacher1;
else if(q=='n')break;
}
else if(a==3)
{
teacher3();
cout<<" (y/n)";
char q;cin>>q;
if(q=='y')goto teacher1;
else if(q=='n')break;
}
else if(a==4) {
system("cls");break;}
else cout<<"
\t\t\t\t !";
}
}
}
int tpassword()
{
int k=0,i;
char A[]="123456";
char B[10];
char a;
system("cls");
for(i=0;i<8;i++)
cout<<endl;
while(1)
{
cout<<"\t\t\t :";
i=0;
while(1)
{
a=getch();
if(a==13)
break;
B[i]=a;
i++;
cout<<"*";
}
B[i]='\0';
if(strcmp(A,B)==0) return 1;
else
{
k++;
cerr<<"
\t\t\t ! !
"<<endl;
}
if(k==2) return 0;
}
}
void teacher1()//
{
ofstream outstuf;
cout<<" :(y/n)";
char k;cin>>k;
if(k=='n')
{
student * s,* q;
s=new student;head=q=s;
if(u==1)outstuf.open("student1.txt",ios::out);
else if(u==2)outstuf.open("student2.txt",ios::out);
cout<<"\t :";
int k;cin>>k;
cout<<"\t , , , ( 1 none)
";
cin>>s->number>>s->name>>s->password>>s->cnumber>>s->course[0];
outstuf<<s->number<<'\t'<<setw(8)<<s->name<<'\t'<<s->password<<'\t'<<s->cnumber<<'\t'<<s->course[0]<<'
';
int i=1;
for(i=1;i<k;i++)
{
s=new student;
cin>>s->number>>s->name>>s->password>>s->cnumber>>s->course[i];
outstuf<<s->number<<'\t'<<setw(8)<<s->name<<'\t'<<s->password<<'\t'<<s->cnumber<<'\t'<<s->course[i]<<'
';
q->next=s;
q=s;
}
q->next=NULL;
outstuf.close();
}
else if(k=='y')
{
student * s,* q;
s=new student;
for(q=head;q->next!=NULL;q=q->next);q->next=s;s=q;
if(u==1)outstuf.open("student1.txt",ios::app);
else if(u==2)outstuf.open("student2.txt",ios::app);
cout<<"\t :";
int k;cin>>k;
cout<<"\t , , , ( 1 1)
";
cin>>s->number>>s->name>>s->password>>s->cnumber>>s->course[0];
outstuf<<s->number<<'\t'<<setw(8)<<s->name<<'\t'<<s->password<<'\t'<<s->cnumber<<'\t'<<s->course[0]<<'
';
int i;
for(i=1;i<k;i++)
{
s=new student;
cin>>s->number>>s->name>>s->password>>s->cnumber>>s->course[i];
outstuf<<s->number<<'\t'<<setw(8)<<s->name<<'\t'<<s->password<<'\t'<<s->cnumber<<'\t'<<s->course[i]<<'
';
q->next=s;
q=s;
}
q->next=NULL;
outstuf.close();
}
}
void teacher2()//
{
ofstream outstuf;
cout<<" :(y/n)";
char k;cin>>k;
if(k=='n')
{
course * s,* q;
s=new course;chead=q=s;
if(u==1)outstuf.open("course1.txt",ios::out);
else if(u==2)outstuf.open("course2.txt",ios::out);
cout<<"\t :";
int k;cin>>k;
cout<<"\t :
";
cin>>s->cname;
outstuf<<s->cname<<'
';
for(int i=1;i<k;i++)
{
s=new course;
cin>>s->cname;
outstuf<<s->cname<<'
';
q->next=s;
q=s;
}
q->next=NULL;
outstuf.close();
}
else if(k=='y')
{
course * s,* q;
s=new course;
for(q=chead;q->next!=NULL;q=q->next);q->next=s;q=s;
if(u==1)outstuf.open("course1.txt",ios::app);
else if(u==2)outstuf.open("course2.txt",ios::app);
cout<<"\t :";
int k;cin>>k;
cout<<"\t :
";
cin>>s->cname;
outstuf<<s->cname<<'
';
for(int i=1;i<k;i++)
{
s=new course;
cin>>s->cname;
outstuf<<s->cname<<'
';
q->next=s;
q=s;
}
q->next=NULL;
outstuf.close();
}
}
void teacher3()//
{
student * p;p=head;
system("cls");cout<<"
";
cout<<" "<<setw(5)<<" "<<" "<<setw(5)<<" "<<" "<<setw(5)<<" "<<endl;
while(p!=NULL)
{
cout<<" "<<setw(5)<<p->number<<" "<<setw(5)<<p->name<<" ";
for(int i=0;i<p->cnumber;i++)cout<<p->course[i]<<" ";
cout<<endl;
p=p->next;
}
}
void student1()//
{
cout<<"\t\t\t :";
int m, b;cin>>b;d=b-1;
m=spassword();
if(m==1)
{
student1:
system("cls");//
cout<<"
";
cout<<"※※※※※※※※※※※※※※※※※※※※※※※※※※
"
<<"※ ※
"
<<"※ ※
"
<<"※ : ※
"
<<"※ 1、 ※
"
<<"※ 2、 ※
"
<<"※ 3、 ※
"
<<"※ 4、 ※
"
<<"※ ※
"
<<"※※※※※※※※※※※※※※※※※※※※※※※※※※
"<<endl;
while(1)
{
int a,k=1;
cout<<"\t\t\t : ";
cin>>a;
if(a==1)
{
student2();
cout<<" (y/n)";
char q;cin>>q;
if(q=='y')goto student1;
else if(q=='n')break;
}
else if(a==2) {
student3();goto student1;}
else if(a==3)
{
student4();
cout<<" (y/n)";
char q;cin>>q;
if(q=='y')goto student1;
else if(q=='n')break;
}
else if(a==4){
system("cls");break;}
else cout<<"\t\t\t\t\t !"<<endl;
}
}
}
int spassword()//
{
student * p;p=head;
for(int k=0;k<d;k++)
p=p->next;
int k=0;char B[7];char c[10];
gets(c);system("cls");
while(1)
{
cout<<"
";
cout<<"\t\t :";
gets(B);
if(strcmp(p->password,B)==0) return 1;
else
{
k++;cout<<"
\t\t\t ! !";
if(k>=3) {
system("cls");return 0;}
}
}
}
void student2()//
{
student * p;p=head;
for(int k=0;k<d;k++)
p=p->next;
system("cls");
course *q;
cout<<'
';
cout<<"\t\t\t :
";
for(q=chead;q!=NULL;q=q->next)
cout<<"\t\t\t"<<q->cname<<endl;
cout<<"\t\t\t ( ): ";
cin>>p->cnumber;
cout<<"\t\t\t :
";
int i;
for(i=0;i<p->cnumber;i++)
{
cout<<"\t\t\t ";
cin>>p->course[i];
}
save();
}
void student3()//
{
student * p;p=head;
for(int k=0;k<d;k++)
p=p->next;
t:
system("cls");
cout<<"
";
cout<<" :";
char q[7],w[7];
for(int i=0;i<6;i++)
cin>>q[i];
cout<<"
:";
for(int i=0;i<6;i++)
cin>>w[i];
while(1)
{
int k;
for(k=0;k<6;k++)
{
if(q[k]==w[k]){
}
else break;
}
if(k==6)
{
int i=0;
while(q[i])
{
p->password[i]=q[i];i++;}
p->password[6]='\0';
break;
}else goto t;
}save();
}
void student4()//
{
student * p;p=head;
for(int k=0;k<d;k++)
p=p->next;
cout<<"\t\t :
";
for(int i=0;i<p->cnumber;i++)
{
cout<<"\t\t ";
cout<<p->course[i]<<endl;
}
}
void save() //
{
ofstream outstuf1;
ofstream outstuf2;
if(u==1){
outstuf1.open("student1.txt",ios::trunc);outstuf2.open("course1.txt",ios::trunc);}
if(u==2){
outstuf1.open("student2.txt",ios::trunc);outstuf2.open("course2.txt",ios::trunc);}
student * s;
for(s=head;s!=NULL;s=s->next)
{
int i;
outstuf1<<s->number<<'\t'<<s->name<<'\t'<<s->password<<'\t'<<s->cnumber;
for(i=0;i<s->cnumber;i++) outstuf1<<'\t'<<s->course[i];
outstuf1<<'
';
}
course * q;
q=chead;
for(q=chead;q!=NULL;q=q->next)
{
outstuf2<<q->cname<<'
';}
outstuf1.close();outstuf2.close();
}
void turn()//
{
ifstream instuf1;ifstream instuf2;
if(u==1){
instuf1.open("student1.txt",ios::in);instuf2.open("course1.txt",ios::in);}
if(u==2){
instuf1.open("student2.txt",ios::in);instuf2.open("course2.txt",ios::in);}
student * s,* q; int i;
while(!instuf1.eof())
{
s=new student;
if(head==NULL)
{
head=q=s;
instuf1>>s->number>>s->name>>s->password>>s->cnumber;
for(i=0;i<s->cnumber;i++)instuf1>>s->course[i];
}
else
{
s=new student;
instuf1>>s->number>>s->name>>s->password>>s->cnumber;
for(i=0;i<s->cnumber;i++)instuf1>>s->course[i];
q->next=s;
q=s;
}
}
q->next=NULL;
course * z,* x;
z=new course;chead=x=z;
instuf2>>z->cname;
while(!instuf2.eof())
{
z=new course;
instuf2>>z->cname;
x->next=z;
x=z;
}
x->next=NULL;
instuf1.close();instuf2.close();
}
int main()
{
//
cout<<endl<<endl;
cout<<"*******************************************
"
<<"* *
"
<<"* *
"
<<"* *
"
<<"* : *
"
<<"* 1. *
"
<<"* *
"
<<"* 2. *
"
<<"* *
"
<<"* 3. *
"
<<"*******************************************
"<<endl;
cout<<" : ";
cin>>u;
switch(u)
{
case 1:
{
cout<<endl;
cout<<" :(y/n)";
char a;cin>>a;if(a=='n'){
turn();menu();}
else if(a=='y')menu();
}break;
case 2:
{
cout<<endl;
cout<<" :(y/n)";
char a;cin>>a;if(a=='n'){
turn();menu();}
else if(a=='y')menu();
}break;
case 3:break;
}
}
おい!写さないで、参考にしてください!自分のコードにもっと高い突破をしなければなりません!