首页 > 分享 > 【任务】C++自学完后写的一个小项目

【任务】C++自学完后写的一个小项目

红栈说BSP 于 2024-12-25 17:12:58 发布

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。

//main.cpp #include <iostream> #include <cstdlib> #include <cstdint> #include <string> #include<vector> #include "hypotenuse.h" using namespace std; extern float hypotenuse(float a, float b); namespace hypo { float module_1(); int module_2(); } using namespace hypo; static float hypo::module_1() { int i; int c = 45; float q[3] = { 0,0,0 }; string s = "Enter the length of the two sides of the right triangle:n"; string t = "a="; string u = "b="; string v = "Thus,the hypotenuse c="; string w = "Completed!n"; vector<float> cont(3); cout << s << t; cin >> q[0]; cout << u; cin >> q[1]; q[2] = hypotenuse(q[0], q[1]); cont[0] = q[0]; cont[1] = q[1]; cont[2] = q[2]; cout << v << q[2] << "n" << w << endl; for (i = 0; i < 3; i++) { cout << cont[i] << "n"<<endl; } return EXIT_SUCCESS; } class hypo_class { private: static string a, b, r; public: static int module_3(); }; static int hypo::module_2() { string a = "hypo"; string b = "ten"; string r = "use"; cout << a+b+r<<"n"<< endl; return EXIT_SUCCESS; } int hypo_class::module_3() { cout << "Thanks!n" << endl; return EXIT_SUCCESS; } int main() { hypo::module_1(); hypo::module_2(); hypo_class::module_3(); }

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859

//hypotenuse.cpp #include <iostream> #include "hypotenuse.h" using namespace std; float hypotenuse(float a, float b) {if (a < 0 || b < 0){abort();}return sqrtf((float)(pow(a, 2) + pow(b, 2))); } 123456789101112

// hypotenuse.h #ifndef _HYPOTENUSE_H__ #define __HYPOTENUSE_H__ #include <iostream> float hypotenuse(float a, float b); #endif 12345678

(跟着PDF自学c++,共花了6小时,边学边写,自己即兴想的一个小项目。自己调开发环境里的问题花了好久,但是我很开心,毕竟自己学,自己调环境,最后成功运行了。这种成就感相对于“跟别人学,让别人帮忙把环境配好再写代码”而言要高许多。)

相关知识

探索C++之美:玫瑰花代码项目推荐
一个可敬的队友
自动浇花系统设计.doc
C++ 学习笔记(一) 搭设环境
C++控制台渲染一朵逼真的玫瑰花
C++做的玫瑰花
c++第二次实验
影视后期/影视制作/影视特效/影视剪辑自学视频教程
字符串 (C++/CX)
常见C/C++ XML解析器比较

网址: 【任务】C++自学完后写的一个小项目 https://m.huajiangbk.com/newsview1313993.html

所属分类:花卉
上一篇: 花卉设施栽培第4章设施环境调控
下一篇: 八月瓜生长环境要求