IO-00~~~IO-04

来源:互联网 发布:如何成为金融数据分析 编辑:程序博客网 时间:2024/05/18 03:16

前几个题目比较简单,我把他们写在一块省的每次都要建立新的博文麻烦

IO-00

#include<iostream>
using std::cout;
int main()
{
cout << "Hello World !";
return 0;
}


IO-01  //我只输出了前两行,因为哪些地名和数字太麻烦,剩下的自己补充就能得到原题的效果

#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
char *line = "------------------------------------------------------";
cout << line<<endl;
cout << left;cout << setw(15) << "Province";
cout << right;cout << setw(15) << "Area(km2)" << setw(15) << "Pop(10k)" << endl;
cout << line << endl;
cout << left; cout << setw(15) << "Anhui";
cout << right; cout << setw(15) << "139600.00" << setw(15) << "6461.00" << endl;
cout << left; cout << setw(15) << "Bejing";
cout << right; cout << setw(15) << "16410.54" << setw(15) << "1180.70" << endl;
cout << line << endl;
return 0;
}


IO-02

#include<iostream>
int main()
{
using namespace std;
int a, b;
cout << "Enter two numbers :"<<endl;
if (cin >> a&&cin >> b)
{
cout << a << "+" << b << "=" << a + b << endl;
cout << a << "-" << b << "=" << a - b << endl;
cout << a << "*" << b << "=" << a * b << endl;
cout << a << "/" << b << "=" << a / b << endl;
}
cin.get();
return 0;
}


IO-03

#include<iostream>
#include<iomanip>
int main()
{
using namespace std;
ios_base::fmtflags orig = cout.setf(ios_base::fixed, ios_base::floatfield);
int n = 4; int a[4]; int sum = 0;
cout << "Enter four numbers.\n";
for (int i = 0; i < n; i++)
{
cin >> a[i]; sum += a[i];
}
cout << "Sum = " << sum;
cout.precision(1);
cout<< " ; Average = " << double(sum)/ 4 << endl;
return 0;
}


IO-04

#include<iostream>
int main()
{
using namespace std;
ios_base::fmtflags orig = cout.setf(ios_base::fixed, ios_base::floatfield);
cout.precision(2);
int one; char two; float three; float four;
cout << "Enter four value: float1, int,char,float2\n";
cin >> three;
cin >> one;
cin >> two;
cin >> four;
cout << "Following is output :char,int,float1,float2\n";
cout << two <<"  "<< one <<"  "<< three <<"  "<< four << endl;
return 0;
}


0 0