C++ 带结构的数组字符
C++ Array Characters w/ Structures
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
对部门进行排序。
相关文章:
- 指向指向字符数组的指针数组的指针
- 比较字符数组
- 如何使用Crypto++并为RSA返回可打印的字节/字符数组
- 使用无符号字符数组有效存储内存
- 按字符值访问int数组
- 错误:字符数组的初始值设定项太多
- 对字符数组中的元素执行逐位操作
- C++,在int数组中输入字符串或字符会输出0,而不是ascii或error
- C++ 无法在字符数组中使用 for 循环打印字母模式
- 如何在 C++ 中从文件中读取字符数组(带有一些空格)
- 移动二维数组中的字符
- C++ 传递二维字符数组
- 无法在 C++ 中输入字符数组
- C++ 带结构的数组字符
- 数组字符包含量超出预期
- 读取文件并添加到数组字符
- 如何在Qt中更改或替换数组字符
- 为什么编译器不在参数中传递数组字符 *arr[] 的大小?
- 井字棋数组字符错误
- 分割数组字符