Solution manual for c how to program late objects version 7 e 7th edition paul deitel harvey deitel

Page 1

C++ How to Program: LateObjectsVersion,7/E

7th

Full chapter download at: https://testbankbell.com/product/solution-manual-for-c-howto-program-late-objects-version-7-e-7th-edition-paul-deitel-harvey-deitel/

Objectives

Inthis chapter you’ll learn:

■ Basic hardware andsoftware concepts.

■ The different types of programming languages.

■ A typical C++ program development environment.

■ The history ofthe Internet andthe World Wide Web, andthe Web2 0 phenomenon.

■ To test-drive C++ applications inGNU C++ on Linux andMicrosoft’s Visual C++® on Windows®.

■ Some basic object technology concepts.

© 2011 Pearson Education, Inc., Upper Saddle River, NJ. All Rights Reserved.

Self-Review Exercises

1.1 Fillin the blanks in each ofthe following:

a) The company that popularized personal computingwas .

ANS: Apple

b) The computer that made personal computing legitimate in business and industry was the

ANS: IBM Personal Computer

c) Computers process data under the control of sets of instructions called computer .

ANS: programs

d) The six key logical units of the computer are the , , , , and the

ANS: input unit, output unit, memoryunit, arithmeticand logic unit, centralprocessing unit, secondary storage unit.

e) The three typesof languages discussed in the chapter are , , and

ANS: machinelanguages, assembly languages, high-level languages.

f) The programsthat translatehigh-level language programs into machine language are called .

ANS: compilers.

g) C is widely known as the development language ofthe operating system.

ANS: UNIX.

h) The language was developed by Wirth for teachingstructuredprogramming.

ANS: Pascal

i) The Department of Defense developed the Ada language with a capabilitycalled , whichallows programmers to specify that manyactivities can proceed in parallel

ANS: multitasking.

j) , or labeling content, is another keypart of the collaborative theme of Web 2.0.

ANS: Tagging.

k) With Internet applications, the desktop evolvesto the .

ANS: webtop.

l) involves reworking codeto makeit clearer and easier to maintain while preserving itsfunctionality.

ANS: Refactoring.

m) With development, individuals and companies contributetheir efforts in developing, maintainingand evolving software in exchange for the right to use that software fortheir own purposes, typically at no charge

ANS: open source.

n) are used to match specificcharacter patterns in text Theycanbe used to validate data to ensure that it is in a particular format, to replace parts of one string with another, or to split a string

ANS: Regular expressions.

1.2 Fillin the blanks in each ofthe following sentences about the C++ environment.

a) C++ programs arenormally typedinto a computerusing a(n) program.

2 Chapter1 Introduction to Computers,the Internet and the World Wide Web: Exercises 2 © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All Rights Reserved. NJ. All Rights
3 Chapter1 Introduction to Computers,the Internet and the World Wide Web: Exercises 3 © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All Rights Reserved. NJ. All Rights ANS: editor

b) In a C++system, a(n) programexecutes before the compiler’s translation phase begins

ANS: preprocessor.

c) The program combinesthe output of the compilerwith various library functions to producean executable program.

ANS: linker.

d) The programtransfers the executable programfromdisk to memory.

ANS: loader

1.3 Fillin the blanks in each ofthe following statements (based on Section 1.19):

a) Objects have the propertyof although objects mayknow how to communicate withoneanotheracrosswell-defined interfaces, they normally are not allowed to knowhowother objects areimplemented.

ANS: informationhiding.

b) C++programmers concentrate on creating , whichcontain data members and the member functions that manipulate those data members and provide servicesto clients.

ANS: classes.

c) Classes can have relationships with other classes These relationships are called .

ANS: associations

d) The process of analyzing and designing a system froman object-oriented point ofview iscalled

ANS: object-oriented analysisand design (OOAD).

e) OOD also takes advantage of relationships, where new classes of objects are derived by absorbing characteristics of existing classes then adding unique characteristics oftheir own

ANS: inheritance.

f) isa graphical language that allows people who design software systems to use an industry-standard notation to represent them.

ANS: The UnifiedModeling Language (UML).

g) The size,shape, color and weight ofanobject areconsidered ofthe object.

ANS: attributes

Exercises

1.4 Categorize each ofthe following itemsas eitherhardware or software:

a) CPU

ANS: hardware.

b) C++ compiler

ANS: software.

c) ALU

ANS: hardware.

d) C++ preprocessor

ANS: software.

e) input unit

ANS: hardware.

f) an editorprogram

4 Chapter1 Introduction to Computers,the Internet and the World Wide Web: Exercises 4 © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All Rights Reserved. NJ. All Rights
5 Chapter1 Introduction to Computers,the Internet and the World Wide Web: Exercises 5 © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All Rights Reserved. NJ. All Rights ANS: software

1.5 Why might you want to writea programin a machine-independent language insteadof a machine-dependent language? Why might a machine-dependent language be more appropriate for writing certain types of programs?

ANS: Machineindependent languages are useful for writingprograms to be executed on multiple computer platforms. Machine dependent languages are appropriate for writing programs to be executed on a single platform

1.6 Fillin the blanks in each ofthe following statements:

a) Which logical unit ofthe computer receives information fromoutside the computerfor use bythe computer? .

ANS: input unit.

b) The process of instructing the computer to solve specific problems is called .

ANS: computerprogramming.

c) What typeof computerlanguage uses English-like abbreviations formachine language instructions? .

ANS: assembly language

d) Which logical unit ofthe computersends informationthat has already beenprocessed by the computer to various devices so that the information may be used outside the computer? .

ANS: output unit

e) Which logicalunits ofthe computerretaininformation?

ANS: memory unit and secondary storage unit.

f) Which logical unit of the computerperforms calculations? .

ANS: arithmetic and logical unit.

g) Which logical unit ofthe computermakes logical decisions? .

ANS: arithmetic and logical unit

h) The level of computer language most convenient to the programmer for writingprograms quickly and easily is .

ANS: high-level language.

i) The only language that a computer directly understands is called that computer's

ANS: machine language.

j) Which logical unit ofthe computercoordinates the activities ofall the other logical units?

ANS: central processing unit.

1.7 Whyissomuch attention todayfocused on object-oriented programming?

ANS: Object-oriented programming enables the programmer to build reusable software components that model items in the real world. Building software quickly, correctly, and economically has been an elusive goal in the software industry The modular, object-oriented design and implementationapproachhas been found to increase productivity while reducing development time, errors, and cost

1.8 Distinguish between the terms fatal errorand nonfatalerror Why might you prefer to experience a fatal errorratherthan a nonfatalerror?

ANS: Afatal error causes aprogram to terminate prematurely Anonfatal error occurs when the logic of the program isincorrect, andthe program doesnot work properly Afatal error is preferred for debugging purposes A fatal error immediately lets you know

6 Chapter1 Introduction to Computers,the Internet and the World Wide Web: Exercises 6 © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All Rights Reserved. NJ. All Rights

there isa problemwith the program, whereas anonfatal errorcan be subtle and possibly goundetected.

1.9 Give a brief answer to each ofthe following questions:

6 Chapter1 Introduction to Computers,the Internet and the World Wide Web: Exercises 6 © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All Rights Reserved. NJ. All Rights

a) Whydoes thistextdiscussstructured programming in addition to object-oriented programming?

ANS: Objectsarecomposed in part ofstructured program pieces

b) What kinds of messages do people sendto one another?

ANS: Peoplesend messages through body language, speech, writings, e-mail,telephones, etc.

c) Objects send messages to one another across well-defined interfaces What interfaces does a carradio(object) present to itsuser (a person object)?

ANS: Dials andbuttons that allow the user to select astation, adjustthe volume, adjust bass and treble, play a CD or tape,etc.

1.10 (The Watch as an Object) You areprobably wearing on yourwrist one of the world’s most common types of objects a watch Discuss how each of the following terms and concepts applies to the notion of a watch: object,attributes, behaviors, class,inheritance (consider, for example, an alarm clock), encapsulation, interface, informationhiding,datamembers and member functions

ANS: The entire watch is an object that is composed of many other objects (such as the movingparts, the band, the face, etc.) Watch attributes aretime, color,band, style (digital or analog), etc The behaviors of the watchinclude setting the time and getting the time. A watch can be considered a specific type of clock(as can an alarm clock).With that in mind, it is possible that a class called Clock could existfrom which other classessuch aswatch and alarmclock could inherit the basic features of the clock. The watch is an abstraction of the mechanics neededto keeptrackof the time The user of the watch doesnot need to know the mechanics of the watch in order to use it; the useronlyneeds to know how to read the face of the watch and that the watchkeeps the proper time In this sense, the mechanics of the watchare encapsulated (hidden) inside the watch. The interface to the watch (itsface and controls for setting the time) allows the user to setand get the time. The useris not allowed to directly touch the internalmechanics ofthe watch Allinteraction with the internal mechanics is controlledby the interface to the watch. The data members stored in the watch arehidden inside the watchand the memberfunctions (looking at the face to getthe time and setting the time)provide the interface to the data.

1.11 Fillin the blanks in each ofthe following statements (based on Section 1.17):

a) The open source database management system used in LAMP development is

ANS: MySQL

b) Akey advantage of Software as a Service (SaaS) is .

ANS: When the servers are updated, all clients worldwide see the new capabilities; no local installation isneeded.

c) areproven architectures forconstructing flexible andmaintainable object-oriented software.

ANS: Design patterns

d) is the most popularopensource server-side“scripting” language fordevelopingInternet-based applications

ANS: PHP

Making a Difference

© 2011 Pearson Education, Inc., Upper Saddle River, NJ. All Rights Reserved. NJ. All Rights Making a Difference 5 5 Chapter1 Introduction to Computers,the Internet and the World Wide Web:

1.12 (Test Drive: Carbon Footprint Calculator) Somescientists believe that carbon emissions, especially from the burning of fossil fuels, contribute significantly to global warming and that this can becombatted if individuals take steps to limittheiruse of carbon-based fuels Organizations and individuals areincreasinglyconcerned about their “carbon footprints.” Websites such as TerraPass

© 2011 Pearson Education, Inc., Upper Saddle River, NJ. All Rights Reserved. NJ. All Rights Making a Difference 6 6 Chapter1 Introduction to Computers,the Internet and the World Wide Web:

www.terrapass.com/carbon-footprint-calculator/ and Carbon Footprint

www.carbonfootprint.com/calculator.aspx

provide carbon footprint calculators. Test drive these calculators to determine your carbon footprint Exercises in laterchapters will ask you to program yourown carbonfootprint calculator To prepare forthis, research the formulas forcalculating carbonfootprints.

1.13 (Test Drive: Body Mass Index Calculator) By recentestimates, two-thirds of the people in the United States are overweight and about half of those are obese. This causessignificant increases in illnesses such asdiabetes and heartdisease To determine whether aperson isoverweight orobese, youcanuse a measure called the bodymass index (BMI).The United States Department ofHealth and Human Servicesprovides a BMIcalculator at www.nhlbisupport.com/bmi/ Use it to calculate your ownBMI.An exercisein Chapter 2 will ask you to program your own BMIcalculator. To prepareforthis, research the formulas forcalculating BMI.

1.14 (Attributes of Hybrid Vehicles) In this chapteryoulearned the basics of classes. Now you’ll begin “fleshing out” aspects of a class called “Hybrid Vehicle.” Hybrid vehicles are becoming increasingly popular,because theyoften getmuch better mileage than purely gasoline-powered vehicles Browse the weband studythe features of four or five of today’s popular hybrid cars, then list as many oftheirhybrid-related attributes as youcan.Forexample, common attributesinclude citymiles-per-gallon and highway-miles-per-gallon. Also list the attributes of the batteries (type, weight, etc.).

ANS:

• Manufacturer

• Typeof Hybrid Battery hybrid(Hybrid Electric Vehicles), Plug-inhybrid,Fuelcell etc.

• Driverfeedback system so the driver canmonitor fuel efficiency based on their driving

• Energy recovery for example, regenerative breaking

• Carbon footprint tons ofCO2 per year

• Fuelcapacity

• City-miles-per-gallon

• Highway-miles-per-gallon

• Two-mode hybridpropulsion system

• Engine size V6, V8, etc.

• Vehicle type SUV, crossover, compact, mid-size, etc.

• Seating capacity

• Horse power

• Drivetrain (front wheel drive, all wheel drive)

• Top speed

• Torque

• Price

1.15 (Gender Neutrality) Manypeople wantto eliminate sexismin all forms ofcommunication. You’ve beenasked to create a program that can process a paragraph of textand replace gender-specific words with gender-neutralones Assuming that you’ve been given a list of gender-specific

© 2011 Pearson Education, Inc., Upper Saddle River, NJ. All Rights Reserved. NJ. All Rights Making a Difference 7 7 Chapter1 Introduction to Computers,the Internet and the World Wide Web:

words and their gender-neutral replacements (e g., replace “wife” by“spouse,” “man” by“person,” “daughter” by “child” and so on), explain the procedure you’d use to read through a paragraph of textand manually perform these replacements How might yourprocedure generate astrange term

© 2011 Pearson Education, Inc., Upper Saddle River, NJ. All Rights Reserved. NJ. All Rights Making a Difference 8 8 Chapter1 Introduction to Computers,the Internet and the World Wide Web:

like “woperchild?” In Chapter 3, you’ll learn that a more formal term for “procedure” is “algorithm,” and that an algorithm specifiesthe steps to beperformed and the orderin which to perform them.

ANS: Search through the entireparagraph fora wordsuch as“wife” and replace every occurrence with “spouse.” Repeat this searching process for every gender specific word in the list You couldaccidentally geta wordlike “woperchild” ifyouare not careful about how you performreplacements. For example, the word “man” can be part of a larger word, like “woman.” So, replacing everyoccurrenceof “man” can yield strange results.Consider the processof replacing “man” with “person” then replacing “son”with “child.” If you encounter the word “woman,” which contains the word “man,” you’d replace “man” with “person” resulting in the word “woperson.” In a subsequent pass you’d encounter“woperson” and replace “son” with “child” resultingin the “woperchild ”

© 2011 Pearson Education, Inc., Upper Saddle River, NJ. All Rights Reserved. NJ. All Rights Making a Difference 9 9 Chapter1 Introduction to Computers,the Internet and the World Wide Web:

Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.