当前位置:文档之家› c primerplus(第六版)课后编程练习答案

c primerplus(第六版)课后编程练习答案

c  primerplus(第六版)课后编程练习答案
c  primerplus(第六版)课后编程练习答案

第二章:开始学习C++

//ex2.1--display your name and address

#include

int main(void)

{

using namespace std;

cout<<"My name is liao chunguang and I live in hunan chenzhou.\n”;}

//ex2.2--convert the furlong units to yard uints-把浪单位换位码单位

#include

double fur2yd(double);

int main()

{

using namespace std;

cout<<"enter the distance measured by furlong units:";

double fur;

cin>>fur;

cout<<"convert the furlong to yard"<

double yd;

yd=fur2yd(fur);

cout<

return 0;

}

double fur2yd(double t)

{

return 220*t;

}

//ex2.3-每个函数都被调用两次

#include

void mice();

void see();

using namespace std;

int main()

{

mice();

mice();

see();

see();

return 0;

}

void mice()

{

cout<<"three blind mice"<

}

void see()

{

cout<<"see how they run"<

}

//ex2.4

#include

int main()

{

using namespace std;

cout<<"Enter your age:";

int age;

cin>>age;

int month;

month=age*12;

cout<

return 0;

}

//ex2.5---convert the Celsius valve to Fahrenheit value

#include

double C2F(double);

int main()

{

using namespace std;

cout<<"please enter a Celsius value:";

double C;

cin>>C;

double F;

F=C2F(C);

cout<

}

double C2F(double t)

{

return 1.8*t+32;

}

//ex2.6---convert the light years valve to astronomical units--把光年转换为天文单位#include

double convert(double);//函数原型

int main()

{

using namespace std;

cout<<"Enter the number of light years:";

double light_years;

cin>>light_years;

double astro_units;

astro_units=convert(light_years);

cout<

}

double convert(double t)

{

return 63240*t;//1 光年=63240 天文单位

}

//ex2.7--显示用户输入的小时数和分钟数

#include

void show();

main()

{

using namespace std;

show();

return 0;

}

void show()

{

using namespace std;

int h,m;

cout<<"enter the number of hours:";

cin>>h;

cout<<"enter the number of minutes:";

cin>>m;

cout<<"Time:"<

}

第三章:处理数据

//ex3.1—将身高用英尺(feet)和英寸(inch)表示

#include

const int inch_per_feet=12;// const常量--1feet=12inches--1英尺=12英寸

int main()

{

using namespace std;

cout<<"please enter your height in inches:___\b\b\b";// \b表示为退格字符int ht_inch;

cin>>ht_inch;

int ht_feet=ht_inch/inch_per_feet;//取商

int rm_inch=ht_inch%inch_per_feet;//取余

cout<<"your height is "<

<

return 0;

}

//ex3.2--计算相应的body mass index(体重指数)

#include

const int inch_per_feet=12;

const double meter_per_inch=0.0254;

const double pound_per_kilogram=2.2;

int main()

{

using namespace std;

cout<<"Please enter your height:"<

cout<<"First,enter your height of feet part(输入你身高的英尺部分):_\b";

int ht_feet;

cin>>ht_feet;

cout<<"Second,enter your height of inch part(输入你身高的英寸部分):_\b";

int ht_inch;

cin>>ht_inch;

cout<<"Now,please enter your weight in pound:___\b\b\b";

double wt_pound;

cin>>wt_pound;

int inch;

inch=ht_feet*inch_per_feet+ht_inch;

double ht_meter;

ht_meter=inch*meter_per_inch;

double wt_kilogram;

wt_kilogram=wt_pound/pound_per_kilogram;

cout<

cout<<"Your pensonal body information as follows:"<

cout<<"身高:"<

<<"体重:"<

double BMI;

BMI=wt_kilogram/(ht_meter*ht_meter);

cout<<"your Body Mass Index(体重指数) is "<

return 0;

}

//ex3.3 以度,分,秒输入,以度输出

#include

const int minutes_per_degree=60;

const int seconds_per_minute=60;

int main()

{

using namespace std;

cout<<"Enter a latitude in degrees,minutes,and seconds:\n";

cout<<"First,enter the degrees:";

int degree;

cin>>degree;

cout<<"Next,enter the minutes of arc:";

int minute;

cin>>minute;

cout<<"Fianlly,enter the seconds of arc:";

int second;

cin>>second;

double show_in_degree;

show_in_degree=(double)degree+(double)minute/minutes_per_degree+(double)second/mi nutes_per_degree/seconds_per_minute;

cout<

return 0;

}

//ex3.4

#include

const int hours_per_day=24;

const int minutes_per_hour=60;

const int seconds_per_minute=60;

int main()

{

using namespace std;

cout<<"Enter the number of seconds:";

long seconds;

cin>>seconds;

int Day,Hour,Minute,Second;

Day=seconds/seconds_per_minute/minutes_per_hour/hours_per_day;

Hour=seconds/seconds_per_minute/minutes_per_hour%hours_per_day;

Minute=seconds/seconds_per_minute%minutes_per_hour;

Second=seconds%seconds_per_minute;

cout<

return 0;

}

//ex3.5

#include

int main()

{

using namespace std;

cout<<"Enter the world population:";

long long world_population;

cin>>world_population;

cout<<"Enter the population of the US:";

long long US_population;

cin>>US_population;

double percentage;

percentage=(double)US_population/world_population*100;

cout<<"The population of the US is "<

return 0;

}

//ex3.6 汽车耗油量-美国(mpg)or欧洲风格(L/100Km)

#include

int main()

{

using namespace std;

cout<<"Enter the miles of distance you have driven:";

double m_distance;

cin>>m_distance;

cout<<"Enter the gallons of gasoline you have used:";

double m_gasoline;

cin>>m_gasoline;

cout<<"Your car can run "<

cout<<"Computing by European style:\n";

cout<<"Enter the distance in kilometers:";

double k_distance;

cin>>k_distance;

cout<<"Enter the petrol in liters:";

double k_gasoline;

cin>>k_gasoline;

cout<<"In European style:"<<"your can used "<<100*k_gasoline/k_distance<<" liters of petrol per 100 kilometers\n";

return 0;

}

//ex3.7 automobile gasoline consumption-耗油量--欧洲风格(L/100Km)转换成美国风格(mpg) #include

int main()

{

using namespace std;

cout<<"Enter the automobile gasoline consumption figure in\n"

<<"European style(liters per 100 kilometers):";

double Euro_style;

cin>>Euro_style;

cout<<"Converts to U.S. style(miles per gallon):"<

cout<

return 0;

}

// Note that 100 kilometers is 62.14 miles, and 1 gallon is 3.875 liters.

//Thus, 19 mpg is about 12.4 L/100Km, and 27 mpg is about 8.7 L/100Km.

Enter the automobile gasoline consumption figure in

European style(liters per 100 kilometers):12.4

Converts to U.S. style(miles per gallon):

12.4 L/100Km = 19.4187 mpg

Press any key to continue

// ex3.7 automobile gasoline consumption-耗油量--美国风格(mpg)转换成欧洲风格(L/100Km) #include

int main()

{

using namespace std;

cout<<"Enter the automobile gasoline consumption figure in\n"

<<"U.S. style(miles per gallon):";

double US_style;

cin>>US_style;

cout<<"Converts to European style(miles per gallon):"<

cout<

return 0;

}

// Enter the automobile gasoline consumption figure in

U.S. style(miles per gallon):19

Converts to European style(miles per gallon):

19 mpg = 12.6733L/100Km

Press any key to continue

第四章复合类型

//ex4.1 display the information of student

#include

const int Asize=20;

using namespace std;

struct student//定义结构描述

{

char firstname[Asize];

char lastname[Asize];

char grade;

int age;

};

void display(student);//函数原型放在结构描述后

int main()

{

cout<<"what is your first name?"<

student lcg;//创建结构变量(结构数据对象)

cin.getline(lcg.firstname,Asize);

cout<<"what is your last name?"<

cin.getline(https://www.doczj.com/doc/d26139100.html,stname,Asize);

cout<<"what letter grade do you deserve?"<

cin>>lcg.grade;

cout<<"what is your age?"<

cin>>lcg.age;

display(lcg);

return 0;

}

void display(student name)

{

cout<<"Name: "<

cout<<"Grade:"<

cout<<"Age:"<

}

//ex4.2 use the string-class instead of char-array

#include

#include

int main()

{

using namespace std;

string name,dessert;

cout<<"Enter your name: \n";

getline(cin,name);

cout<<"Enter your favorite dessert: \n";

getline(cin,dessert);

cout<<"I have some delicious "<

cout<<" for you, "<

return 0;

}

//有时候会遇到需要按下两次回车键才能正确的显示结果,这是vc++6.0的一个BUG,更改如下:else if (_Tr::eq((_E)_C, _D))

{_Chg = true;

_I.rdbuf()->sbumpc();//修改后的

break; }

ex4.3 输入其名和姓,并组合显示

#include

#include

const int Asize=20;

int main()

{

using namespace std;

char fname[Asize];

char lname[Asize];

char fullname[2*Asize+1];

cout<<"Enter your first name:";//输入名字,存储在fname[]数组中

cin.getline(fname,Asize);

cout<<"Enter your last name:";//输入姓,存储在lname[]数组中

cin.getline(lname,Asize);

strncpy(fullname,lname,Asize);//把姓lname复制到fullname空数组中

strcat(fullname,", ");//把“,”附加到上述fullname尾部

strncat(fullname,fname,Asize);//把fname名字附加到上述fullname尾部

fullname[2*Asize]='\0';//为防止字符型数组溢出,在数组结尾添加结束符

cout<<"Here's the information in a single string:"<

return 0;

}

//ex4.4 使用string对象存储、显示组合结果

#include

#include

int main()

{

using namespace std;

string fname,lname,attach,fullname;

cout<<"Enter your first name:";

getline(cin,fname);//note:将一行输入读取到string类对象中使用的是getline(cin,str)

//它没有使用句点表示法,所以不是类方法cout<<"Enter your last name:";

getline(cin,lname);

attach=", ";

fullname=lname+attach+fname;

cout<<"Here's the information in a single string:"<

return 0;

}

//ex4.5 declare a struct and initialize it 声明结果并创建一个变量

#include

const int Asize=20;

struct CandyBar

{

char brand[Asize];

double weight;

int calory;

};

int main()

{

using namespace std;

CandyBar snack={"Mocha Munch",2.3,350};

cout<<"Here's the information of snack:\n";

cout<<"brand:"<

cout<<"weight:"<

cout<<"calory:"<

return 0;

}

//ex4.6 结构数组的声明及初始化

#include

const int Asize=20;

struct CandyBar

{

char brand[Asize];

double weight;

int calory;

};

int main()

{

using namespace std;

CandyBar snack[3]={

{"Mocha Munch",2.3,350},

{"XuFuJi",1.1,300},

{"Alps",0.4,100}

};

for(int i=0;i<3;i++)//利用for循环来显示snack变量的内容{

cout<

<

<

}

return 0;

}

//ex4.7 pizza披萨饼

#include

#include

const int Size=20;

struct pizza//声明结构

{

char company[Size];

double diameter;

double weight;

};

int main()

{

using namespace std;

pizza pie;//创建一个名为pie的结构变量

cout<<"What's the name of pizza company:";

cin.getline(https://www.doczj.com/doc/d26139100.html,pany,Size);

cout<<"What's the diameter of pizza:";

cin>>pie.diameter;

cout<<"What's the weight of pizza:";

cin>>pie.weight;

cout<<"company:"<

cout<<"diameter:"<

cout<<"weight:"<

return 0;

}

//ex4.8 pizza pie 披萨饼使用new创建动态结构

#include

#include

const int Size=20;

struct pizza//声明结构

{

char company[Size];

double diameter;

double weight;

};

int main()

{

using namespace std;

pizza *pie=new pizza;//使用new创建动态结构

cout<<"What's the diameter of pizza:";

cin>>pie->diameter;

cin.get();//读取下一个字符

cout<<"What's the name of pizza company:";

cin.get(pie->company,Size);

cout<<"What's the weight of pizza:";

cin>>pie->weight;

cout<<"diameter:"<diameter<<" inches"<

cout<<"company:"<company<

cout<<"weight:"<weight<<" ounches"<

delete pie;//delete释放内存

return 0;

}

//ex.4.9 使用new动态分配数组—方法1

#include

#include

using namespace std;

struct CandyBar

{

string brand;

double weight;

int calory;

};

int main()

{

CandyBar *snack= new CandyBar[3];

snack[0].brand="A";//单个初始化由new动态分配的内存snack[0].weight=1.1;

snack[0].calory=200;

snack[1].brand="B";

snack[1].weight=2.2;

snack[1].calory=400;

snack[2].brand="C";

snack[2].weight=4.4;

snack[2].calory=500;

for(int i=0;i<3;i++)

{

cout << " brand: " << snack[i].brand << endl;

cout << " weight: " << snack[i].weight << endl;

cout << " calorie: " << snack[i].calory << endl<

}

delete [] snack;

return 0;

}

//ex.4.10 数组—方法1

#include

int main()

{

using namespace std;

const int Size = 3;

int success[Size];

cout<<"Enter your success of the three times 40 meters running:\n";

cin >> success[0]>>success[1]>>success[2];

cout<<"success1:"<

cout<<"success2:"<

cout<<"success3:"<

double average=(success[0]+success[1]+success[2])/3;

cout<<"average:"<

return 0;

}

//ex.4.10 array—方法2

#include

#include

int main()

{

using namespace std;

arrayad={0};

cout<<"Enter your success of the three times 40 meters running:\n";

cin >> ad[0]>>ad[1]>>ad[2];

cout<<"success1:"<

cout<<"success2:"<

cout<<"success3:"<

ad[3]=(ad[0]+ad[1]+ad[2])/3;

cout<<"average:"<

return 0;

}

第五章循环和关系表达式

//ex.5.1

#include

int main()

{

using namespace std;

cout<<"Please enter two integers: ";

int num1,num2;

cin>>num1>>num2;

int sum=0;

for(int temp=num1;temp<=num2;++temp)//or temp++

sum+=temp;

cout<<"The sum from "<

}

//ex.5.2

#include

#include

int main()

{

using namespace std;

arrayad={0};

ad[1]=ad[0]=1L;

for(int i=2;i<101;i++)

ad[i]=i*ad[i-1];

for(int i=0;i<101;i++)

cout<

return 0;

}

//ex.5.3

#include

int main()

{

using namespace std;

cout<<"Please enter an integer: ";

int sum=0,num;

while((cin>>num)&&num!=0)

{

sum+=num;

cout<<"So far, the sum is "<

cout<<"Please enter an integer: ";

}

return 0;

}

//ex.5.4

#include

int main()

{

using namespace std;

double sum1,sum2;

sum1=sum2=0.0;

int year=0;

while(sum2<=sum1)

{

++year;

sum1+=10;

sum2=(100+sum2)*0.05+sum2;

}

cout<<"经过"<

cout<<"此时,Cleo的投资价值为"<

return 0;

}

//ex.5.5

#include

const int MONTHS = 12;

const char* months[MONTHS]={"January","February","March","April","May","June","July","August","Sept ember","October","November","December"};

int main()

{

using namespace std;

int sales[MONTHS],sum=0;

for(int i=0;i

{

cout<<"请输入在"<

cin>>sales[i];

sum+=sales[i];

}

cout<<"这一年中的C++ For Fools的总销售量为:"<

return 0;

}

//ex.5.6

#include

const int MONTHS = 12;

const char* months[MONTHS]={"January","February","March","April","May","June","July","August","Sept ember","October","November","December"};

const char* years[3]={"第一年","第二年","第三年"};

int main()

{

using namespace std;

int year_sale[3],sum=0,sales[3][MONTHS];

for(int i=0;i<3;i++)

{

int temp=0;

cout<

for(int j=0;j

{

cout<<"请输入"<

cin>>sales[i][j];

temp+=sales[i][j];

}

year_sale[i]=temp;

sum+=year_sale[i];

}

for(int i=0;i<3;i++)

cout<

return 0;

}

//ex.5.7

#include

#include

using namespace std;

struct car{

string name;

int year;

};

int main()

{

cout<<"How many cars do you wish to catalog? ";

int num;

(cin>>num).get();

car* ps=new car[num];

for(int i=0;i

{

cout<<"Car #"<

cout<<"Please enter the make: ";

getline(cin,ps[i].name);

cout<<"Please enter the year made: ";

(cin>>ps[i].year).get();

}

cout<<"Here is your collection:\n";

for(int i=0;i

cout<

delete [] ps;

return 0;

}

//ex.5.8

#include

#include

int main()

{

using namespace std;

char word[20];

int sum=0;

cout<<"Enter words (to stop,type the word done):\n"; cin>>word;

while(strcmp(word,"done"))

{

sum++;

cin>>word;

}

cout<<"You entered a total of "<

return 0;

}

//ex.5.9

#include

#include

int main()

{

using namespace std;

string word;

int sum=0;

cout<<"Enter words (to stop, type the word done):\n"; cin>>word;

while(word!="done")

{

sum++;

cin>>word;

}

cout<<"You entered a total of "<

return 0;

}

//ex.5.10

#include

int main()

{

using namespace std;

cout<<"Enter number of rows:";

int num;

cin>>num;

for(int i=0;i

{

for(int j=num-i;j>1;j--) cout<<".";

for(int k=0;k<=i;++k)

cout<<"*";

cout<

}

return 0;

}

C语言程序设计第三版习题库答案

C 语言程序设计(第三版)习题库 1、设圆半径r=,圆柱高h=3,求圆周长、圆面积、圆球表面积、圆球体积、圆柱体积。用scanf 输入数据,输出计算结果,输出时要求文字说明,取小数点后两位数字。请编程序。 #include<> main(){ floatr,h,C1,Sa,Sb,Va,Vb; scanf(__”%f ”__,&r); scanf(”%d ”,__&h _);; C1=2**r; Sa=*r*r; Sb=4*Sa; Va=4**r*r*r/3; Vb=Sa*h; printf(___”Cl=%.2fSa=%.2fSb=%.2fVa=%.2fVb=%.2f ”,Cl,Sa,Sb,Va,Vb ); } 2、输入一个华氏温度,要求输出摄氏温度。公式为c=5(F-32)/9 输出要求有文字说明,取位2小数。 #include<> main(){ floatF,c; scanf("%f",&F); ____c=5*(F-32)/9______; printf("c=%.2f",c); } 3、有一函数:?? ???≥-<≤-<=10113101121x x x x x x y 写一程序,输入x 值,输出y 值。 #include<> main(){ intx,y; printf("输入x :"); scanf("%d",&x); if(x<1){/*x<1*/ y=x; printf("x=%3d,y=x=%d\n",x,y);

}elseif(____x<10_______){/*1≤x-10*/ _____y=2*x-1_______; printf("x=%3d,y=2*x-1=%d\n",x,y); }else{/*x≥10*/ y=3*x-11; printf("x=%3d,y=3*x-11=%d\n",x#include"" main() { intx,y; scanf("%d",&x); if(x<1) {y=x;} elseif(x>=1&&x<10) {y=2*x-1;} else {y=3*x-11;} printf("%d",y); }#include"" main() { intx,y; scanf("%d",&x); if(x<1) {y=x;} elseif(x>=1&&x<10) {y=2*x-1;} else {y=3*x-11;} printf("%d\n",y); }#include"" main() { intx,y; scanf("%d",&x); if(x<1) {y=x;} elseif(x>=1&&x<10) {y=2*x-1;} else {y=3*x-11;} printf("%d",y); }scanf("%d",&x);

C++程序设计基础课后答案 第八章

8.1 阅读下列程序,写出执行结果 1.#include class Bclass { public: Bclass( int i, int j ) { x = i; y = j; } virtual int fun() { return 0 ; } protected: int x, y ; }; class Iclass:public Bclass { public : Iclass(int i, int j, int k):Bclass(i, j) { z = k; } int fun() { return ( x + y + z ) / 3; } private : int z ; }; void main() { Iclass obj( 2, 4, 10 ); Bclass p1 = obj; cout << p1.fun() << endl; Bclass & p2 = obj ; cout << p2.fun() << endl; cout << p2.Bclass :: fun() << endl; Bclass *p3 = &obj;

cout << p3 -> fun() << endl; } 2.#include class Base { public: virtual void getxy( int i,int j = 0 ) { x = i; y = j; } virtual void fun() = 0 ; protected: int x , y; }; class A: public Base { public: void fun() { cout<<"x = "<。C语言中没有数据的输入、输出等功能,数据的输入、输出都是通过调用系统提供的库函数scanf和printf等来实现的。这些函数的说明都包括在stdio.h文件中。 ②main是主函数的名称。用{}括起来的内容是函数体,函数体由若干条语句组成,这是计算机要执行的部分,每条语句以分号“;”结束。 ③注意显示的信息有三行,所以要用到换行符“\n”。 参考代码: #include main() { printf("************************\n"); printf(" I love C programs! \n"); printf("************************\n"); }

Java程序设计基础习题答案

Java程序设计基础课后习题参考答案 第2章 1、关于Java Application得入口方法main()得检验: main()方法得参数名就是否可以改变? main()方法得参数个数就是否可以改变? 该方法名就是否可以改变? 参考答案:(1)main()方法得参数名可以改变.(2)main()方法得参数个数不可以改变。(3)该方法名不可以改变。 2、当一个程序没有main()方法时,能编译吗?如果能编译,能运行吗? 参考答案:当一个程序没有main()方法就是,就是可以编译通过得,但就是不能给运行,因为找不到一个主函数入口。 3、下列语句能否编译通过? bytei =127; bytej = 128; longl1 = 999999; long l2= 9999999999; 参考答案:byte i 与long l1可以编译通过。而byte j 与longl2 超出自身数据类型范围,所以编译失败。 4、下列语句能否编译通过? float f1 =3、5; float f2 = 3.5f; 参考答案:java中浮点型得数据在不声明得情况下都就是double型得,如果要表示一个数据就是float型得,必须在数据后面加上“F”或“f”;因此,floatf1 无法编译通过。 5、验证int 与char,int与double等类型就是否可以相互转换。 参考答案:(1)char类型可以转换为int 类型得,但就是int类型无法转换为char类型得;(2)int 可以转换为double类型得,但就是double类型无法转换为int 类型得。 6、计算下列表达式,注意观察运算符优先级规则。若有表达式就是非法表达式,则指出不合法之处且进行解释。 (1)4+5 == 6*2 ?(2) (4=5)/6?? (3)9%2*7/3>17(4)(4+5)<=6/3 ? (5) 4+5%3!=7-2????(6)4+5/6〉=10%2 参考答案:表达式(2)为不合法表达式,只能将值赋值给一个变量,因此其中(4=5)将5赋值给4就是不合法得. 7、下列()就是合法得Java标识符。 (1)Counter1 ??(2)$index, (3) name-7 ??(4)_byte

程序设计基础试题_03_答案.doc

学院领导 审批并签名 A / B卷 广州大学 学年第学期考试卷 课程高级语言程序设计考试形式(开/闭卷,考试/查)学院系专业班级学号姓名 分数 评分 一:选择题(每题3分,共60分) (1)若有以下定义: char a; int b; float c; double d; 则表达式a*b+d-c值的类型为(A)

A) double B) float C) int D) char (2)设a=1,b=2,c=3,d=4,则表达式:a=10 or a<=0 B)a>=10│a<=0 C)a>=10││a<=0 D)a>=10 ││ a<=0 (7)下列可 作为C语言赋值语句的是(C) A) x=3,y=5 B) a=b=6 C) i--; D) y=int(x); (8)设i是int型变量,f是float型变量,用下面的语句给这两个变量输 入值: scanf(i=%d,f=%f,&i,&f); 为了把100和765.12分别赋给i和f,则正确的输入为(A) A) 100765.12 B) i=100,f=765.12 C) 100765.12 D) x=100y=765.12 (9)给出以下定义: char x[ ]=abcdefg;

程序设计基础练习题(全答案版)

《程序设计基础——C#.NET》练习 参考答案: 一、选择题 https://www.doczj.com/doc/d26139100.html,的目的就是将____A____作为新一代操作系统的基础,对互联网的设计思想进行扩展。A.互联网 B. Windows C. C# D. 网络操作系统 2.假设变量x的值为10,要输出x值,下列正确的语句是__C__。 A.System.Console.writeline(“x”) B. System.Cosole.WriteLine(“x”) C. System.Console.WriteLine(“x={0}”,x) D. System.Console.WriteLine(“x={x}”) 3.要退出应用程序的执行,应执行下列的_A___语句。 A. Application.Exit(); B. Application.Exit; C. Application.Close(); D. Application.Close; 4.关于C#程序的书写,下列不正确的说法是__D________。 A.区分大小写 B.一行可以写多条语句 C.一条语句可以写成多行 D.一个类中只能有一个Main()方法,因此多个类中可以有多个Main()方法 5. 在C#语言中,下列能够作为变量名的是__C__。 A.if B. 3ab C. b_3a D. a-bc 7. 能正确表示逻辑关系“a≥5或a≤0”的C#语言表达方式是__D__。 A.a>=5 or a<=0 B. a>=5|a<=0 C. a>=5&&a<=0 D. a>=5||a<=0 8. 以下程序的输出结果是___C_____。 A. 5 B. 4 C. 6 D. 不确定 9. If语句后面的表达式应该是__A___。 A.逻辑表达式 B. 条件表达式 C. 算术表达式 D. 任意表达式10.有如下程序:

(完整版)C语言程序设计练习及答案

《C语言程序设计》练习及答案 得分评卷人复查人 一、单选题,每小题1分,共60分(将正确答案的序号写在题目的括号中)。 1、结构化程序设计的三种基本控制结构是(D )。 A、主程序、子程序、函数 B、输入、处理、输出 C、调用,返回,转移 D、顺序、选择、循环 2、下列关于C程序变量的叙述, ( D )是错误的。 A、变量名必须由字母或下划线开头。 B、程序中的变量必须在被使用之前定义。 C、不同的基本类型的变量之间可以混合运算。 D、变量的数据类型决定变量的"作用域"。 3、能将C语言编写的源程序转换为目标程序的软件是(C )。 A、编辑程序 B、汇编程序 C、编译程序 D、解释程序 4、以下符号中,合法的用户标识符是( D )。 A、-p B、int C、3ab D、_xt_ 5、以下选项中,与m=n++完全等价的表达式是( C )。 A、m=++n B、m+=n+1 C、m=n, n=n+1 D、n=n+1,m=n 6、若有定义:int aa[8];。则以下表达式中不能代表数组元aa[1]的地址的是(C )。 A、&aa[0]+1 B、&aa[1] C、&aa[0]++ D、aa+1 7、表达式!5&(7+3)&&(4+5)的值是(A)。 A、0 B、1 C、5 D、9 8、以下选项中非法的C语言表达式是(A )。 A、x+1=x+1 B、0<=x<100 C、i=j==0 D、(char)(65+3) 9、在TURBO C中, int类型变量所占字节数是(B )。 A、1 B、2 C、4 D、8 10、C语言中基本的数据类型包括(B)。 A、整型,实型,逻辑型 B、整型,实型,字符型

计算机程序设计基础习题册含答案

《计算机程序设计基础》 计算机程序设 计基础_基础知识(一) 班级 学号 姓名 成 绩 一、 单选题 习题册

1.C++源程序文件的默认扩展名为A。 2.A) cpp B) exe C) obj D) lik 3.由C++源程序文件编译而成的目标文件的默认扩展名为C。 4.A) cpp B) exe C) obj D) lik 5.由C++目标文件连接而成的可执行文件的默认扩展名为B。 6.A) cpp B) exe C) obj D) lik 7.编写C++程序一般需经过的几个步骤依次是B。 8.A)编译、编辑、连接、调试 B)编辑、编译、连接、调试 C)编译、调试、编辑、连接 D)编辑、调试、编辑、连接9.程序中主函数的名字为 A 。 10.A) main B) MAIN C) Main D) 任意标识 符 11.下面四个选项中,均是不合法的 用户标识符的选项的是 C。 12.A) A p_o do B)float lao _A C)b-a goto int D)_123 temp INT 13.下列变量名中合法的是 C。 14.A) B)C)Tom B) 3a66 C) _6a7b D) $ABC 15.存储以下数据,占用存储字节最 多的是 D 。 16.A) 0 B) ‘0’

C) “0” D) 17.在C++语言中,字符型数据在内存中的存储形式是D。 18.A) 补码 B) 反码 C) 原码 D) ASCII码 19.若有说明语句:char c =’\072’;则变量c A。 20.A) 包含1个字符 B) 包含2个字符 C) 包含3个字符 D) 说明不合法,变量的值不确定 二、填空题 1.C++头文件和源程序文件的扩展名分别为.h和.cpp 。 2.C++语言规定,标识符只能由字母、数字、下划线三种字符组成,而且第一个字符必须是字母或下划线。 3.一条表达式语句必须以__分号_;___作为结束符。 4.用于从键盘上为变量输入值的标准输入流对象是___cin____;用于输出表达式值的标准输出流对象是__cout____。 5.在一个C++程序文件中,若要包含另外一个头文件或程序文件,则应使用以_#include___标识符开始的预处理命令 计算机程序设计基础_基础知识(二) 班级学号姓名成绩 一、单选题 1.下列哪一个是C++语言中合法的变量 C A) 8ZSe B) ±A0 C) X0_2 D) ’x0’2.已知ch是字符型变量,下面不正确的赋值语句是A 3.A) ch='a+b' B) ch='\0'

C语言程序设计第二版习题参考答案

C语言程序设计第二版 习题参考答案 Document serial number【LGGKGB-LGG98YT-LGGT8CB-LGUT-

C语言程序设计习题参考答案 习题 1 一、判断题 1.在计算机中,小数点和正负号都有专用部件来保存和表示。 2.二进制是由0和1两个数字组成的进制方式。 3.二进制数的逻辑运算是按位进行的,位与位之间没有进位和借位的关系。 4.在整数的二进制表示方法中,0的原码、反码都有两种形式。 5.有符号数有三种表示法:原码、反码和补码。 6.常用字符的ASCII码值从小到大的排列规律是:空格、阿拉伯数字、大写英文字母、小写英文字母。 解:1.F2.T 3.T 4.T 5.T 6.T 二、单选题 1.在计算机中,最适合进行数值加减运算的数值编码是。 A. 原码 B. 反码 C. 补码 D. 移码 2.已知英文小写字母m的ASCII码为十进制数109,则英文小写字母y的ASCII 码为十进制数。 A. 112 B. 120 C. 121 D. 122 3.关于ASCII码,在计算机中的表示方法准确地描述是。 A. 使用8位二进制数,最右边一位为1 B. 使用8位二进制数,最左边一位为1 C. 使用8位二进制数,最右边一位为0 D. 使用8位二进制数,最左边一位为0 4.设在机器字长4位,X=0111B,Y=1011B,则下列逻辑运算中,正确的是 ___________。 A. X∧Y=1000 B. X∨Y=1111 C. X⊕Y=0011 D. ˉY=1000 5.下列叙述中正确的是()。 A.高级语言就是机器语言 B.汇编语言程序、高级语言程序都是计算机程序,但只有机器语言程序才是计算机可以直接识别并执行的程序 C.C语言因为具有汇编语言的一些特性,所以是汇编语言的一种 D.C源程序经过编译、连接,若正确,执行后就能得到正确的运行结果6.用C语言编写的源程序经过编译后,若没有产生编译错误,则系统将()。 A.生成可执行文件B.生成目标文件 C.输出运行结果D.自动保存源文件 7.下列叙述中不正确的是()。 A.main函数在C程序中必须有且只有一个 B. C程序的执行从main函数开始,所以main函数必须放在程序最前面 C. 函数可以带参数,也可以不带参数。

程序设计基础试题(附答案)

程序设计基础复习题 一、单选 1、一个完整的计算机系统应该包括() A、系统软件和应用软件 B、计算机及其外部设备 C、硬件系统和软件系统 D、系统硬件和系统软件 2、“裸机”的概念是指() A、正在进行设计还没有组装好的计算机 B、已经组装好但还没有安装任何软件的计算机 C、仅安装了操作系统的计算机系统 D、安装了文字处理软件但没有安装专用数据处理系统的计算机 3、世界上第一台电子数字计算机研制成功的时间是() A、1936年 B、1946年 C、1956年 D、1970年 4、CASE的含义是() A、计算机辅助设计 B、计算机辅助制造 C、计算机辅助教学 D、计算机辅助软件工程5、当前广泛使用的微型计算机是() A、第一代 B、第二代 C、第三代 D、第四代 6、当代计算机的体系结构称为是() A、冯·诺依曼机 B、非冯·诺依曼机 C、图灵机 D、比尔盖茨机 7、硬盘是() A、输入设备 B、输出设备 C、存储设备 D、计算设备 8、下面4句话中,最准确的表述是() A、程序=算法+数据结构 B、程序是使用编程语言实现算法 C、程序的开发方法决定算法设计 D、算法是程序设计中最关键的因素

9、计算机能直接执行的语言是() A、机器语言 B、汇编语言 C、高级语言 D、目标语言 10、解释程序的功能是() A、将高级语言程序转换为目标程序 B、将汇编语言程序转换为目标程序 C、解释执行高级语言程序 D、解释执行汇编语言程序 11、下面4种程序设计语言中,不是面向对象式语言的是() A、JAVA B、Object Pascal C、Delphi D、C 12、不是C语言的基本数据类型是() A、int B、double C、char D、bool 13、在C语言中,为了求两个整数相除之后得到的余数,可以使用运算符() A、/ B、% C、* D、++ 14、数据的逻辑结构分为() A、纯属结构和非线性结构 B、顺序结构和非顺序结构 C、树型结构和图型结构 D、链式结构和顺序结构 15、用链表表示纯属表的优点是() A、便于随机存取 B、便于插入和删除操作 C、花费的存储空间较顺序存储少 D、元素的物理顺序与逻辑顺序相同 16、栈的最主要特点是() A、先进先出 B、先进后出 C、两端进出 D、一端进一端出 17、下面4句结论只有一句是错误的,它是()

Visual Basic 程序设计基础教程-课后习题答案-范荣强

第一章程序与编程环境 一、填空题 1. 工程,Form_Load 2. 事件(触发) 3. 窗体,Name 4. CurrentX, CurrentY 5. maxButton, BorderStyle = 1 or 3 or 4 or 5 6. Alignment, 空缺,AutoSize 7. Style, LoadPicture 8. Line, Shape 9. 重画10. FillStyle ll. MultiLine, maxLength, Locked 12. Font 13. sub, 对象名,事件名14. 方法,Object.Method, text1.setfocus() 15. Name, minButtom, CurrentX(Y), Caption 16. Interval, Enable 17. timer, Interval, ms(毫秒) 18. Mouse Down, Click, LoastFocus 19. .Frm, .Frx, .bas. cls. Vbp 20. 注释, “Rem 语句”或者“’语句” 第二章数据的类型、表示以及运算 一、请指出下列哪些是VB的合法常量,并说明原因 (1)√(2)X 常量不能加类型说明符号改成123.4 (3)X与上题类似,如果是常量,则类型说明符放在后面(4)√等价于2E3 (5) √(6)√等于十进制的4113 (7)X 如果是16进制要写&符号(8)X 指数不能为小数(9)X 月份超过12,日超过31 (10)√(11)√(12)√等价于上一题(13)X 8进制数每一位不能超过8 (14)√(15)X 变量,常量要为基本数据类型的值(16)√ 二、找出合法变量 (1)√(2)√如果与控件Label1同在一个应用程序里面,该变量会屏蔽掉控件Label1 (3) X 保留字(4)√(5)X 变量不能以数字开头(6)变量不能有小数点 (7)√(8)√数组变量(9)X保留字(10)√可以,但rnd()不可以,rnd()是函数 (11) √(12)√(13)√(14)X ’符号表示注释(15)X 这是表达式,不是变量(16)X 同上,是表达式 三、指出下列数据x,y,z的声明是否正确,如果正确请指明其类型 (1)√ x--long, y—variant, z—integer (2) √ x—long, y—long, z—integer (3) √ x—double, y—double, z—integer (4) X 变量x &中间不能有空格 (5)√自动转换成字符串 (6)X 变量声明不能直接赋值 (7)√ (8)√自动转换成字符串 (9)X 常量不能把函数写上去 (10)√ 四、写出下列表达式的结果 (1)1 (2) 1 (3)false (4) ab12 (5)123 (6)出错,加法表达式中如果有一个是数值类型,则“+”表示加号,而不是字符的链接符号(7)False (8)true (9) true (10) false 默认转换成相同类型(数值),建议这里把2改成D试试 (P.S. 布尔类型TRUE = -1, FALSE = 0; 优先顺序:^(乘方)→-(求负)→*、/→\(整除)→MOD→+、-) 五、写出下列函数的结果

(完整版)程序设计基础试题_10_答案

广州大学学年第学期考试卷 课程高级语言程序设计考试形式(开/闭卷,考试/查) 学院系专业班级学号姓名 一、填空题(每空1分,共10分) 1.C源程序的基本单位是(函数)。 2.一个C源程序中至少应包含一个(main()函数)。 3.若a和b均是int型变量,且a和b的初值均为5,则计算表达式a+=b++ 后,a的值为(10 ),b的值为( 6 )。 4.若a、b和c均是int型变量,则计算表达式a=(b=4)+(c=2)后,b值为( 4 ),c 值为( 2 )。 5.表达式8.2-2/3 的计算结果是(8 )。 6.在C语言中,整数可用三种数制表示,它们分别是(十进制)、(八进制)和(十六进制)。 二、程序计算题(每小题5分,共15分) 1. # define f(a) printf(“%d”,a) main() { int i,b[]={1,2,3,5,7,9,11,13,15},*p=5+b; for(i=3;i;i--) switch(i) { case 1: case 2: f(*p++); break;

case 3: f(*(--p)); } } 2. main() { int arr_sum(int arr[],int n); int a[3][4]={1,3,5,7,9,11,13,15,17,19,21,23}; int *p,total; int (*pt)( int arr[],int n); pt=arr_sum; p=a[0]; total=(*pt)(p,12); printf(“total=%d\n”,total); } arr_sum(int arr[],int n) { int i,sum=0; for(i=0;i

相关主题
文本预览
相关文档 最新文档