標題:
[隨堂測驗] 陣列- 電話簿
[打印本頁]
作者:
張翼安
時間:
2016-4-16 10:06
標題:
[隨堂測驗] 陣列- 電話簿
試以二維陣列的概念, 輸出如下的電話簿.
作者:
蔡季樺
時間:
2016-4-16 10:21
本帖最後由 蔡季樺 於 2016-4-16 11:44 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
string x[6][2]={{"姓名","電話"},
{"Tom","0929645878"},
{"Tony","0935467898"},
{"bank","0921654879"},
{"beach","0929005432"},
{"yee~","0987987732"}};
for(int i=0; i<=5; i++)
{
for(int j=0; j<=1; j++)
{
cout<<x[i][j]<<"\t";
}
cout<<endl;
}
cout<<endl;
system("pause");
return 0;
}
複製代碼
作者:
蔡庭豪
時間:
2016-4-16 10:30
本帖最後由 蔡庭豪 於 2016-4-16 11:30 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
string namenumber[5][2]={{"大雄","0980454666"},{"妓安","0911333898"},{"宜靜","0922999579"},{"啊福","0938234567"},{"叮噹小","0911864356"}};
cout<<"姓名 電話號碼"<<endl;
cout<<"=========================="<<endl;
for(int i=0;i<5;i++)
{
for(int j=0;j<2;j++)
{
cout<<namenumber[i][j]<<"\t";
}
cout<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
張健勳
時間:
2016-4-16 11:08
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
string arr[5][2]={{"小明","0923-456-789"},
{"小王","0983-945-536"},
{"小張","0933-243-555"},
{"小人","0977-525-656"},
{"小影","09開頭的不告訴你"}};
cout<<"姓名 電話號碼"<<endl;
cout<<"=========================="<<endl;
for(int i=0;i<5;i++)
{
for(int =j=0;j<2;j++)
{
cout<<arr[i][j]<<"\t";
}
cout<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
吳承勳
時間:
2016-4-16 11:26
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
string array[5][2]={{"...", "094463443"},
{"---", "096257242"},
{"///", "095678901"},
{"***", "091234567"},
{"+++","091234587"}};
cout << "姓名" << " " << "電話" << endl;
cout << "====================================" << endl;
for(int j = 0; j < 5; j++)
{
for(int i = 0; i < 2; i++)
{
cout << array[j][i] << "\t";
}
cout << endl;
}
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2