您的位置:首页 > 编程语言 > C语言/C++

C++ Primer Plus 第六版_编程练习(1)(Chapter_two 1-7)

2016-06-24 22:01 676 查看
编程工具用得好,搞起研究事半功倍。导师的意见是,学好C++,其他编程都不怕。暂时没有迫切的实战需要,于是决定从最基础的学起,挑了《C++ Primer Plus (第六版)》这本书,开始啃吧。编程练习还是一定要做的,每天一点,记在这里。

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++-Primer