#include<iostream>usingnamespace std;intmain(){
cout <<"Name:Trump"<< endl;
cout<<"Address:The White House is located at No.1600,";
cout <<"Pennsylvania Avenue, downtown of Washington DC"<< endl;return0;}
#include<iostream>usingnamespace std;intmain(){double dis;
cout <<"Please enter a distance in long."<< endl;
cin >> dis;
cout << dis <<" long = "<<200* dis <<" yard"<< endl;return0;}
3.编写一个C++程序,它使用3个用户定义的函数(包括main()),并生成下面的输出……
#include<iostream>usingnamespace std;voidprint1();voidprint2();intmain(){print1();print1();print2();print2();return0;}voidprint1(){
cout <<"Three blind mice"<< endl;}voidprint2(){
cout <<"See how they run"<< endl;}
4.编写一个程序:让用户输入其年龄……
#include<iostream>usingnamespace std;intmain(){
cout <<"Enter your age:";unsignedint year;
cin >> year;
cout << year <<" years includes "<< year *12<<" months."<< endl;return0;}
5.编写一个程序,其中main()调用一个用户定义的函数……
#include<iostream>usingnamespace std;floatfah(float cel);intmain(){float cel;
cout <<"Please enter a Celsius value:";
cin >> cel;
cout << cel <<" degrees Celsius is "<<fah(cel)<<" degrees Fahrenheit."<< endl;return0;}floatfah(float cel){float fah;
fah =1.8* cel +32.0;return fah;}
6.编写一个程序,其中main()调用一个用户定义的函数(光年转换……)
//编程练习2.5编写一个C++程序,其中……#include<iostream>usingnamespace std;doubleast(float lighty);intmain(){double lighty;
cout <<"Please enter the number of light years:";
cin >> lighty;
cout << lighty <<" light years = "<<ast(lighty)<<" astronomical units."<< endl;return0;}doubleast(float lighty){double ast;
ast =63240* lighty;return ast;}
7.编写一个程序,要求用户输入小时数何分钟数……
//编程练习2.5编写一个C++程序,其中……#include<iostream>usingnamespace std;voidTime(int h,int min);intmain(){int h, min;
cout <<"Enter the number of hours:";
cin >> h;
cout <<"Enter the number of minutes:";
cin >> min;Time(h, min);return0;}voidTime(int h,int min){int hour, mins;
hour = h%24+ min /60;
mins = min %60;
cout <<"Time: "<< hour <<":"<< mins << endl;}