编程环境Visual Studio 2017
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
#include <iostream> // practice 1 void p2_1(void) { std::cout << "Jimmy Chen" << std::endl; std::cout << "China, Guangdong Province, Huizhou" << std::endl; return; } // practice 2 void p2_2(void) { int ilong = 0; int iyards = 0; std::cout << "Input the distance in long:"; std::cin >> ilong; iyards = 220 * ilong; std::cout << "the distance in yards is " << iyards << std::endl; return; } // practice 3 void string1(void) { std::cout << "Three blind mice" << std::endl; return; } void string2(void) { std::cout << "See how they run" << std::endl; return; } void p2_3(void) { string1(); string1(); string2(); string2(); return; } // practice 4 void p2_4(void) { int years = 0; int months = 0; std::cout << "Enter your age:"; std::cin >> years; months = years * 12; std::cout << years << " years contain " << months << " monthes!" << std::endl; return; } // practice 5 double Celsius2Fahrenheit(double Celsius) { return (1.8 * Celsius + 32.0); } void p2_5(void) { double Celsius = 0.0; double Fahrenheit = 0.0; std::cout << "Please enter a Celsius value :"; std::cin >> Celsius; Fahrenheit = Celsius2Fahrenheit(Celsius); std::cout << Celsius << " degrees Celsius is " << Fahrenheit << " defrees Fahrenheit." << std::endl; return; } // practice 6 double LightYears2Astronomical(double LightYears) { return (LightYears * 63240); } void p2_6(void) { double lightYears = 0; double astronomical = 0; std::cout << "Enter the number of light years: "; std::cin >> lightYears; astronomical = LightYears2Astronomical(lightYears); std::cout << lightYears << " light years = " << astronomical << " astronomical units." << std::endl; return; } // practice 7 void disTime(int hours, int minutes) { std::cout << "Time: " << hours << ":" << minutes << std::endl; return; } void p2_7(void) { int hours = 0; int minutes = 0; std::cout << "Enter the number of hours: "; std::cin >> hours; std::cout << "Enter the number of minutes: "; std::cin >> minutes; disTime(hours, minutes); return; } int main(int argc, char **argv) { p2_7(); getchar(); } |
此文为博主原创文章,转载请注明出处
我是想问博主,是1.先通读,然后一章一章做课后题;2.一边做一边看。我用第二种方法,速度奇慢,效率好低啊。您有什么读技术书籍的建议呢?
如果是初学者,推荐用第二种方法。说到读技术书籍,其实也没什么特别好的建议。建议就是不能浮躁,不要想着一次就能所有知识点都了解,毕竟C++ primer plus这本书,我就读了三遍了。第一遍先了解基本的语法内容吧,之后就是写和看别人的代码,写个大半年或一年之后回来读第二遍,你会发现新世界的。
谢谢!了解了。
谢谢博主!
博主 最后一题的main函数为什么要传这两个参数进去呢?这两个参数的意思是数组吗?还有就是getchar在这里的作用是什么呢?
原题:编写一个程序,要求用户输入小时数和分钟数。在main函数中,将这两个值传递给一个void函数,后者以下面这样的格式显示这两个值.........
博主厉害了