C++ 带结构的数组字符

C++ Array Characters w/ Structures

本文关键字:数组 字符 结构 C++      更新时间:2023-10-16
 struct prof
 {
string fn;
string ln;
string deg;
string dep;
string pos;
   };

   int main ()
   {
    prof ins[50];
   int i=0;
   int h=0;
   int d=0; 
   int choice;
   a:
   cout<<"Good Day!!"<<endl;
  cout<<"How many college instructor you want to input?";
   cin>>h;


 for(i=0;i<h;i++)
{

cout<<"First name:";
cin>>ins[i].fn;
cout<<"Last name:";
cin>>ins[i].ln;
cout<<"Department:";
cin>>ins[i].dep;
cout<<"Position:";
cin>>ins[i].pos;
cout<<"Degree:";
cin>>ins[i].deg;
 }

cout << "   "<<endl;
cout << "Here are the "<<h<<" college instructor that you encode:"<<endl;
cout << "   "<<endl;

 for(i=0;i<h;i++)
{

cout<<"# "<<i<<" Name: "<<ins[i].fn<<" "<<ins[i].ln<<endl;
cout<<"# "<<i<<" Department: "<<ins[i].dep<<endl;
cout<<"# "<<i<<" Position: "<<ins[i].pos<<endl;
cout<<"# "<<i<<" Degree: "<<ins[i].deg<<endl;
cout<<"                    "<<endl;
getch ();
}
 cout << " Thank you for using this program, do you want to encode again?   Yes(1)          No(2) "<<endl;
cin >> choice;
if (choice==1) {goto a;}
if (choice==2) {return 0;}

}

这是我的代码。有人问我另一个版本,它将根据教授的部门输出。它将把所有"部门 a"放在一起,把"部门 b"放在一起,依此类推。顺便说一句,我是新的编程环境。

根据我的理解,你想要对某种结构类型的数组进行排序。

我会使用<algorithm>传递lambda stable_sort对部门进行排序。