• 使用海伦公式求三角形面积C++


    1. #include<iostream>
    2. #include<windows.h>
    3. #include<conio.h>
    4. #include<algorithm>
    5. #include<cmath>
    6. #include<vector>
    7. #include<stdio.h>
    8. #include<iostream>
    9. #include<string>
    10. #include<cstring>
    11. #include<windows.h>
    12. #include<conio.h>
    13. #include<cstdlib>
    14. #include<ctime>
    15. #include<fstream>
    16. using namespace std;
    17. void gotoxy(int y,int x)
    18. {
    19. COORD coord;
    20. coord.X=x;
    21. coord.Y=y;
    22. HANDLE a=GetStdHandle(STD_OUTPUT_HANDLE);
    23. SetConsoleCursorPosition(a,coord);
    24. }
    25. void bukakeqingping(){
    26. gotoxy(0,0);
    27. for (int i = 0; i < 100; i++) {
    28. cout << " " << endl;
    29. }
    30. gotoxy(0,0);
    31. }
    32. void color(int a)//打印颜色
    33. {
    34. /*亮白*/ if(a==0) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
    35. /*蓝色*/ if(a==1) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN|FOREGROUND_BLUE);
    36. /*绿色*/ if(a==2) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN);
    37. /*紫色*/ if(a==3) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_BLUE);
    38. /*红色*/ if(a==4) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED);
    39. /*黄色*/ if(a==5) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN);
    40. /*深蓝色*/ if(a==6) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_BLUE);
    41. /*土黄色or金黄色*/ if(a==7) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED|FOREGROUND_GREEN);
    42. /*灰色接近白*/ if(a==8) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
    43. }
    44. long long numberaio(string n){
    45. for (int i = 0; i < 100000; i++) {
    46. if(n[i]=='\0')
    47. {
    48. return i;
    49. }
    50. }
    51. }
    52. void coutAIO(string b,int truefalse0 = 1,bool truefalse1 = 1,bool truefalse3 = 0){
    53. int i=0,s=0;
    54. long long a=numberaio(b);
    55. while(a!=0){
    56. s=rand()%9;
    57. if(a!=0&&s==0)
    58. {
    59. color(0);
    60. cout << b[i];
    61. a--;
    62. i++;
    63. }
    64. if(a!=0&&s==1)
    65. {
    66. color(1);
    67. cout << b[i];
    68. a--;
    69. i++;
    70. }
    71. if(a!=0&&s==2)
    72. {
    73. color(2);
    74. cout << b[i];
    75. a--;
    76. i++;
    77. }
    78. if(a!=0&&s==3)
    79. {
    80. color(3);
    81. cout << b[i];
    82. a--;
    83. i++;
    84. if(truefalse0!=false){
    85. Sleep(20);
    86. }
    87. }
    88. if(a!=0&&s==4)
    89. {
    90. color(4);
    91. cout << b[i];
    92. a--;
    93. i++;
    94. }
    95. if(a!=0&&s==5)
    96. {
    97. color(5);
    98. cout << b[i];
    99. a--;
    100. i++;
    101. }
    102. if(a!=0&&s==6)
    103. {
    104. color(6);
    105. cout << b[i];
    106. a--;
    107. i++;
    108. }
    109. if(a!=0&&s==7)
    110. {
    111. color(7);
    112. cout << b[i];
    113. a--;
    114. i++;
    115. }
    116. if(a!=0&&s==8)
    117. {
    118. color(8);
    119. cout << b[i];
    120. a--;
    121. i++;
    122. }
    123. if(truefalse0 ==1){
    124. Sleep(10);
    125. }
    126. if(truefalse0 ==2){
    127. Sleep(20);
    128. }
    129. if(truefalse0 ==3){
    130. Sleep(40);
    131. }
    132. if(truefalse0 ==4){
    133. Sleep(100);
    134. }
    135. if(truefalse0 ==5){
    136. Sleep(300);
    137. }
    138. if(truefalse0 ==6){
    139. Sleep(1000);
    140. }
    141. if(truefalse0 ==100){
    142. Sleep(1);
    143. }
    144. }
    145. if(truefalse1!=false){
    146. cout << endl;
    147. }
    148. if(truefalse3!=false){
    149. getch();
    150. bukakeqingping();
    151. }
    152. }
    153. void start(int n)
    154. {
    155. int g=n;
    156. system("cls");
    157. Sleep(1000);
    158. gotoxy(0,0);
    159. for (int i=1;i<=n; i++)
    160. {
    161. for (int i=1;i<=g; i++)
    162. {
    163. coutAIO("██┃",0,0);
    164. }
    165. cout<<endl;
    166. }
    167. coutAIO("华丽!!",4);
    168. Sleep(5000);
    169. system("cls");
    170. Sleep(5000);
    171. //ksjm();
    172. //start();
    173. }
    174. void sjxjs()
    175. {
    176. color(6);
    177. gotoxy(20,40);
    178. coutAIO(" 三 角 形 面 积 计 算 ",3);
    179. gotoxy(22,40);
    180. coutAIO(" sān jiǎo xíng miàn jí jì suàn",3);
    181. Sleep(2000);
    182. gotoxy(24,40);
    183. coutAIO(" H E P P Y ",3);
    184. Sleep(200);
    185. gotoxy(26,40);
    186. coutAIO("  作者: i m X 2 G ",3);
    187. Sleep(1000);
    188. color(3);
    189. gotoxy(28,45);
    190. coutAIO(" imX2G出品,必是精品! ",3);
    191. Sleep(2000);
    192. color(2);
    193. system("cls");
    194. start(60);
    195. gotoxy(0,60);
    196. system("cls");
    197. bool xii=true;
    198. while(xii)
    199. {
    200. cout<<"\t\t\t\t\t\tv.1.0.0";
    201. gotoxy(0,0);
    202. printf(" WELCOME WELCOME \n");
    203. printf("┌──────────────────────────────────────────────────────────────────────────────────────────┐\n");
    204. printf("│ │\n");
    205. printf("│ │\n");
    206. printf("│ │\n");
    207. printf("│ │\n");
    208. printf("│ │\n");
    209. printf("│ │\n");
    210. printf("│ │\n");
    211. printf("│ │\n");
    212. printf("│ │\n");
    213. printf("│ │\n");
    214. printf("│ │\n");
    215. printf("│ │\n");
    216. printf("│ │\n");
    217. printf("│ │\n");
    218. printf("│ │\n");
    219. printf("│ │\n");
    220. printf("│ │\n");
    221. printf("│ │\n");
    222. printf("│ │\n");
    223. printf("│ │\n");
    224. printf("│卍 卐│\n");
    225. printf("│卍卍 卐卐│\n");
    226. printf("│卍卍卍 卐卐卐│\n");
    227. printf("│卍卍卍卍 卐卐卐卐│\n");
    228. printf("└──────────────────────────────────────────────────────────────────────────────────────────┘\n");
    229. double a,b,c,hcy,ans;
    230. gotoxy(2,2);
    231. coutAIO("这是一个三角面积计算器,请输入第一、二、三条边:");
    232. gotoxy(3,2);
    233. cin >> a;
    234. gotoxy(4,2);
    235. cin >> b;
    236. gotoxy(5,2);
    237. cin >> c;
    238. gotoxy(6,2);
    239. if(a+b<=c||a+c<=b||b+c<=a||a<0||b<0||c<0){
    240. bukakeqingping();
    241. color(4);
    242. cout<<"这个图形不符合三角形的成立条件!!!";
    243. Sleep(3000);
    244. bukakeqingping();
    245. goto flag;
    246. }
    247. hcy=(a+b+c)/2;
    248. ans=sqrt(hcy*(hcy-a)*(hcy-b)*(hcy-c));
    249. coutAIO("这个三角形的面积是:");
    250. gotoxy(6,8);
    251. cout << ans;
    252. flag:
    253. gotoxy(7,2);
    254. coutAIO("输入0退出,输入1继续");
    255. gotoxy(6,18);
    256. cin >> xii;
    257. bukakeqingping();
    258. }
    259. }
    260. void full_screen()
    261. {
    262. HWND hwnd = GetForegroundWindow();
    263. int cx = GetSystemMetrics(SM_CXSCREEN); /* 屏幕宽度 像素 */
    264. int cy = GetSystemMetrics(SM_CYSCREEN); /* 屏幕高度 像素 */
    265. LONG l_WinStyle = GetWindowLong(hwnd,GWL_STYLE); /* 获取窗口信息 */
    266. /* 设置窗口信息 最大化 取消标题栏及边框 */
    267. SetWindowLong(hwnd,GWL_STYLE,( l_WinStyle |WS_MAXIMIZE| WS_POPUP) & ~WS_CAPTION & ~WS_THICKFRAME & ~WS_BORDER);//
    268. SetWindowPos(hwnd, HWND_TOP, 0, 0, cx, cy, 0);
    269. }
    270. int main()
    271. {
    272. full_screen();
    273. sjxjs();
    274. gotoxy(27,2);
    275. getch();
    276. exit(0);
    277. }

  • 相关阅读:
    零基础学Java(1)初识Java程序
    Java学习笔记3.6.1 final关键字 - final修饰类
    [Vue3] pinia状态管理
    刷题分享—常见的经典面试题二
    ESP32 之 ESP-IDF 教学(十七)——组件依赖
    vue3中函数必须有返回值么?
    陪诊小程序系统平台功能模式
    云计算与大数据——Spark的安装和配置
    GLSL (2)数据类型
    21天学习挑战赛——Python正则表达式
  • 原文地址:https://blog.csdn.net/klaudius/article/details/125539396