C++ Primer Plus 第六版_编程练习(1)(Chapter_two 1-7)
2016-06-24 22:01
676 查看
编程工具用得好,搞起研究事半功倍。导师的意见是,学好C++,其他编程都不怕。暂时没有迫切的实战需要,于是决定从最基础的学起,挑了《C++ Primer Plus (第六版)》这本书,开始啃吧。编程练习还是一定要做的,每天一点,记在这里。
2_1:
2_2:
2_3:
2_4:
2_6
2_7
2_1:
#include <iostream> using namespace std; int main() { char name = 'k'; char add_ = 'C'; cout << name << endl; cout << add_ << endl; return 0; }
2_2:
#include <iostream> using namespace std; int main() { int long_; int ma; cout << "please input long_:"; cin >> long_; ma = long_ * 220; cout << "the long_ is " << ma << " ma" << endl; return 0; }
2_3:
#include <iostream> using namespace std; void function_1(); void function_2(); int main() { int i; for (i = 0; i < 2; i++) { function_1(); function_2(); } return 0; } void function_1() { cout << "Three blind mice" << endl; } void function_2() { cout << "See how they run" << endl; }
2_4:
#include<iostream> using namespace std; int main() { int year; int month; cout << "Enter your age:"; cin >> year; month = year * 12; cout << "Your age include " << month << " mouth" << endl; return 0; }
#include "iostream" using namespace std; float change(float a) { float b; b = 1.8*a + 32.0; return b; } int main() { float sh; cout << "Please enter a Celsius value:"; cin >> sh; float h = change(sh); cout << sh << " degrees Celsius is " << h << " degrees Fahrenheit." << endl; return 0; }
2_6
#include "iostream" using namespace std; double chenge(float a); int main() { float light_year; double astronomical_unite; cout << "Enter the number of light years: "; cin >> light_year; astronomical_unite = chenge(light_year); cout << light_year << " light years = " << astronomical_unite << " astronomical unites." << endl; return 0; } double chenge(float a) { return a * 63240; }
2_7
#include "iostream" using namespace std; void show_time(int a, int b); int main() { int hours_; int minutes_; cout << "Enter the number of hours:"; cin >> hours_; cout << "Enter the number of minutes:"; cin >> minutes_; show_time(hours_, minutes_); return 0; } void show_time(int a, int b) { cout << "Time: " << a << ":" << b << endl; }
相关文章推荐
- C++数组
- 函数
- stl关联容器
- getline()这个函数
- C++ Primer 5th - 2.1 基础内建类型
- C++ Primer 5th - 1.5 类
- 《C++ Primer》笔记
- 浅拷贝、深拷贝与引用计数
- Vector的简单使用
- c++语句补充
- c++基础复习之表达式
- c++基础复习之数组与指针
- 《C++primer》第二章--变量和基本内置类型
- 复制控制
- C++中cin如何输入字符串
- 读书笔记(四)---C++ Primer
- ~第七章:类型与语句
- C++调用webservice
- C++ Primer 学习笔记(持续更新......)
- C++ Primer 总结之Chap7 Functions