第五周 C++实践 C++的初步知识
2016-01-29 14:58
501 查看
// 第五周项目.cpp : 定义控制台应用程序的入口点。 // //项目5.3.3:某公司工资按周发放,标准是每小时制20元,若员工周工作时间超过40小时,超出部分每小时30元。 //编程序输入一名员工一周的工作小时数,输出他的周工资 #include "stdafx.h" #include <iostream> using namespace std; int main() { int hour, salary; cout << "请输入员工工作的小时数:"; cin >> hour; if (hour <= 40) { salary = hour * 20; } else { salary = 800 + (hour - 40) * 30; } cout << "员工的工资是:" << salary << endl; return 0; } //项目5.3.2:输入3个整数,输出其中的最大值 // #include "stdafx.h" #include <iostream> using namespace std; int main() { int a[3]; int max; cout << "请输入三个正整数:"; for (int i = 0; i < 3; i++) { cin >> a[i]; } max = a[0]; for (int i = 1; i < 3; i++) { if (a[i]>=max) max = a[i]; } cout << "max = " << max << endl; return 0; } //项目5.3.1:输入两个正整数(前大后小,前小后大都可以),求出两数的正差值并输出 // #include "stdafx.h" #include <iostream> using namespace std; int main() {
int a[2]; int max,b; cout << "请输入两个正整数:"; for (int i = 0; i < 2; i++) { cin >> a[i]; } if (a[0]>a[1]) { max = a[0]; b = max - a[1]; } else { max = a[1]; b = max - a[0]; } cout << "两个正整数的正差数是:" << b << endl; return 0; }
//项目5.2.3:输入圆柱体的半径r和高h,输出圆柱体的表面积s(值直接写3.1415926) // #include "stdafx.h" #include <iostream> using namespace std; int main() { double a[2]; double r, h; long double s; cout << "请输入圆柱体的半径r和高h:"; for (int i = 0; i < 2; i++) { cin >> a[i]; } r = a[0]; h = a[1]; s = 2 * 3.1415926*r*h + 2 * r*r*3.1415926; cout << "圆柱体的表面积是:" << s << endl; return 0; } //项目5.2.2:输入两个电阻R1和R2的阻值,求它们并联后的阻值R // #include "stdafx.h" #include <iostream> using namespace std; int main() { float a[3]; float r1, r2, r; cout << "请输入两个电阻的阻值r1,r2:" << endl; for (int i = 0; i < 2; i++) { cin >> a[i]; } r1 = a[0]; r2 = a[1]; r = 1 / (1 / r1 + 1 / r2); cout << "并联后的阻值是:" << r << endl; return 0; } //项目5.2.1:输入长方形的两边长a和b,输出长方形的周长和面积 // #include "stdafx.h" #include <iostream> using namespace std; int main() { int a[3]; cout << "请输入长方形的两边长a,b:"; for (int i = 0; i < 2; i++) { cin >> a[i]; } a[2] = a[0] + a[1]; cout << "长方形的周长是:" << 2 * a[0] + 2 * a[1] << endl; cout << "长方形的面积是:" << a[0] * a[1] << endl; return 0; } //5.1:“捣乱”制造些错误,对此进行观察 // #include "stdafx.h" #include <iostream> using namespace std; int main() { int a, b, sum; cout << "请输入a,b的值:"; cin >> a >> b; cout << endl; sum = a + b; cout << "a+b = " << sum << endl; return 0; }
相关文章推荐
- 浮点数在内存中的存储
- C语言学习小记
- jpeg2000(j2k)图像编码解码:c++实现openjpeg内存流接口(memory stream)
- C++ 检测内存泄露工具 -- Windows平台
- [C++]exit & abort & 析构 & 异常
- 中兴通讯C++/C笔试题及答案
- 自定义内存池(C++需要掌握)
- VS2013编译libjpeg库
- C++ 宏定义与常量
- C语言宏中"#"和"##"的用法
- USACO Greedy Gift Givers 解题日志
- C语言中的回调
- C++基本概念——常用基本内置类型
- 数组、字符串长度的计算
- 【C语言复习(六)】隐式类型转换相关分析
- Visual Studio 2015下载、安装及使用(C、C++)指南
- c++内存池
- leetcode刷题系列C++-Search in Rotated Sorted Array II
- socket编程之C语言一个简单监听程序
- c++随机数