面向对象软件工程 第二章 答案
软件工程思考题答案
第一章根本概念1.软件的特点是什么?软件的定义:软件=程序+数据+文档软件的特点:1)软件是逻辑实体;具有抽象性;软件的形态不可见;--必须通过观察、分析、思考、判断来了解其功能、性能和其它特性。
2〕软件是人脑思维的产物,其生产过程与硬件不同。
--开发过程的质量控制及软件产品保护问题。
3〕软件的开发和运行受计算机系统限制。
--软件移植问题。
4〕软件的开发技术落后,手工开发方式仍占统治地位。
--开发效率低。
2.2006年发布的国家分类标准是什么?1〕按功能:系统软件、支撑软件、应用软件2〕按规模:微型软件、小型软件、大型软件、甚大型软件、极大型软件3〕按工作方式:实时处理软件、分时软件、交互式软件、批处理软件4〕按效劳对象:工程软件、产品软件5〕按使用频度:使用频度低、使用频度高6〕按失效影响:不良影响、严重影响3.软件危机的表现有哪些?1)软件开发进度难以预测2)软件开发本钱难以控制3)用户对产品功能难以满足4)软件产品质量无法保证5)软件产品难以维护4.产生软件危机的原因?1)用户需求不明确2)缺乏正确的理论指导3)软件开发规模越来越大4)软件开发复杂度越来越高5.什么是软件工程三要素?软件工程的三要素:方法、工具和过程。
6.软件工程的根本目标是什么?①付出较低的开发本钱②到达要求的软件功能③取得较好的软件性能④开发的软件易于移植⑤需要较低的维护费用⑥能按时完成开发工作,及时交付使用7软件工程的根本原那么是什么?①抽象:采用分层次抽象,自顶向下、逐层细化的方法控制软件开发过程的复杂性。
②信息隐蔽:将模块设计成“黑箱〞,实现的细节隐藏在模块内部,不让模块的使用者直接。
这就是信息封装,使用与实现别离的原那么。
③模块化:如C语言程序中的函数过程,C++ 语言程序中的类。
模块化有助于信息隐蔽和抽象,有助于表示复杂的系统。
④局部化:要求在一个物理模块内集中逻辑上相互关联的计算机资源,保证模块之间具有松散的耦合,模块内部具有较强的内聚。
面向对象程序设计课后答案(完整版)
面向对象程序设计课后答案(完整版)第二章2-4#includeusing namespace std;Add(int a,int b);int main(){int x,y,sum;cout>x>>y;sum = add(x,y);cout >*p;p++;}p = p-20;for( i=0;i0) countp++;if(*p>age ;try{checkagescore(name,age);}catch( string){cout<<"exception :name is exit"<<endl;continue;}catch(int){cout<<"exception :age is not proper"<<endl;continue;}cout<<"name:"<<name<<" age :"< }return 0;}第三章3-1(1)A (2)C (3)B (4)C (5)C(6)B (7)B (8)C (9)C3-7(1)main()函数中p1.age = 30;语句是错误的。
age 是类的私有成员(2)构造函数应当给常数据成员和引用成员初始化,将构造函数改为:A(int a1,int b1):a(a1),b(b1){}或A(int a1 ):a(a1),b(a){}再将main中的A a(1,2); 改为A a(1);(3)(1)在Test 类中添加语句:void print();void Print(){cout<<x<<"-"<<y<<"="<<x-y<<endl;}改为void Test::Print(){cout<<x<<"-"<<y<<"="<<x-y<<endl;}main函数中Init(38,15);改为:A.Init(38,15);Print();改为:A.Print();3-8(1)Constructing AConstructing BDestructing BDestructing A(2)double a,double bpoint & pp.x3-9class box{int len1,len2,len3;public:box(int l1,int l2,int l3){len1 = l1;len2 = l2; len3 = l3;} long volumn(){return len1*len2*len3;}};3-10class Test{int m1,m2;public:void Init(int a,int b){m1 = a;m2 = b;}void Pring(){cout<<m1<<" "<<m2<<endl;}};3-11略3-12}第四章4-6(1)D (2)D (3)D (4)D (5)B(6)D4-7(1)static int count = 0;这样初始化静态成员值是不对的将其改为static int count;在类外,main函数前加int Sample::count = 0;(2)#include//#includeusing namespace std;class Ctest{private:int x; const int y1;public:const int y2;Ctest(int i1,int i2):y1(i1),y2(i2) {y1 =10;//y1 为常量不能赋值x = y1;}int readme() const;};int Ctest::readme ()const{int i;i = x;x++; //常函数内不能改变成员值return x;}int main(){Ctest c(2,8);int i = c.y2;c.y2 = i;//y2为常量,不能改值i = c.y1;//y1私有,类外不能访问return 0;}将出错语句全部注释4-8(1)题中印刷错误,将class C构造函数改为: C(){cout<<"constructor C:";}运行结果为:constructor Aconstructor Bconstructor C(2)40(3)3434-9#include#includeclass Date{int year;int month;int day;public:Date(int y,int m,int d){year=y;month=m;day=d;}void disp(){cout<<year<<" "<<month<<" "<<day<<endl;}friend int count_day(Date &d,int k);friend int l(int year);friend int h(Date &d1,Date &d2);};int count_day(Date &d,int k){static int day_tab[2][12]={{31,28,31,30,31,30,31,31,30,31,30,3 1},{31,29,31,30,31,30,31,31,30,31,30,31}};// 使用二维数组存放各月天数,第一行对应非闰年,第二行对应闰年int j,i,s;if(l(d.year))j=1;//闰年,取1else j=0;//非闰年,取0if(k)//K非0时{s=d.day;for(i=1;i<d.month;i++)//d.month为输入的月份s+=day_tab[j][i-1];}else//K为0时{s=day_tab[j][d.month]-d.day;for(i=d.month+1; i<=12; i++)s+=day_tab[j][i-1];}return s;//S为相差的天数}int l(int year){if(year%4==0&&year%100!=0||year%400==0) // 是闰年return 1;else // 不是闰年return 0;}int h(Date &d1,Date &d2){int days,day1,day2,y;if(d1.year<d2.year)//第一个日期年份小于第二个日期年份{days=count_day(d1,0);for(y=d1.year+1;y<d2.year;y++)if(l(y))//闰年。
java面向对象程序设计第二版课后答案.doc
java 面向对象程序设计第二版课后答案【篇一:java 面向对象程序设计课后答案】s=txt>java 面向对象程序设计清华大学出版社(编著耿祥义张跃平)习题解答建议使用文档结构图(选择word 菜单→视图→文档结构图)习题11.james gosling、、、、2.(1)使用一个文本编辑器编写源文件。
(2)使用java 编译器(javac.exe )编译java 源程序,得到字节码文件。
(3)使用java 解释器(java.exe )运行java 程序3.java 的源文件是由若干个书写形式互相独立的类组成的。
应用程序中可以没有public 类,若有的话至多可以有一个public 类。
4.系统环境path d\jdk\bin;系统环境classpath d\jdk\jre\lib\rt.jar;.;5. b6.java 源文件的扩展名是.java 。
java 字节码的扩展名是.class 。
7. d8.(1)speak.java(2)生成两个字节码文件,这些字节码文件的名字speak.class 和xiti8.class ava xiti8(4)执行java speak 的错误提示exception in thread main ng.nosuchmethoderror: main 执行java xiti8 得到的错误提示exception in thread main ng.noclassdeffounderror: xiti8 (wrong name: xiti8) 执行java xiti8.class 得到的错误提示exception in thread main ng.noclassdeffounderror:xiti8/class 执行java xiti8 得到的输出结果im glad to meet you9.属于操作题,解答略。
习题21. d2.【代码1】【代码2】错误//【代码3】更正为float z=6.89f; 3.float 型常量后面必须要有后缀“f或”“f。
面向对象的C++程序设计 第六版 课后习题答案第二章
Chapter 2C++ Basics1. Solutions to the Programming Projects:1. Metric - English units ConversionA metric ton is 35,273.92 ounces. Write a C++ program to read the weight of a box of cereal in ounces then output this weight in metric tons, along with the number of boxes to yield a metric ton of cereal.Design: To convert 14 ounces (of cereal) to metric tons, we use the 'ratio of units' to tell us whether to divide or multiply:1 metric tons14 ounces * * = 0.000397 metric tons35,273 ouncesThe use of units will simplify the determination of whether to divide or to multiply in making a conversion. Notice that ounces/ounce becomes unit-less, so that we are left with metric ton units. The number of ounces will be very, very much larger than the number of metric tons. It is then reasonable to divide the number of ounces by the number of ounces in a metric ton to get the number of metric tons.Now let metricTonsPerBox be the weight of the cereal box in metric tons. Let ouncesPerBox the be the weight of the cereal box in ounces. Then in C++ the formula becomes:const double ouncesPerMetric_ton = 35272.92; metricTonsPerBox = ouncesPerBox / ouncesPerMetricTon;This is metric tons PER BOX, whence the number of BOX(es) PER metric ton should be the reciprocal:boxesPerMetricTon = 1 / metricTonsPerBox;Once this analysis is made, the code proceeds quickly://Purpose: To convert cereal box weight from ounces to // metric tons to compute number of boxes to make up a // metric ton of cereal.#include <iostream>using namespace std;const double ouncesPerMetricTon = 35272.92;int main(){double ouncesPerBox, metricTonsPerbox,boxesPerMetricTon;char ans = 'y';while( 'y' == ans || 'Y' == ans ){cout << “enter the weight in ounces of your”<< “favorite cereal:” <<end l;cin >> ouncesPerBox;metricTonsPerbox =ouncesPerBox / ouncesPerMetricTon;boxesPerMetricTon = 1 / metricTonsPerbox;cout << "metric tons per box = "<< metricTonsPerbox << endl;cout << "boxes to yield a metric ton = "<< boxesPerMetricTon << endl;cout << " Y or y continues, any other character ”<< “terminates." << endl;cin >> ans;}return 0;}A sample run follows:enter the weight in ounces of your favorite cereal:14metric tons per box = 0.000396905boxes to yield a metric ton = 2519.49Y or y continues, any other characters terminates.yenter the weight in ounces of your favorite cereal:20metric tons per box = 0.000567007boxes to yield a metric ton = 1763.65Y or y continues, any other characters terminates.n2. Lethal DoseCertain artificial sweeteners are poisonous at some dosage level. It is desired to know how much soda a dieter can drink without dying. The problem statement gives no information about how to scale the amount of toxicity from the dimensions of the experimental mouse to the dimensions of the dieter. Hence the student must supply this necessary assumption as basis for the calculation.This solution supposes the lethal dose is directly proportional to the weight of the subject, henceweightOfDieterlethalDoseDieter = lethalDoseMouse *weightOfMouseThis program accepts weight of a lethal dose for a mouse, the weight of the mouse, and the weight of the dieter, and calculates the amount of sweetener that will just kill the dieter, based on the lethal dose for a mouse in the lab. If the student has problems with grams and pounds, a pound is 454 grams.It is interesting that the result probably wanted is a safe number of cans, while all the data can provide is the minimum lethal number! Some students will probably realize this, but my experience is that most will not. I just weighed a can of diet pop and subtracted the weight of an empty can. The result is about 350 grams. The label claims 355 ml, which weighs very nearly 355 grams. To get the lethal number of cans from the number of grams of sweetener, you need the number of grams ofsweetener in a can of pop, and the concentration of sweetener, which the problem assumes 0.1% , that is a conversion factor of 0.001.gramsSweetenerPerCan = 350 * 0.001 = 0.35 grams/cancans = lethalDoseDieter / (0.35 grams / can)////Input: lethal dose of sweetener for a lab mouse, weights// of mouse and dieter, and concentration of sweetener in a // soda.//Output: lethal dose of soda in number of cans.//Assumption: lethal dose proportional to weight of subject// Concentration of sweetener in the soda is 1/10 percent #include <iostream>using namespace std;const double concentration = .001; // 1/10 of 1 percentconst double canWeight = 350;const double gramsSweetnerPerCan = canWeight concentration; //units of grams/canint main(){double lethalDoseMouse, lethalDoseDieter,weightMouse, weightDieter; //units: gramsdouble cans;char ans;do{cout << "Enter the weight of the mouse in grams"<< endl;cin >> weightMouse;cout << "Enter the lethal dose for the mouse in“<< ”grams " << endl;cin >> lethalDoseMouse;cout << "Enter the desired weight of the dieter in”<<“ grams " << endl;cin >> weightDieter;lethalDoseDieter =lethalDoseMouse weightDieter/weightMouse;cout << "For these parameters:\nmouse weight: "<< weightMouse<< " grams " << endl<< "lethal dose for the mouse: "<< lethalDoseMouse<< "grams" << endl<< "Dieter weight: " << weightDieter<< " grams " << endl<< "The lethal dose in grams of sweetener is: "<< lethalDoseDieter << endl;cans = lethalDoseDieter / gramsSweetnerPerCan;cout << "Lethal number of cans of pop: "<< cans << endl;cout << "Y or y continues, any other character quits"<< endl;cin >> ans;} while ( 'y' == ans || 'Y' == ans );return 0;}A typical run follows:17:23:09:~/AW$ a.outEnter the weight of the mouse in grams15Enter the lethal dose for the mouse in grams100Enter the desired weight of the dieter, in grams 45400For these parameters:mouse weight: 15 gramslethal dose for the mouse: 100 gramsDieter weight: 45400 gramsThe lethal dose in grams of sweetener is: 302667 Lethal number of cans of pop: 864762Y or y continues, any other character quitsyEnter the weight of the mouse in grams30Enter the lethal dose for the mouse in grams100Enter the desired weight of the dieter, in grams 45400For these parameters:mouse weight: 30 gramslethal dose for the mouse: 100 gramsDieter weight: 45400 gramsThe lethal dose in grams of sweetener is: 151333 Lethal number of cans of pop: 432381Y or y continues, any other character quitsq17:23:56:~/AW$3. Pay IncreaseThe workers have won a 7.6% pay increase, effective 6 months retroactively. This program is to accept the previous annual salary, then outputs the retroactive pay due the employee, the new annual salary, and the new monthly salary. Allow user to repeat as desired. The appropriate formulae are:const double INCREASE = 0.076;newSalary = salary * (1 + INCREASE);monthly = salary / 12;retroactive = (salary – oldSalary)/2;The code follows:////Given 6 mos retroactive 7.6% pay increase,//input salary//Output new annual and monthly salaries, retroactive pay#include <iostream>using namespace std;const double INCREASE = 0.076;int main(){double oldSalary, salary, monthly, retroactive;char ans;cout << "Enter current annual salary." << endl<< "I'll return new annual salary, monthly ”<< “salary, and retroactive pay." << endl;cin >> oldSalary;//old annual salarysalary = oldSalary*(1+INCREASE);//new annual salarymonthly = salary/12;retroactive = (salary – oldSalary)/2;cout << "new annual salary " << salary << endl;cout << "new monthly salary " << monthly << endl;cout << "retroactive salary due: "<< retroactive << endl;return 0;}17:50:12:~/AW$ a.outEnter current annual salary.100000I'll return new annual salary, monthly salary, andretroactive pay.new annual salary 107600new monthly salary 8966.67retroactive salary due: 38004. Retroactive Salary// File: Ch2.4.cpp// Modify program from Problem #3 so that it calculatesretroactive// salary for a worker for a number of months entered by the user. //Given a 7.6% pay increase,//input salary//input number of months to compute retroactive salary//Output new annual and monthly salaries, retroactive pay#include <iostream>const double INCREASE = 0.076;int main(){using std::cout;using std::cin;using std::endl;double oldSalary, salary, monthly, oldMonthly, retroactive;int numberOfMonths; // number of months to pay retroactiveincreasechar ans;cout << "Enter current annual salary and a number of months\n"<< "for which you wish to compute retroactive pay.\n"<< "I'll return new annual salary, monthly "<< "salary, and retroactive pay." << endl;cin >> oldSalary;//old annual salarycin >> numberOfMonths;salary = oldSalary * (1+INCREASE); //new annual salaryoldMonthly = oldSalary/12;monthly = salary/12;retroactive = (monthly - oldMonthly) * numberOfMonths;// retroactive = (salary - oldSalary)/2; // six monthsretroactive pay increase.cout << "new annual salary " << salary << endl;cout << "new monthly salary " << monthly << endl;cout << "retroactive salary due: "<< retroactive << endl;return 0;}/*Typical runEnter current annual salary and a number of monthsfor which you wish to compute retroactive pay.I'll return new annual salary, monthly salary, and retroactive pay. 120009new annual salary 12912new monthly salary 1076retroactive salary due: 684Press any key to continue*/5. No solution provided.6. No solution provided.7. PayrollThis problem involves payroll and uses the selection construct. A possible restatement: An hourly employee's regular payRate is $16.78/hour for hoursWorked <= 40 hours. If hoursWorked > 40 hours, then (hoursWorked -40) is paid at an overtime premium rate of 1.5 * payRate. FICA (social security) tax is 6% and Federal income tax is 14%. Union dues of$10/week are withheld. If there are 3 or more covered dependents, $15 more is withheld for dependent health insurance.a) Write a program that, on a weekly basis, accepts hours worked then outputs gross pay, each withholding amount, and net (take-home) pay.b) Add 'repeat at user discretion' feature.I was unpleasantly surprised to find that with early GNU g++ , you cannot use a leading 0 (such as an SSN 034 56 7891) in a sequence of integer inputs. The gnu iostreams library took the integer to be zero and went directly to the next input! You either have to either use an array of char, or 9 char variables to avoid this restriction.Otherwise, the code is fairly straight forward.//file //pay roll problem://Inputs: hoursWorked, number of dependents//Outputs: gross pay, each deduction, net pay////This is the 'repeat at user discretion' version//Outline://In a real payroll program, each of these values would be//stored in a file after the payroll calculation was printed //to a report.////regular payRate = $10.78/hour for hoursWorked <= 40//hours.//If hoursWorked > 40 hours,// overtimePay = (hoursWorked - 40) * 1.5 * PAY_RATE.//FICA (social security) tax rate is 6%//Federal income tax rate is 14%.//Union dues = $10/week .//If number of dependents >= 3// $15 more is withheld for dependent health insurance.//#include <iostream>using namespace std;const double PAY_RATE = 16.78;const double SS_TAX_RATE = 0.06;const double FedIRS_RATE = 0.14;const double STATE_TAX_RATE = 0.05;const double UNION_DUES = 10.0;const double OVERTIME_FACTOR = 1.5;const double HEALTH_INSURANCE = 15.0;int main(){double hoursWorked, grossPay, overTime, fica,incomeTax, stateTax, union_dues, netPay;int numberDependents, employeeNumber;char ans;//set the output to two places, and force .00 for cents cout.setf(ios::showpoint);cout.setf(ios::fixed);cout.precision(2);// compute payrolldo{cout << "Enter emplo yee SSN (digits only,”<< “ no spaces or dashes) \n”;cin >> employeeNumber ;cout << “Please the enter hours worked and number “<< “of employees.” << endl;cin >> hoursWorked ;cin >> numberDependents;cout << endl;if (hoursWorked <= 40 )grossPay = hoursWorked * PAY_RATE;else{overTime =(hoursWorked - 40) * PAY_RATE * OVERTIME_FACTOR; grossPay = 40 * PAY_RATE + overTime;}fica = grossPay * SS_TAX_RATE;incomeTax = grossPay * FedIRS_RATE;stateTax = grossPay * STATE_TAX_RATE;netPay =grossPay - fica - incomeTax- UNION_DUES - stateTax;if ( numberDependents >= 3 )netPay = netPay - HEALTH_INSURANCE;//now print report for this employee:cout << "Employee number: "<< employeeNumber << endl;cout << "hours worked: " << hoursWorked << endl; cout << "regular pay rate: " << PAY_RATE << endl;if (hoursWorked > 40 ){cout << "overtime hours worked: "<< hoursWorked - 40 << endl;cout << "with overtime premium: "<< OVERTIME_FACTOR << endl;}cout << "gross pay: " << grossPay << endl;cout << "FICA tax withheld: " << fica << endl;cout << "Federal Income Tax withheld: "<< incomeTax << endl;cout << "State Tax withheld: " << stateTax << endl;if (numberDependents >= 3 )cout << "Health Insurance Premium withheld: "<< HEALTH_INSURANCE << endl;cout << "Flabbergaster's Union Dues withheld: "<< UNION_DUES << endl;cout << "Net Pay: " << netPay << endl << endl;cout << "Compute pay for another employee?”<< “ Y/y repeats, any other ends" << endl;cin >> ans;} while( 'y' == ans || 'Y' == ans );return 0;}//A typical run:14:26:48:~/AW $ a.outEnter employee SSN (digits only, no spaces or dashes) 234567890Please the enter hours worked and number of employees.101Employee number: 234567890hours worked: 10.00regular pay rate: 16.78gross pay: 167.80FICA tax withheld: 10.07Federal Income Tax withheld: 23.49State Tax withheld: 8.39Flabbergaster's Union Dues withheld: 10.00Net Pay: 115.85Compute pay for another employee? Y/y repeats, any other ends yEnter employee SSN (digits only, no spaces or dashes) 987654321Please the enter hours worked and number of employees.103Employee number: 987654321hours worked: 10.00regular pay rate: 16.78gross pay: 167.80FICA tax withheld: 10.07Federal Income Tax withheld: 23.49State Tax withheld: 8.39Health Insurance Premium withheld: 35.00Flabbergaster's Union Dues withheld: 10.00Net Pay: 80.85Compute pay for another employee? Y/y repeats, any other ends yEnter employee SSN (digits only, no spaces or dashes) 123456789Please the enter hours worked and number of employees.453Employee number: 123456789hours worked: 45.00regular pay rate: 16.78overtime hours worked: 5.00with overtime premium: 1.50gross pay: 797.05FICA tax withheld: 47.82Federal Income Tax withheld: 111.59State Tax withheld: 39.85Health Insurance Premium withheld: 35.00Flabbergaster's Union Dues withheld: 10.00Net Pay: 552.79Compute pay for another employee? Y/y repeats, any other ends n14:28:12:~/AW $8. No solution provided.9. Installment Loan TimeNo down payment, 18 percent / year, payment of $50/month, payment goes first to interest, balance to principal. Write a program that determines the number of months it will take to pay off a $1000 stereo. The following code also outputs the monthly status of the loan.#include <iostream>using namespace std;// chapter 2 problem 9.int main(){double principal = 1000.;double interest, rate = 0.015;int months = 0;cout << "months\tinterest\tprincipal" << endl;while ( principal > 0 ){months++;interest = principal * rate;principal = principal - (50 - interest);if ( principal > 0 )cout << months << "\t" << interest << "\t\t"<< principal << endl;}cout << "number of payments = " << months;//undo the interation that drove principal negative: principal = principal + (50 - interest);//include interest for last month:interest = principal * 0.015;principal = principal + interest;cout << " last months interest = " << interest;cout << " last payment = " << principal << endl;return 0;}Testing is omitted for this problem.10. No solution provided.11. Separate numbers by sign, compute sums and averages// Programming Problem 11// Read ten int values output// sum and average of positive numbers// sum and average of nonpositive numbers,// sum and average of all numbers,//// Averages are usually floating point numbers.We mulitply// the numerator of the average computation by 1.0 to make// the int values convert automatically to double.#include <iostream>int main(){using std::cout;using std::cin;using std::endl;int value, sum = 0, sumPos = 0, sumNonPos = 0;int countPos = 0, countNeg = 0;cout << "Enter ten numbers, I'll echo your number and compute\n"<< "the sum and average of positive numbers\n"<< "the sum and average of nonpositive numbers\n"<< "the sum and average of all numbers\n\n";for(int i =0; i < 10; i++){cin >> value;cout << "value " << value <<endl;sum += value;if (value > 0){sumPos += value;countPos++;}else{sumNonPos += value;countNeg++;}}cout << "Sum of Positive numbers is "<< sumPos << endl;cout << "Average of Positive numbers is "<< (1.0 * sumPos) / countPos << endl;cout << "Sum of NonPositive numbers is "<< sumNonPos << endl;cout << "Average of NonPositive numbers is "<< (1.0 * sumNonPos) / countNeg << endl;cout << "Sum " << sum << endl;cout << "Average is " << (1.0 * sum)/(countPos + countNeg) << endl;if((countPos + countNeg)!= 10)cout << "Count not 10, error some place\n";return 0;}/*Typical runEnter ten numbers, I'll echo your number and computethe sum and average of positive numbersthe sum and average of nonpositive numbersthe sum and average of all numbers4value 45value 5-1value -13value 3-4value -4-3value -39value 98value 87value 72value 2Sum of Positive numbers is 38Average of Positive numbers is 5.42857Sum of NonPositive numbers is -8Average of NonPositive numbers is -2.66667Sum 30Average is 3Press any key to continue*/12.//***********************************************************************// Ch2Proj12.cpp//// This program computes the square root of a number n// using the Babylonian algorithm.//*********************************************************************** #include <iostream>using namespace std;// ====================// main function// ====================int main(){double guess, previousguess, n, r;// Input number to compute the square root ofcout << "Enter number to compute the square root of." << endl;cin >> n;// Initial guesspreviousguess = n;guess = n /2;// Repeat until guess is within 1% of the previous guesswhile (((previousguess - guess) / previousguess) > 0.01){previousguess = guess;r = n / guess;guess = (guess + r) / 2;}cout << "The estimate of the square root of " << n << " is "<< guess << endl;return 0;}13.//*********************************************************************** // Ch2Proj13.cpp//// This program inputs a speed in MPH and converts it to// Minutes and Seconds per mile, as might be output on a treadmill.//*********************************************************************** #include <iostream>using namespace std;// ====================// main function// ====================int main(){double milesPerHour, hoursPerMile, minutesPerMile, secondsPace;int minutesPace;// Input miles per hourcout << "Enter speed in miles per hour:" << endl;cin >> milesPerHour;// Compute inverse, which is hours per milehoursPerMile = 1.0 / milesPerHour;// Convert to minutes per mile which is 60 seconds/hour * hoursPerMile minutesPerMile = 60 * hoursPerMile;// Extract minutes by converting to an integer, while// truncates any value after the decimal pointminutesPace = static_cast<int>(minutesPerMile);// Seconds is the remaining number of minutes * 60secondsPace = (minutesPerMile - minutesPace) * 60;cout << milesPerHour << " miles per hour is a pace of " << minutesPace << " minutes and " << secondsPace << " seconds. " << endl;return 0;}14.//*********************************************************************** // Ch2Proj14.cpp//// This program plays a simple game of "Mad Libs".//*********************************************************************** #include <iostream>using namespace std;// ====================// main function// ====================int main(){string instructorName;string yourName;string food;int num;string adjective;string color;string animal;cout << "Welcome to Mad Libs! Enter your name: " << endl;cin >> yourName;cout << "Enter your instructor's first or last name." << endl;cin >> instructorName;cout << "Enter a food." << endl;cin >> food;cout << "Enter a number between 100 and 120." << endl;cin >> num;cout << "Enter an adjective." << endl;cin >> adjective;cout << "Enter a color." << endl;cin >> color;cout << "Enter an animal." << endl;cin >> animal;cout << endl;cout << "Dear Instructor " << instructorName << "," << endl;cout << endl;cout << "I am sorry that I am unable to turn in my homework at this time."<< endl;cout << "First, I ate a rotten " << food << " which made me turn " << color << " and " << endl;cout << "extremely ill. I came down with a fever of " << num << "." << endl;cout << "Next, my " << adjective << " pet " << animal << " must have " <<"smelled the remains " << endl;cout << "of the " << food << " on my homework, because he ate it. I am " <<"currently " << endl;cout << "rewriting my homework and hope you will accept it late." << endl;cout << endl;cout << "Sincerely," << endl;cout << yourName << endl;return 0;}2. Outline of topics in the chapter2.1 Variables and assignments2.2 Input and Output2.3 Data Types and Expressions2.4 Simple Flow of Controlbranchinglooping2.5 Program Style3. General Remarks on the chapter:This chapter is a very brief introduction to the minimum C++ necessary to write simple programs.Comments in the Student's code:Self documenting code is a code feature to be striven for. The use of identifier names that have meaning within the context of the problems being solved goes a long way in this direction.Code that is not self documenting for whatever reasons may be made clearer by appropriate (minimal) comments inserted in the code."The most difficult feature of any programming language to master is thecomment."-- a disgruntled maintenance programmer."Where the comment and the code disagree, both should be assumed to be inerror."-- an experienced maintenance programmer.With these cautions in mind, the student should place remarks at the top of file containing program components, describing the purpose. Exactly what output is required should be specified, and any conditions on the input to guarantee correct execution should also bespecified.Remarks can clarify difficult points, but remember, if the comment doesn't add to what can be gleaned from the program code itself, the comment is unnecessary, indeed it gets in the way. Good identifier names can reduce the necessity for comments!iostreams vs stdioYou will have the occasional student who has significant C programming experience. These students will insist on using the older stdio library input-output (for example, printf). Discourage this, insist on C++ iostream i/o. The reason is that the iostream library understands and uses the type system of C++. You have to tell stdio functions every type for every output attempted. And if you don't get it right, then the error may not be obvious in the output. Either iostreams knows the type, or the linker will complain that it doesn't have the member functions to handle the type you are using. Then it is easy enough to write stream i/o routines to do the i/o in a manner consistent with the rest of the library.。
软件工程 第二章测验 测验答案 慕课答案 UOOC优课 课后练习 深圳大学
第二章测验一、单项选择题(共40.00分)1.以下哪一个阶段不属于软件定义时期?()A.问题定义B.可行性研究C.需求分析D.概要设计正确答案:D2 .瀑布模型各阶段之间具有顺序性和()oA.反应性B.依赖性C.同构性D.统一性正确答案:B3 .应用螺旋模型时,维护和开发之间()oA.存在明显界限B.必须由不同团队完成C.通常采用不同的开发方法D.没有本质区别正确答案:D4.最适用于内部开发的大规模软件工程的生命周期模型是()oA.瀑布模型B.喷泉模型C.螺旋模型D,增量模型正确答案:C二、多项选择题(共33.00分)1 .采用快速原型模型开发软件时,原型系统可用于O oA,捕获和理解用户需求B,帮助进行用户界面设计C.支持软件结构设计D.测试目标系统性能正确答案:A B2 .喷泉模型的特点包括()oA.迭代无缝B.强调重用C.风险驱动D.文档驱动正确答案:A B3 .()应用了迭代的思想。
A.瀑布模型B.喷泉模型C.螺旋模型D,增量模型正确答案:BCD三、判断题(共27,00分)1 .增量模型有利于快速响应用户需求的变化。
()A.正确B.错误正确答案:A2 .瀑布模型的每个阶段结束前都要对完成的文档进行评审。
()A.正确B.错误正确答案:A3 .面向对象方法在概念和表示方法上的一致性,保证了在各项开发活动之间的无缝过渡。
()A.正确B.错误正确答案:A。
面向对象程序设计课后习题答案
第一章:面向对象程序设计概述[1_1]什么是面向对象程序设计?面向对象程序设计是一种新型的程序设计范型。
这种范型的主要特征是:程序=对象+消息。
面向对象程序的基本元素是对象,面向对象程序的主要结构特点是:第一:程序一般由类的定义和类的使用两部分组成,在主程序中定义各对象并规定它们之间传递消息的规律。
第二:程序中的一切操作都是通过向对象发送消息来实现的,对象接受到消息后,启动有关方法完成相应的操作。
面向对象程序设计方法模拟人类习惯的解题方法,代表了计算机程序设计新颖的思维方式。
这种方法的提出是软件开发方法的一场革命,是目前解决软件开发面临困难的最有希望、最有前途的方法之一。
[1_2]什么是类?什么是对象?对象与类的关系是什么?在面向对象程序设计中,对象是描述其属性的数据以及对这些数据施加的一组操作封装在一起构成的统一体。
对象可以认为是:数据+操作在面向对象程序设计中,类就是具有相同的数据和相同的操作的一组对象的集合,也就是说,类是对具有相同数据结构和相同操作的一类对象的描述。
类和对象之间的关系是抽象和具体的关系。
类是多个对象进行综合抽象的结果,一个对象是类的一个实例。
在面向对象程序设计中,总是先声明类,再由类生成对象。
类是建立对象的“摸板”,按照这个摸板所建立的一个个具体的对象,就是类的实际例子,通常称为实例。
[1_3]现实世界中的对象有哪些特征?请举例说明。
对象是现实世界中的一个实体,其具有以下一些特征:(1)每一个对象必须有一个名字以区别于其他对象。
(2)需要用属性来描述它的某些特性。
(3)有一组操作,每一个操作决定了对象的一种行为。
(4)对象的操作可以分为两类:一类是自身所承受的操作,一类是施加于其他对象的操作。
例如:雇员刘名是一个对象对象名:刘名对象的属性:年龄:36 生日:1966.10.1 工资:2000 部门:人事部对象的操作:吃饭开车[1_4]什么是消息?消息具有什么性质?在面向对象程序设计中,一个对象向另一个对象发出的请求被称为“消息”。
JAVA语言与面向对象程序设计课后章节习题答案
String s1 = in1.getText(); double d1 = Double.parseDouble( s1 ); String s2 = in2.getText(); double d2 = Double.parseDouble( s2 ); double result = d1 * d2; out.setText( d1 + "X" + d2 +"=" + result); } } } 2.Java 有哪些基本数据类型?写出 int 型所能表达的最大、最 小数据。 答:Java 中定义了 4 类/8 种基本数据类型: (1)逻辑型——boolean (2)整数型——byte, short, int, long (3)浮点数型——float, double (4)字符型——char 其中整型 int 占 4 个字节,其范围为-2147483648-2147483647。 3.Java 的字符采用何种编码方案?有何特点?写出五个常见的转 义符。 答:char(字符型)是用 Unicode 编码表达的字符,在内存中占两 个字节。由于 Java 的字符类型采用了一种新的国际标准编码方 案——Unicode 编码,这样便于东方字符和西方字符处理,这样
/doc/3c8e0230a88271fe910ef12d2 af90242a895ab8c.html 网站下载较新的版本,如 JDK1.5(也称 为 JDK5.0)。 JDK 文档也可以从网上下载。 3.编写一个 Java Application,利用 JDK 软件包中的工具编译 并运行这个程序,在屏幕上输出“Welcome to Java World!”。 答:见程序。 public class Ex2_3 { public static void main(String[] args) { System.out.println("Welcom to java vorld"); } } 4.编写一个 Java Applet,使之能够在浏览器中显示“Welcome to Java Applet World!”的字符串信息。 答:见程序。import java.awt.*; import java.applet.*; public class Ex2_4 extends Applet { //an applet public void paint(Graphics g){ g.drawString ("Welcome to Java Applet World!",20,20); }
[VIP专享]面向对象程序设计第二章课后答案
1.什么是命名空间,如何访问命名空间的成员?【解答】为了解决不同文件中同名变量的问题,C++标准中引入命名空间的概念。
命名空间(namespace)是一种特殊的作用域,命名空间可以由程序员自己来创建,可以将不同的标识符集合在一个命名作用域内,这些标识符可以类、对象、函数、变量、结构体、模板以及其他命名空间等。
在作用域范围内使用命名空间就可以访问命名空间定义的标识符。
有3种访问方法:(1)直接指定标识符,访问方式为:命名空间标识符名∷成员名。
(2)使用using namespace命令(3)使用using关键词声明2.什么是内联函数,它有什么特点?哪些函数不能定义为内联函数?【解答】用inline关键字声明或定义的函数称为内联函数。
C++中对于功能简单、规模小、使用频繁的函数,可以将其设置为内联函数。
内联函数(inline function)的定义和普通函数相同,但C++对它们的处理方式不一样。
在编译时,C++将用内联函数程序代码替换对它每次的调用。
这样,内联函数没有函数调用的开销,即节省参数传递、控制转移的开销,从而提高了程序运行时的效率。
但是,由于每次调用内联函数时,需要将这个内联函数的所有代码复制到调用函数中,所以会增加程序的代码量,占用更多的存储空间,增大了系统空间方面的开销。
因此,内联函数是一种空间换时间的方案。
函数体内有循环语句和switch语句,递归调用的函数不能定义为内联函数。
3.什么是函数重载?在函数调用时,C++是如何匹配重载函数的?【解答】函数重载是指两个或两个以上的函数具有相同的函数名,但参数类型不一致或参数个数不同。
编译时编译器将根据实参和形参的类型及个数进行相应地匹配,自动确定调用哪一个函数。
使得重载的函数虽然函数名相同,但功能却不完全相同。
在函数调用时,C++是匹配重载函数规则如下:首先寻找一个精确匹配,如果能找到,调用该函数;其次进行提升匹配,通过内部类型转换(窄类型到宽类型的转换)寻求一个匹配,如char到int、short到int等,如果能找到,调用该函数;最后通过强制类型转换寻求一个匹配,如果能找到,调用该函数。
软件工程(山东科技大学)知到章节答案智慧树2023年
软件工程(山东科技大学)知到章节测试答案智慧树2023年最新第一章测试1.软件是一种( )参考答案:逻辑产品2.产生软件危机的原因主要与两个方面的问题有关,它们是()参考答案:软件产品本身的特点与其它工业产品不一样,而且在软件的开发和维护过程中用的方法不正确3.开发软件所需高成本和产品的低质量之间有着尖锐的矛盾,这种现象称为( )参考答案:软件危机4.在软件研究过程中,CASE是()参考答案:指计算机辅助软件工程第二章测试1.以下软件生命周期模型中不属于演化模型的是()参考答案:瀑布模型2.下列关于原型模型的说法,错误的是()参考答案:原型必须是可以运行的,原型做得越复杂,说明开发团队的水平越高3.CMM提供了一个成熟度等级框架,下面哪一级不属于CMM成熟度等级()参考答案:优先级4.基于构件的开发模型利用预先包装好的软件构件(包括组织内部开发的构件和现存商品化构件COTS)来构造应用系统。
参考答案:对5.喷泉模型认为软件生命周期的各个阶段是相互重叠和多次反复的。
主要用于面向对象方法中。
参考答案:对第三章测试1.可行性分析的结论主要由以下几类()参考答案:其他都对2.需求分析中开发人员要从用户那里了解()。
参考答案:软件做什么3.需求分析是()。
参考答案:软件开发工作的基础4.在需求分析过程中,分析员要从用户那里解决的最重要的问题是明确软件做什么。
()参考答案:对5.软件需求规格说明书在软件开发中具有重要的作用,它是软件可行性分析的依据。
()参考答案:错第四章测试1.为了提高模块的独立性,模块内部最好是()。
参考答案:功能内聚2.一个模块的()太大一般是因为缺乏中间层次,应当适当增加中间层次的控制模块。
参考答案:扇出3.模块的内聚性最高的是()。
参考答案:功能内聚4.模块的耦合性可以按照耦合程度的高低进行排序,以下哪一项符合从低到高的正确次序()。
参考答案:无直接耦合,数据耦合,控制耦合,内容耦合5.模块划分的最重要的原则是模块独立性原则()参考答案:对第五章测试1.SA法的主要描述手段有( )参考答案:DFD图、数据词典、加工说明2.数据流图是常用的进行软件需求分析的图形工具,其基本符号是()参考答案:加工、数据流、数据存储和外部实体3.某系统软件结构如下图所示,该软件结构的宽度为( )参考答案:34.变换型的DFD图可看成是对输入数据进行转换而得到输出数据的处理,因此可以使用事务分析技术得到初始的模块结构图。
第二章软件工程
以下不属于UML模型图组成部分的是()。
5分A.事物B.关系C.图D.结构正确答案:D我的答案:B得分:02.在用例之间,会有三种不同的关系,下列哪个不是他们之间可能的关系()5分A.包含B.泛化C.扩展D.关联正确答案:D我的答案:D得分:53.下列关于UML包的描述,错误的是()5分A.大多数面向对象的语言都提供了类似UML包的机制,用于组织及避免类间的名称冲突。
B.当一个包导入另外一个包时,该包里的元素能够使用被导入包里的元素,而不必在使用时通过包名指定其中的元素。
C.当使用某个包中的类时如果未将包导入,则需要使用包名加类名的形式引用指定的类。
D.要在UML中显示导入关系,需要画一条从包连接到目标包的实线,再加上字符import正确答案:D我的答案:D得分:54.下列表述错误的是()5分A.交互图强调的是对象到对象的控制流,而活动图则强调的是从活动到活动的控制流。
B.活动图用来描述事物或对象的活动变化流程,是一种表述业务过程、工作流的技术。
C.复合活动是可以再分解的复杂活动。
D.活动流描述活动之间的有向关系,反映一个活动向另外一个活动之间的转移。
用带箭头的虚线表示。
正确答案:D我的答案:D得分:55.关于用例与类的对比中()是错误的5分A.都属于模型结构元素B.都存在继承关系C.类描述系统的部分静态视图,用例描述系统动态的行为视图D.类描述的是系统的内部构成,用例也可以描述系统的内部构成正确答案:D我的答案:D得分:56.UML图中,对新开发系统的需求进行建模,规划开发什么功能或测试用例,采用(1)最适合。
而展示交付系统的软件组件和硬件之间的关系的图是(2)。
5分A.类图部署图B.对象图组件图C.用例图部署图D.交互图组件图正确答案:C我的答案:C得分:57.以下不属于UML模型图组成部分的是()5分A.事物B.关系C.图D.结构正确答案:D我的答案:B得分:08.在UML模型图的事物中,结构事物主要包括7种,以下不是结构事物的是()A.类、接口B.协作、用例C.对象、图例D.活动类、组件和节点正确答案:C我的答案:C得分:59.UML图中,一张交互图显示一个交互。
软件工程大作业(2)(答案)
软件工程大作业(2)(答案)软件工程作业第二部分一、填空1.结构化分析方法的分析策略是___自顶向下逐步求精_______。
2.衡量模块独立性的两个定性标准是_耦合性与内聚性________。
3.软件集成测试的方法主要有两种,它们是___渐增式与非渐增式测试_______。
4.继承性是子类自动共享其父类的__数据结构和方法____________机制。
5.在面向对象方法中,人们常用状态图描述类中对象的___动态行为________。
6.规定功能的软件,在一定程度上能从错误状态自动恢复到正常状态,则称该软件为____容错_____软件。
7.可行性研究的目的是用最小的代价在尽可能短的时间内确定该软件项目_是否值得开发_。
8.需求分析阶段,分析人员要确定对问题的综合需求,其中最主要的是__功能需求_。
9.软件生存周期中时间最长、花费的精力和费用最多的一个阶段是__维护_____阶段。
10.对象之间进行通信叫做__消息_____。
11.计算机辅助软件工程这一术语的英文缩写为_CASE_______。
12.McCall提出的软件质量模型包括______11________个软件质量特性。
13.为了便于对照检查,测试用例应由输入数据和预期的___输出结果____两部分组成。
14.软件结构是以____模块__________为基础而组成的一种控制层次结构。
15.结构化语言(PDL)是介于自然语言和____形式语言____之间的一种半形式语言。
16.软件概要设计的主要任务就是__软件结构的设计______。
17.结构化程序设计方法是使用___三种基本控制结构____构造程序。
18.软件开发是一个自顶向下逐步细化和求精过程,而软件测试是一个__自底向上或相反顺序 _____集成的过程。
19.在建立对象的功能模型时,使用的数据流图中包含有处理、数据流、动作对象和__数据存储对象_____。
二、选择1.UML是软件开发中的一个重要工具,它主要应用于哪种软件开发方法( C )A、基于瀑布模型的结构化方法B、基于需求动态定义的原型化方法C、基于对象的面向对象的方法D、基于数据的数据流开发方法2.面向对象的开发方法中,(B)将是面向对象技术领域内占主导地位的标准建模语言。
面向对象程序设计第二章课后答案说课讲解
面向对象程序设计第二章课后答案1.什么是命名空间,如何访问命名空间的成员?【解答】为了解决不同文件中同名变量的问题,C++标准中引入命名空间的概念。
命名空间(namespace)是一种特殊的作用域,命名空间可以由程序员自己来创建,可以将不同的标识符集合在一个命名作用域内,这些标识符可以类、对象、函数、变量、结构体、模板以及其他命名空间等。
在作用域范围内使用命名空间就可以访问命名空间定义的标识符。
有3种访问方法:(1)直接指定标识符,访问方式为:命名空间标识符名∷成员名。
(2)使用using namespace命令(3)使用using关键词声明2.什么是内联函数,它有什么特点?哪些函数不能定义为内联函数?【解答】用inline关键字声明或定义的函数称为内联函数。
C++中对于功能简单、规模小、使用频繁的函数,可以将其设置为内联函数。
内联函数(inline function)的定义和普通函数相同,但C++对它们的处理方式不一样。
在编译时,C++将用内联函数程序代码替换对它每次的调用。
这样,内联函数没有函数调用的开销,即节省参数传递、控制转移的开销,从而提高了程序运行时的效率。
但是,由于每次调用内联函数时,需要将这个内联函数的所有代码复制到调用函数中,所以会增加程序的代码量,占用更多的存储空间,增大了系统空间方面的开销。
因此,内联函数是一种空间换时间的方案。
函数体内有循环语句和switch语句,递归调用的函数不能定义为内联函数。
3.什么是函数重载?在函数调用时,C++是如何匹配重载函数的?【解答】函数重载是指两个或两个以上的函数具有相同的函数名,但参数类型不一致或参数个数不同。
编译时编译器将根据实参和形参的类型及个数进行相应地匹配,自动确定调用哪一个函数。
使得重载的函数虽然函数名相同,但功能却不完全相同。
在函数调用时,C++是匹配重载函数规则如下:首先寻找一个精确匹配,如果能找到,调用该函数;其次进行提升匹配,通过内部类型转换(窄类型到宽类型的转换)寻求一个匹配,如char到int、short到int等,如果能找到,调用该函数;最后通过强制类型转换寻求一个匹配,如果能找到,调用该函数。
谭浩强《C++面向对象程序设计》第二章答案
谭浩强《C++面向对象程序设计》第二章答案-CAL-FENGHAI-(2020YEAR-YICAI)_JINGBIAN第二章1#include <iostream>using namespace std;class Time{public:void set_time();void show_time();private: //成员改为公用的 int hour;int minute;int sec;};void Time::set_time() //在main函数之前定义{cin>>hour;cin>>minute;cin>>sec;}void Time::show_time() //在main 函数之前定义{cout<<hour<<":"<<minute<<":"<<sec<< endl;}int main(){Time t1;();();return 0;}2:#include <iostream>using namespace std;class Time{public:void set_time(void){cin>>hour;cin>>minute;cin>>sec;}void show_time(void){cout<<hour<<":"<<minute<<":"<<sec<< endl;}private: int hour;int minute;int sec;};Time t;int main(){();();return 0;}3:#include <iostream>using namespace std;class Time{public:void set_time(void);void show_time(void);private:int hour;int minute;int sec;};void Time::set_time(void){cin>>hour;cin>>minute;cin>>sec;}void Time::show_time(void){cout<<hour<<":"<<minute<<":"<<sec<< endl;}Time t;int main(){ ();();return 0;}4://#include <iostream>using namespace std;#include ""int main(){Student stud;();();return 0;}//(即#include "" //在此文件中进行函数的定义#include <iostream>using namespace std; //不要漏写此行void Student::display( ){ cout<<"num:"<<num<<endl;cout<<"name:"<<name<<endl;cout<<"sex:"<<sex<<endl;}void Student::set_value(){ cin>>num;cin>>name;cin>>sex;}5://#include <iostream>#include ""int main(){Array_max arrmax;();();();return 0;}//#include <iostream>using namespace std;#include ""void Array_max::set_value() { int i;for (i=0;i<10;i++)cin>>array[i];}void Array_max::max_value() {int i;max=array[0];for (i=1;i<10;i++)if(array[i]>max) max=array[i]; }void Array_max::show_value() {cout<<"max="<<max<<endl; }6:解法一#include <iostream>using namespace std;class Box{public:void get_value();float volume();void display();public:float lengh;float width; float height;};void Box::get_value(){ cout<<"please input lengh, width,height:";cin>>lengh;cin>>width;cin>>height;}float Box::volume(){ return(lengh*width*height);}void Box::display(){ cout<<volume()<<endl;}int main(){Box box1,box2,box3;();cout<<"volmue of bax1 is "; ();();cout<<"volmue of bax2 is "; ();();cout<<"volmue of bax3 is "; ();return 0;}解法二:#include <iostream>using namespace std;class Box{public:void get_value();void volume();void display();public:float lengh;float width;float height;float vol;};void Box::get_value(){ cout<<"please input lengh, width,height:";cin>>lengh;cin>>width;cin>>height;}void Box::volume(){ vol=lengh*width*height;}void Box::display(){ cout<<vol<<endl;}int main(){Box box1,box2,box3;();();cout<<"volmue of bax1 is "; ();();();cout<<"volmue of bax2 is "; ();();();cout<<"volmue of bax3 is "; ();return 0;}。
面向对象软件工程答案
面向对象软件工程答案【篇一:软件工程考试试题与答案】txt> 一、单项选择题1.好的软件结构应该是()a.低耦合、低内聚b.高耦合、高内聚c.高耦合、低内聚d.低耦合、高内聚答案: d2.需求分析中开发人员要从用户那里了解()a.软件的规模b.软件做什么c.用户使用界面d.输入的信息答案: b3.软件调试技术包括()a.演绎法b .循环覆盖c .边界值分析 d .集成测试答案: a4.软件需求规格说明书的内容不应包括对()的描述。
a.用户界面及运行环境b .主要功能c .算法的详细过程 d .软件的性能答案: c5.常用动词或动词词组来表示()a.属性b.关联c.类d.对象答案: b6.软件可行性研究实质上是要进行一次()需求分析、设计过程。
a.详细的b.深入的c.彻底的d.简化、压缩的答案: d7.软件部分的内部实现与外部可访问性分离,这是指软件的()a.继承性b.共享性c.抽象性d.封装性答案: d8.软件部分的内部实现与外部可访问性分离,这是指软件的()a.共享性b.继承性c.抽象性d.封装性答案: d9.在详细设计阶段,经常采用的工具有()a.pdlb. dfdc.scd.sa答案: a10.数据字典是对数据定义信息的集合,它所定义的对象都包含于()a.软件结构b .程序框图c .方框图d .数据流图答案: d11.软件工程结构化生命周期方法,提出将软件生命周期划分为计划、开发和运行三个时期,下述()工作应属于软件开发期的内容。
a.问题定义b.可行性研究c.都不是d.总体设计答案: d12 .应用执行对象的操作可以改变该对象的()a.功能b .数据c .属性d .行为答案: c13 .软件质量因素不包括()a.可理解性b .可测试性 c .正确性 d .高性能答案: d14 .软件可行性研究实质上是要进行一次()需求分析、设计过程。
a.详细的b .彻底的c .深入的d .简化、压缩的答案: d15 .结构化设计是一种面向()的设计方法。
软件工程第1-2章课后习题参考答案
第一章课后参考答案1.什么是软件危机?它们有哪些典型表现?为什么会出现软件危机?“软件危机”是指计算机软件的“开发”和“维护”过程中所遇到的一系列“严重问题”。
这些问题决不仅仅是不能正常运行的软件才具有的,实际上,几乎“所有软件”都不同程度地存在这些问题。
“软件危机”包含两方面的问题:(1)如何开发软件,以满足对软件日益增长的需求;(2)如何维护数量不断膨胀的已有软件。
它们有以下表现:(1)对软件开发成本和进度的估计常常很不准确;(2)用户对“已完成的”软件系统不满意的现象经常发生;(3)软件产品的质量往往靠不住;(4)软件常常是不可维护的;(5)软件通常没有适当的文档资料;(6)软件成本在计算机系统总成本中所占的比例逐年上升;(7)软件开发生产率提高的速度,远远跟不上计算机应用普及深入的趋势。
出现软件危机的原因(1)开发人员与客户认识之间的矛盾(2)开发人员能力与开发目标之间的矛盾(3)预估与实际工作量之间的矛盾(4)客户认识的提高与软件维护之间的矛盾(5)遗产系统与实施软件之间的矛盾2.假设自己是一家软件公司的总工程师,当把图1.1给手下的软件工程师们观看,告诉他们及时发现并改正错误的重要性时,有人不同意这个观点,认为要求在错误进入软件之前就清楚它们是不现实的,并举例说:“如果一个故障是编码错误造成的,那么,一个人怎么能在设计阶段清除它呢?”应该怎么反驳他?答:在软件开发的不同阶段进行修改付出的代价是很不相同的,在早期引入变动,涉及的面较少,因而代价也比较低;在开发的中期,软件配置的许多成分已经完成,引入一个变动要对所有已完成的配置成分都做相应的修改,不仅工作量大,而且逻辑上也更复杂,因此付出的代价剧增;在软件“已经完成”是在引入变动,当然付出的代价更高。
一个故障是代码错误造成的,有时这种错误是不可避免的,但要修改的成本是很小的,因为这不是整体构架的错误。
3.什么是软件工程?它有哪些本质特征?怎么用软件工程消除软件危机?软件工程是知道计算机软件开发和维护的一门工程学科。
面向对象分析与设计(第二版)习题答案
面向对象分析与设计(第二版)习题答案第一章:面向对象基础知识1.1 什么是面向对象分析和设计?面向对象分析和设计(Object-Oriented Analysis and Design,OOAD)是软件工程中一种常用的方法论,通过将问题领域进行建模,通过对象、类、继承、封装等概念来描述现实世界中的实体、关系和行为。
面向对象分析和设计的目标是开发出可复用、可维护、可扩展、高质量的软件系统。
1.2 面向对象分析和设计的优势有哪些?面向对象分析和设计有以下优势: - 高度模块化:通过将系统划分为多个独立的对象,便于理解和设计系统的各个部分。
- 可复用性:面向对象设计强调对象的复用,通过定义通用的类和接口,可以提高代码的复用程度。
- 可维护性:面向对象的封装特性使得系统的各个部分具有独立性,便于维护和修改。
- 可扩展性:通过继承和多态等特性,可以方便地扩展和修改系统的功能。
- 高可靠性:面向对象的封装和隐藏特性可以减少系统中的错误和安全漏洞。
- 开发效率高:面向对象的分析和设计提供了一种更自然的思考和描述问题的方法,可以提高开发效率。
第二章:面向对象建模2.1 对象的特征有哪些?对象具有以下特征: - 状态(State):对象的状态是对象的属性值的集合,表示对象的某个时刻的状态。
- 行为(Behavior):对象可以执行的操作,描述了对象能够做什么。
- 身份(Identity):每个对象都有唯一的身份,可以通过身份来区分不同的对象。
2.2 类和对象之间的关系有哪些?类和对象之间有以下关系: - 实例化(Instantiation):类是对象的模板,对象是类的一个具体实例。
- 继承(Inheritance):一个类可以继承另一个类的属性和方法。
- 聚合(Aggregation):一个类可以包含其他类的对象作为成员变量。
- 关联(Association):两个类之间存在某种关系,一个类的对象可以访问另一个类的对象。
软件工程第一二三章习题参考答案
请问:
(1)为什么鲍曼拆下存储器就能摆脱计算机的干扰而独自控制宇宙飞船?我们现在遇到的软件问题有这么严重吗?
(2)如果不依靠飞行指挥中心,鲍曼怎样才知道HAL的故障预报有问题?
(3)应该怎样设计计算机系统,才能避免出现故事中描述的这类问题?
3.什么是软件工程?它有哪些本质特性?怎样用软件工程消除(至少是缓解)软件危机?
答:软件工程是指导计算机软件开发和维护的一门工程学科。采用工程的概念、原理、技术和方法来开发和维护软件,把经过时间考验而证明正确的管理技术和当前够得到的最好的技术方法结合起来,以经济地开发出高质量的软件并有效地维护它。
软件工程本质特性:1)软件工程关注于大型程序的构造;2)软件工程的中心课题是控制复杂性;3)软件经常变化;4)开发软件的效率非常重要;5)和谐地合作是开发软件的关键;6)软件必须有效地支持它的用户;7)在软件工程领域中是由具有一种文化背景的人替具有另一种文化背景的人创造产品。
消除软件危机的途径:为了消除软件危机,首先应该对计算机软件有一个正确的认识。必须充分认识到软件开发不是某种个体劳动的神秘技巧,而应该是一种组织良好、管理严密、各类人员协同配合、共同完成的工程项目。应该推广使用在实践中总结出来的开发软件的成功的技术和方法,并且研究探索更好更有效的技术和方法,尽快消除在计算机系统早期发展阶段形成的一些错误概念和做法。应该开发和使用更好的软件工具。为了解决软件危机,既要有技术措施(方法和工具),又要有必要的组织管理措施。
软件工程第一二三章习题参考答案
人怎么能在设计阶段清除它呢?”你怎么反驳他?
答:在软件开发的不同阶段进行修改付出的代价是很不相同的,在早期引入变动,涉及的面较少,因而代价也比较低;在开发的中期,软件配置的许多成分已经完成,引入一个变动要对所有已完成的配置成分都做相应的修改,不仅工作量大,而且逻辑上也更复杂,因此付出的代价剧增;在软件已经完成时再引入变动,当然付出的代价更高。一个故障是代码错误造成的,有时这种错误是不可避免的,但要修改的成本是很小的,因为这不是整体构架的错误。
面向对象软件工程(使用UML,模式与Java)全套课后习题答案
Advantages:
• Developers need only learn one notation for all development activities. • Traceability among models and between models and code is made easier since they are written in the same
The first decision is a system design decision. The second decision is also a system design decision if made by developers (otherwise, it is a requirements decision). The third decision is a requirements decision.
notation.
Disadvantages:
• A programming language is a low level notation which is difficult to use for representing user requirements, for example.
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Object-Oriented Software Engineering: Using UML, Patterns, and Java: Solutions to Exercises2. Modeling with UML: Solutions2-1Consider an ATM system. Identify at least three different actors that interact with this system. An actor is any entity (user or system) that interacts with the system of interest. For an ATM, this includes:•Bank Customer •ATM Maintainer•Central Bank Computer •ThiefThe last actor is often referred to as a “misactor” in the literature, because it is an actor that interacts with the system but shouldn’t.2–2Can the system under consideration be represented as an actor? Justify your answer.The system under consideration is not external to the system and shouldn’t be represented as an actor. There are a few cases, however, when representing the system as an actor may clarify the use case model. These include situations where the system initiates uses cases, for example, as time passes (Check for Outdated Articles, Send Daily Newsletter).2–3What is the difference between a scenario and a use case? When do you use each construct?A scenario is an actual sequence of interactions (i.e., an instance) describing one speci fic situation; a use case is a general sequence of interactions (i.e., a class) describing all possible scenarios associated with a situation. Scenarios are used as examples and for clarifying details with the client. Use cases are used as complete descriptions to specify a user task or a set of related system features.2–4Draw a use case diagram for a ticket distributor for a train system. The system includes two actors: a traveler,who purchases different types of tickets, and a central computer system, which maintains a reference database for the tariff. Use cases should include: BuyOneWayTicket , BuyWeeklyCard , BuyMonthlyCard , UpdateTariff .Also include the following exceptional cases: Time-Out (i.e., traveler took too long to insert the right amount), TransactionAborted (i.e., traveler selected the cancel button without completing the transaction), DistributorOutOfChange , and DistributorOutOfPaper .Figure 2-1Example solution to Exercise 2–4.BuyOneWayTicketBuyWeeklyCardUpdateTariff TransactionAbortedDistributorOutOfChangeDistributorOutOfPaperDistributorException<<extend>><<extend>><<extend>>Object-Oriented Software Engineering: Using UML, Patterns, and Java: Solutions to ExercisesThis questions can have several correct answers, Figure 2-1 being a possible answer. The following elements should be present:•The relationship between an actor and a use case is a communication relationship (undirected solid line).•The relationship between exceptional use cases and common use cases is an <<extend>> relationship.•The exceptional use cases described in the exercise only apply to the use cases invoked by the traveler.The following elements should be present in a “good” answer:•All exceptions apply to all traveler use cases. Instead of drawing 3x4 relationships between these use cases, an abstract use case from which the exceptional use case inherit can be used, thus reducing the number of<<extend>> relationships to 3 at the cost of introducing 4 generalization relationships.•The student can introduce exceptional use cases not specified in the exercise that apply to the CentralComputerSystem use cases.2–5Write the flow of events and specify all fields for the use case UpdateTariff that you drew in Exercise 2–4. Do not forget to specify any relationships.Figure 2-2 depicts a possible solution for this exercise.Use case name UpdateTariffParticipating actor Initiated by CentralComputerSystemFlow of events 1.The CentralComputerSystem activates the “UpdateTariff” function of the ticket distributors available on the network.2.The ticket distributor disables the traveler interface and posts a sign indicatingthat the ticket distributor is under maintenance.3.The ticket distributor waits for the new database from theCentralComputerSystem.4.After waiting a minute for the ticket distributors to reach a waiting state, the CentralComputerSystembroadcasts the new database.5.The ticket distributor system receives the new database of tariff. Upon complete,the ticket distributor sends an acknowledgement to the CentralComputerSystem.6.After acknowledgment, the ticket distributor enables the traveler interface andcan issue tickets at the new tariff.7.The CentralComputerSystem checks if all ticket distributors have acknowledged the new database. Ifnot, the CentralComputerSystem invokes the CheckNonRespondingDistributors use case.Entry condition•The ticket distributor is connected to a network reachable by the CentralComputerSystem.Exit condition•The ticket distributor can issue tickets under the new tariff, OR•The ticket distributor is disabled and displays a sign denoting that it is under maintenance.Quality•The ticket distributor stays offline at most 2 minutes and is considered out-of-order otherwise. requirementsFigure 2-2 A possible solution for the UpdateTariff use case.Object-Oriented Software Engineering: Using UML, Patterns, and Java: Solutions to Exercises2–6Draw a class diagram representing a book defined by the following statement: “A book is composed of a number of parts, which in turn are composed of a number of chapters. Chapters are composed of sections.”Focus only on classes and relationships.Figure 2-4Example solution for Exercise 2–8.This exercise checks the student’s understanding of basic aspects of object diagrams, including:Object-Oriented Software Engineering: Using UML, Patterns, and Java: Solutions to Exercises•Objects are represented with rectangles and underlined labels.•The class of an object is included in the label of the object (e.g., uml:Chapter is of class Chapter).•Links are represented with solid lines2–9Extend the class diagram of Exercise 2–6 to include the following attributes:• a book includes a publisher, publication date, and an ISBN• a part includes a title and a number• a chapter includes a title, a number, and an abstract• a section includes a title and a numberFigure 2-6Example solution for Exercise 2–10.This exercise checks the student’s knowledge of abstract classes and inheritance.2–11Draw a class diagram representing the relationship between parents and children. Take into account that a person can have both a parent and a child. Annotate associations with roles and multiplicities.Figure 2-7 depicts a canonical solution. This exercise is meant to emphasize the difference between a relationship, a role, and a class. In the above sentence, parent and child are roles while person is the class under consideration. This results in a class diagram with a single class and a single association with both ends to the class.Object-Oriented Software Engineering: Using UML, Patterns, and Java: Solutions to Exercises A common modeling mistake by novices is to draw two classes, one for the parent and one for the child.2–12Draw a class diagram for bibliographic references. Use the references in Appendix C, Bibliography, to testyour class diagram. Your class diagram should be as detailed as possible. The domain of bibliographic references is rich and complex. Consequently, students should deepened theirunderstanding of the domain before they attempt to draw a class diagram (similar to the requirements analysis of a system). Figure 2-8 depicts an incomplete sample solution that could be accepted as suf ficient from an instructor. The class diagram should minimally include the following concepts:•An abstract class Publication (or BibliographicReference )• A many to many relationship between Author and Publication •At least three or more concrete classes re fining Publication•At least one aggregation relationship (e.g., between Journal and Article or Proceedings and ConferencePaper ). Both ends of the aggregation should also be subclasses of Publication .2–13Draw a sequence diagram for thewarehouseOnFire scenario of Figure 2-15. Include the objects bob , alice ,john , FRIEND , and instances of other classes you may need. Draw only the first five message sends.Figure 2-7Example solution for Exercise 2–11.Figure 2-8Example solution for Exercise 2–12.Person parentchild *2Object-Oriented Software Engineering: Using UML, Patterns, and Java: Solutions to ExercisesThis exercise checks the student’s knowledge of sequence diagrams when using instances. This exercise can have several correct answers. In addition to the UML rules on sequence diagrams, all correct sequence diagrams for this exercise should include one or more actors on the left of the diagram who initiate the scenario, one or more objects in the center of the diagram which represent the system, and a dispatcher actor on the right of the diagram who isnotified of the emergency. All actors and objects should be instances. Figure 2-9 depicts a possible answer.Figure 2-11 is an example solution for this exercise. The following elements should be present in the solution:•Activity names should be verb phrases indicating what the initiating actor is attempting to accomplish. Roles should be indicated with swimlanes•Activities that are concurrent or which do not need to happen in a sequential order should be indicated with complex transitions.2–16Add exception handling to the activity diagram you developed in Exercise 2–15. Consider at least three exceptions (e.g., delivery person wrote down wrong address, deliver person brings wrong pizza, store out of anchovies).This exercise checks the student’s knowledge of decision points. Figure 2-12 depicts an example solution. Students modeling a realistic example will also think about cascaded exceptions and learn to represent them with multiple decision points.2–17Consider the software development activities which we described in Section 1.4. Draw an activity diagram depicting these activities, assuming they are executed strictly sequentially. Draw a second activity diagram depicting the same activities occurring incrementally (i.e., one part of the system is analyzed, designed, implemented, and tested completely before the next part of the system is developed). Draw a third activity diagram depicting the same activities occurring concurrently.This exercise tests the student’s knowledge of the activity diagram syntax, not the knowledge of software engineering activities. In the sample solution provided in Figure 2-13, we assumed that requirements elicitation need to be completed before any subsystem decomposition can be done. This leads to a splitting of the flow of control in the third diagram where all remaining activities occur concurrently. The instructor could accept a solution where requirements elicitation also occurs incrementally or concurrently with the other development activities.Figure 2-11An example of pizza order activity diagram with exception handling.Figure 2-12An example of pizza order activity diagram.Requirements ElicitationSystemDesignObjectDesignAnalysis ImplementationRequirements ElicitationSystemDesign 1ObjectDesign 1Analysis 1SystemDesign 2ObjectDesign 2Analysis 2Implementation1Implementation2SystemDesign 3ObjectDesign 3Analysis 3Implementation3Sequential activitiesIncremental activitiesConcurrent activitiesFigure 2-13Example solution for Exercise 2–17.。