C++ Primer Plus 第2章 编程练习
2015-07-11 20:55
519 查看
1.
#include <iostream>
int main()
{
using namespace std;
cout << "betaojia" << endl;
cout << "beijing" << endl;
cin.get();
return 0;
}
2.
#include <iostream>
double fur2feet(double);
int main()
{
using namespace std;
double fur;
cin >> fur;
double feet = fur2feet(fur);
cout << feet << endl;
cin.get();
cin.get();
return 0;
}
double fur2feet(double t)
{
double f = t*220.0;
return f;
}
3.
#include <iostream>
void first();
void second();
int main()
{
first();
first();
second();
second();
return 0;
}
void first()
{
using namespace std;
cout << "Three blind mice" << endl;
}
void second()
{
using namespace std;
cout << "See how they run" << endl;
}
4.
#include <iostream>
int year2month(int);
int main()
{
using namespace std;
cout << "Enter your age: ";
int age;
cin >> age;
//cout << endl;
int month = year2month(age);
cout << month;
cin.get();
cin.get();
return 0;
}
int year2month(int y)
{
return y*12;
}5.
#include <iostream>
double C2F(double);
int main()
{
using namespace std;
cout << "Please enter a Celsius value: ";
double c;
cin >> c;
double f = C2F(c);
cout << c << " degree Celsius is " << f << " degree Fahrenheit.";
cin.get();
cin.get();
return 0;
}
double C2F(double a)
{
return 1.8 * a + 32.0;
}
6.
#include <iostream>
double lightyear2astronomicalunit(double);
int main()
{
using namespace std;
cout << "Enter the number of light years: ";
double l;
cin >> l;
double a = lightyear2astronomicalunit(l);
cout << l << " light years = " << a << " astromical units.";
cin.get();
cin.get();
return 0;
}
double lightyear2astronomicalunit(double a)
{
return 63240.0 * a;
}
7.
#include <iostream>
using namespace std;
int inputhour();
int inputmin();
int main()
{
int hour = inputhour();
int min = inputmin();
cout << "Time: " << hour << ":" << min;
cin.get();
cin.get();
return 0;
}
int inputhour()
{
cout << "Enter the number of hours: ";
int h;
cin >> h;
return h;
}
int inputmin()
{
cout << "Enter the number of minutes: ";
int m;
cin >> m;
return m;
}
#include <iostream>
int main()
{
using namespace std;
cout << "betaojia" << endl;
cout << "beijing" << endl;
cin.get();
return 0;
}
2.
#include <iostream>
double fur2feet(double);
int main()
{
using namespace std;
double fur;
cin >> fur;
double feet = fur2feet(fur);
cout << feet << endl;
cin.get();
cin.get();
return 0;
}
double fur2feet(double t)
{
double f = t*220.0;
return f;
}
3.
#include <iostream>
void first();
void second();
int main()
{
first();
first();
second();
second();
return 0;
}
void first()
{
using namespace std;
cout << "Three blind mice" << endl;
}
void second()
{
using namespace std;
cout << "See how they run" << endl;
}
4.
#include <iostream>
int year2month(int);
int main()
{
using namespace std;
cout << "Enter your age: ";
int age;
cin >> age;
//cout << endl;
int month = year2month(age);
cout << month;
cin.get();
cin.get();
return 0;
}
int year2month(int y)
{
return y*12;
}5.
#include <iostream>
double C2F(double);
int main()
{
using namespace std;
cout << "Please enter a Celsius value: ";
double c;
cin >> c;
double f = C2F(c);
cout << c << " degree Celsius is " << f << " degree Fahrenheit.";
cin.get();
cin.get();
return 0;
}
double C2F(double a)
{
return 1.8 * a + 32.0;
}
6.
#include <iostream>
double lightyear2astronomicalunit(double);
int main()
{
using namespace std;
cout << "Enter the number of light years: ";
double l;
cin >> l;
double a = lightyear2astronomicalunit(l);
cout << l << " light years = " << a << " astromical units.";
cin.get();
cin.get();
return 0;
}
double lightyear2astronomicalunit(double a)
{
return 63240.0 * a;
}
7.
#include <iostream>
using namespace std;
int inputhour();
int inputmin();
int main()
{
int hour = inputhour();
int min = inputmin();
cout << "Time: " << hour << ":" << min;
cin.get();
cin.get();
return 0;
}
int inputhour()
{
cout << "Enter the number of hours: ";
int h;
cin >> h;
return h;
}
int inputmin()
{
cout << "Enter the number of minutes: ";
int m;
cin >> m;
return m;
}
相关文章推荐
- c语言
- C++完美实现Singleton模式
- 【C++】静态成员与单例模式
- C++中的inline函数
- C语言的复习
- C++11新增for循环遍历方法
- 拆除vs发展c++程序开发过程中产生的.ipch和.sdf文件的方法
- C++11变参模板
- c++ primer读书笔记-第十三章 复制控制
- c++uml关系总结(关联,聚合,组合,依赖。。。)
- C++ primer 5 笔记2 chapter 2 变量和基本类型(2.1~2.3)
- 用C++实现最小公倍数和最大公约数
- C++笔记(7):动态内存分配与释放函数
- c++primer要点-特殊工具与技术
- C++笔记(6):结构体
- C语言 交换两个变量的值的实现
- C++笔记(5):指针
- LeetCode 之 Implement Queue using Stacks — C++ 实现
- chapter17test5
- C++实现数字媒体二维图像变换