c++primer 第二章编程练习答案】的更多相关文章

2.7.1 #include<iostream> int main() { using namespace std; ]; ]; cout << "input name :"; cin >> name; cout << "input address:"; cin >> address; cin.get(); cout << "name is " << name;…
Python编程快速上手-让繁琐工作自动化-第二章习题及其答案 1.布尔数据类型的两个值是什么?如何拼写? 答:True和False,使用大写的T和大写的F,其他字母是小写. 2.3个布尔操作符是什么? 答:and.or和not. 3.写出每个布尔操作符的真值表(也就是操作数的每种可能组合,以及操作的结果) 答:and:True and True  -> True True and False -> FalseFalse and True -> FalseFasle and False…
C++PRIMER第二章前半部分答案 哈哈哈,为什么是前半部分呢,后半部分还在学习中,重新系统性的学习c++,共同进步嘛,不多说,跟我一起来看看吧,第三章开始才是新手收割的时候,慢慢来~~ 2.1&2.2 // 1.尺寸不同也就是可表示的数据大小不同,无符号和有符号即一个是所有bit都来存储值表示数据没有符号,另一个则相反,float与double即表示精度范围不同,double更精准些 // 2.利率,本金,付款都可选用double,因为浮点数运算通常选double // 当然,学过java的…
前言 本人在通过<C语言程序设计:现代方法(第2版)>自学C语言时,发现国内并没有该书完整的课后习题答案,所以就想把自己在学习过程中所做出的答案分享出来,以供大家参考.这些答案是本人自己解答,并参考GitHub上相关的分享和Chegg.com相关资料.因为并没有权威的答案来源,所以可能会存在错误的地方,如有错误还希望大家能够帮助指出. 第二章练习题和编程题答案 练习题 2.2节 1.建立并运行由Kernighan和Ritchie编写的著名的“hello world”程序: 1 #include…
把昨天看的第二章巩固一下,做一做编程习题. 2.6: 第一天交2元罚金,以后每一天都是前一天的平方,第N天罚金将是多少? 这个题目和2.4.4-3介绍的幂运算基本一致.若按相同的递归思路分析,比那个问题要简单,因为从1次幂开始并且指数呈2^(n-1)分布,即1,2,3,4,16……所以没有对指数是奇数时的判定.实际上用循环来求要比用递归快.在不考虑溢出的前提下,解法如下: #include<iostream> using namespace std; typedef unsigned long…
第二章 :变量和基本类型 2.1 基本内置类型 C++定义了一套包含算术类型(arithmetic type)和空类型(void)在内的基本数据类型 2.1.1 算术类型 算术类型的分类: 整型(integral type,包含字符和布尔类型)和浮点型 算术类型的尺寸: 不同的机器具有不一样的尺寸,但都遵循下表的规则 解析: 1.bool类型的取值为真(true)或假(flase) 2.char的空间应当保证能存放机器基本字符集中的任意字符对应的数字值 3.其他字符类型用于确保存放机器最大扩展字…
#include<iostream> using namespace std; int main() { cout << "My name is Jiantong Chen." << endl << "I'm a student in the Xi'an University."; cin.get(); ; } #include<iostream> using namespace std; int main…
6.11.1 #include<iostream> #include<cctype> int main() { using namespace std; char ch; cin.get(ch); while (ch != '@') { if (isdigit(ch)) cout << ch; else if (isupper(ch)) { ch = tolower(ch); cout << ch; } else if (islower(ch)) { ch…
5.9.1 #include<iostream> int main() { using namespace std; ; cout << "input first interger: "; cin >> one; cout << "input second interger: "; cin >> two; for (temp = one; temp <= two; ++temp) sum += tem…
4.13.1 #include<iostream> struct students { ]; ]; char grade; int age; }; int main() { using namespace std; students student1; cout << "What is your fistname? "; cin.).get(); cout << "What is your lastname? "; cin.get…
3.7.1 #include<iostream> int main() { using namespace std; ; int height,inch,foot; cout << "please input your height __ inch\b\b\b\b\b\b\b"; cin >> height; inch = height % unit; foot = height / unit; cin.get(); cout << &q…
1 // chapter12_1_cow.h 2 3 4 #ifndef LEARN_CPP_CHAPTER12_1_COW_H 5 #define LEARN_CPP_CHAPTER12_1_COW_H 6 7 class Cow { 8 private: 9 char name_[20]; 10 char * hobby_; 11 double weight_; 12 public: 13 Cow(); 14 Cow(const char * name, const char * hobby…
最近开学,事情较多,过两天更新...…
1 // chapter10_1_account.h 2 3 #ifndef LEARN_CPP_CHAPTER10_1_ACCOUNT_H 4 #define LEARN_CPP_CHAPTER10_1_ACCOUNT_H 5 6 #include <iostream> 7 #include <string> 8 9 10 class Account { 11 private: 12 std::string name_; 13 std::string id_; 14 double…
1 // chapter09_golf.h 2 3 #ifndef LEARN_CPP_CHAPTER09_GOLF_H 4 #define LEARN_CPP_CHAPTER09_GOLF_H 5 6 #include <cstring> 7 #include <iostream> 8 9 const int Len = 40; 10 struct golf { 11 char fullname[Len]; 12 int handicap; 13 }; 14 15 void se…
1 void ch8_1_print(const std::string & str, int n = 0 ) { 2 using namespace std; 3 static int flag = 0; 4 ++ flag; 5 if (!n) 6 cout << str << endl; 7 else { 8 for (int i = flag; i; -- i) 9 cout << str << endl; 10 } 11 } 12 void…
1 double ch7_1_harmonicaverage(double a, double b) { 2 return 2 / (1 / a + 1 / b); 3 } 4 5 void ch7_1() { 6 using namespace std; 7 double a{0}, b{0}; 8 while (true) { 9 cout << "a: "; 10 cin >> a; 11 cout << "b: "; 12…
1 void ch6_1() { 2 using namespace std; 3 char ch; 4 while ((ch = cin.get()) != '@') { 5 if (isdigit(ch)) 6 continue; 7 else if (islower(ch)) 8 ch = toupper(ch); 9 else if (isupper(ch)) 10 ch = tolower(ch); 11 cout << ch; 12 } 13 } 14 15 void ch6_2(…
1 void ch5_1() { 2 using namespace std; 3 int small, big, sum{0}; 4 cout << "enter small and big: " << endl; 5 cout << "small: "; cin >> small; 6 cout << "big: "; cin >> big; 7 for (int i =…
1 void ch4_1() { 2 using namespace std; 3 string fname, lname; 4 char grade; 5 unsigned int age; 6 cout << "enter first name: "; 7 getline(cin, fname); 8 cout << "enter last name: "; 9 getline(cin, lname); 10 cout <<…
1 void ch3_1() { 2 using namespace std; 3 unsigned int factor = 12; 4 unsigned int inch, feet; 5 cout << "enter your height in inch:______\b\b\b\b\b\b"; 6 cin >> inch; 7 cout << inch / 12 << " feet and " <<…
1 void ch2_1() { 2 using namespace std; 3 cout << "xxxxxxxx" << endl; 4 } 5 6 void ch2_2() { 7 using namespace std; 8 double num; 9 cout << "please input a distance in long: "; 10 cin >> num; 11 cout << &q…
初始完成者:哈尔滨工业大学 李秋豪 许可:除2.55对应代码外(如需使用请联系randy.bryant@cs.cmu.edu),任何人可以自由的使用,修改,分发本文档的代码. 本机环境: (有一些需要在多种机器上测试的就没有试验) frank@under:~/tmp$ uname -a Linux under 4.10.0-35-generic #39~16.04.1-Ubuntu SMP Wed Sep 13 09:02:42 UTC 2017 x86_64 x86_64 x86_64 GNU…
环境:vs2017 /**编程练习2**/ */ #include<stdio.h> int main(void) { printf("张三\n"); printf("张\n三\n"); printf("张"); printf("三\n"); getchar(); ; } */ #include<stdio.h> int main(void) { printf("姓名:张三\n地址:中国\n&…
变量和基本类型之第一篇:基本内置类型和变量 一. (1) C++定义了一套包括算数类型和空类型,这些类型有:布尔类型bool,字符类型char,宽字符类型wchar_t,Unicode字符char16_t,Unicode字符char32_t,短整型short(int), 整形int,长整形long(int),长整形long long(int),单精度浮点型float,双精度浮点型double,扩展精度浮点数long double. 其中,wchar_t.char16_t.char32_t用于扩展…
2.1 程序: Celsius=eval(input("Enter a degree in Celsius:"))#输入摄氏度的值Celsiusfahrenheit =(9/5)*Celsius + 32 #定义华氏温度fahrenheitprint(Celsius,"Celsius is",fahrenheit,"Fahrenheit") 结果: Enter a degree in Celsius:4343 Celsius is 109.4 F…
第一题 设置线程块中线程数为1024效果优于设置为1023,且提升明显,不过原因未知,以后章节看看能不能回答. 第二题 参考文件sumArraysOnGPUtimer.cu,设置block=256,新建内核,使每个线程处理两个元素. 思路很简单,将数据的虚拟内存对半分为高低两块,每一内核线程同时处理两个索引区域序列相同的数据即可: # include <cuda_runtime.h> # include <stdio.h> # include <sys/time.h>…
术语表 第 2 章 变量和基本类型 地址(address): 是一个数字,根据它可以找到内存中的一个字节    别名生命(alias declaration): 为另一种类型定义一个同义词:使用 "名字 = 类型" 的格式将名字作为该类型的同义词.    算术类型(arithmetic type): 布尔值,字符,整数,浮点数等内置类型.    数组(array): 是一种数据结果,存放着一组未命名的对象,可以通过索引来访问这些对象.    auto: 是一种类型说明符,通过变量的初始…
//1.程序尽量避免依赖于实现环境的行为.比如:如果将int的尺寸看成一个确定不变的已知值,那么这样的程序就称为不可移植的. typedef int int32; //使用类似的typedef,可以有效的解决移植问题 //2.进行算术运算的时候,要注意有符号类型向无符号类型的提升 + (unsigned ; //value = 4294967295 //3.一个行如42的值被称为字面值常量,这样的值一看便知.每个字面值常量对应一种数据类型,字面值常量的形式和值决定了其数据类型. //4.泛化的转…
1.引用: 为对象起了另外一个名字,引用类型引用另外一种类型,通过将声明符写成&d的形式来定义引用类型,其中d也就是声明的变量名(声明符就是变量名). PS:1.通过图片中编译所提示的报错信息也可知,引用必须被初始化: 2.引用并非对象,相反的,它只是为一个已经存在的对象所起的另一个名字而已: 2.指针: 与引用类似,指针也实现了对其他对象的间接访问,不过,指针本身就是一个对象,允许对指针赋值与拷贝,而且在其生命周期内可以先后指向几个不同的对象(引用只能指向一个初始化的). 指针无须再定义时赋初…