

Intro to Computers and C++ 1

Objectives
In this chapter, you’ll:
◼ Learn computer hardware, software and Internet basics.
◼ Understand a data hierarchy from bits to databases.
◼ Understand the types of programming languages.
◼ Understand thestrengths of C++ and other languages.
◼ Beintroduced to the C++ standard library of reusable components.
◼ Compile andrun aC++ application using our three preferred compilersand Docker containers.
◼ Beintroducedtoobjecttechnologyconceptsusedin theobjects-naturalcasestudies (Chapters2–9)anddiscussed indetailin the object-oriented programmingChapters 9–11.
◼ Understand how concurrent programminghelps maximize performance on multi-core processors.
◼ Beintroduced to big dataand datascience.
◼ Learn about exciting recent developments in computing, including the Metaverse, artificial intelligence and related technologies.
Exercises
1.1 Categorizeeachofthefollowingitemsaseitherhardwareor software:
a) CPU.
Answer: Hardware.
b) C++ compiler. Answer: Software.
c) ALU.
Answer: Hardware.
d) C++ preprocessor.
Answer: Software.
e) input unit.
Answer: Hardware.
f) an editor program.
Answer: Software.
1.2 (Computer Organization) Fill in the blanks in each of the following statements:
a) Thelogicalunitthatreceivesinformationfromoutsidethecomputerforuseby the computer is the .
Answer:inputunit.
b) is thelogicalunitthatsendsinformation thecomputerhas already processed to various devicesfor use outside the computer.
Answer: output unit.
c) and arethecomputer’slogicalunitsthatretaininformation. Answer: memory unit, secondary storage unit.
d) is the computer’s logical unit for performing calculations. Answer: ALU.
e) isthecomputer’s logicalunit formaking logicaldecisions. Answer: ALU.
f) isthecomputer’slogicalunitforcoordinatingthe otherlogicalunits’ activities.
Answer: CPU.
1.3 Discuss the purpose of each of the following:
a) cin
Answer: cin (the standard inputstream),which is normally thekeyboard,but cin canbeconnectedtoanotherstream.
b) cout
Answer:Dataisoftenoutputto cout(thestandardoutputstream),whichisnormally the computer screen, but cout can be connected to another stream.
c) cerr
Answer: The standard error stream is referred to as cerr The cerr stream (normallyconnectedtothescreen)isusedfordisplayingerrormessages.It’scommon to route regular output data, i.e., cout, to a device other than the screen while keeping cerr assigned to the screen so thatthe usercan be immediately informed of errors.
1.4 Fillin the blanks in each of the following statements:
a) Information in the computer’s memory unit is it’s typically lost when the computer’s power is turned off.
Answer: volatile.
b) As a measure of computer memory size, TB stands for which is 1024 gigabytes.
Answer: terabyte.
c) Most computers today have processors that economically implement multiple processors on a single integrated circuit chip.
Answer: multi-core.
d) enable concurrent programming with a simple sequential like coding style.
Answer: Coroutines.
e) The most popular database model is the database inwhich data is stored in simple tables of rows and columns.
Answer: relational.
f) is the process of searching through extensive collections of data to find valuable insights.
Answer: Data mining.
g) With software individuals contribute to developing, maintaining and evolvingthesoftware.Anyonecan thenuse thatsoftwarefortheirownpurposes normallyatnocharge,butsubjecttovarious(typicallygenerous)licensing requirements.
Answer: open-source.
h) Today, mostof the code for general-purpose operating systems is written in . Answer:CorC++.
i) The C++ programming models are , , , ,
Answer:proceduralprogramming,object-orientedprogramming,functional-style programming, generic programming and template metaprogramming.
j) Existing older C++ code using older coding idioms is called code. Answer: legacy.
k) When writing new software avoid Insteaduseexistingpiecesfrom code libraries.
Answer:“reinventing thewheel.”
l) Microsoft’s primary language for the Metaverse is Answer: C#.
m) The thatobjectscomefromareessentiallyreusablesoftwarecomponents.
Answer: classes.
n) TheprotocolforcommunicatingovertheARPANETbecameknownasthe
Answer: Transmission Control Protocol (TCP).
o) TCPensuredthatmessages,consistingofsequentiallynumberpiecescalled wereproperlydeliveredfrom sender to receiver, arrived intactand were reassembled in the correct order.
Answer: packets.
p) In the Internet of Things (IoT) a "thing" is any device with a(n) and theability to send,and insomecases receive, data automaticallyover the Internet.
Answer: IP address.
q) The applications-development methodology of enables you to rapidly developpowerful software applications by combining (often free) complementarywebservicesandvariousformsofinformationfeeds.
Answer: mashups.
r) typicallyreferstosimulated,3Denvironmentsthatyouinteractwith.
Answer: Virtual reality (VR).
s) isasoftware-based ledgerdistributedovernodesontheInternet.
Answer: Blockchain.
t) A is adigitalorvirtualcurrency securedbycryptography.
Answer: cryptocurrency.
u) are blockchain-based “cryptographically unique tokens linked to digital or physical content, providing proof of ownership.”
Answer: Non-fungible tokens.
v) is by far the mostwidely used version controlsystem.
Answer: GitHub.
w) The "four Vs of big data are , , , and Answer: Volume, Velocity, Variety and Veracity.
x) Somepeople feelthatthe ultimateproblemto be solved in AIis Answer: artificial general intelligence.
y) ChatGPT is a shining example of the field of . Answer: generative AI.
1.5 Statewhichofthefollowingaretrueandwhichare false.Iffalse,explainwhy.
a) Computingcostsaredroppingrapidlyduetoimpressivedevelopmentsinhardware, software and Internet technologies.
Answer: True.
b) Fordecades,computerpowerapproximatelydoubled inexpensivelyeveryyear. This remarkable trend is called Moore’s law.
Answer: False. It doubled approximately every two years.
c) Takingfulladvantageofmulti-corearchitecturerequireswritingmultithreaded applications.
Answer: True.
d) Anycomputer can directly understand only its ownassembly language. Answer:False.Actually,anycomputercandirectlyunderstandonlyisownmachine language.
e) Thesoftware thatcontains the coreoperating-systemcomponents is called the kernel.
Answer: True.
f) iOS is the most widely used mobile-phone operating system.
Answer: False. It’s Android.
g) C++ isthepremiere language forbuildinghigh-performance business-critical and mission-critical operating systems.
Answer: True.
h) Theprogramminglanguagemostcloselyassociatedwiththeexpression“write once, run anywhere” is Java.
Answer: True.
i) Swiftiswidelyusedtoaddprogrammabilitytowebpages,suchasanimations and user interactivity.
Answer: False. Actually, it’s JavaScript.
j) AstheARPANETevolved,toenable thehugevarietyofnetworkinghardware and software to intercommunicate, ARPA developed the Internet Protocol (IP), which created a true “network of networks.”
Answer: True.
k) Cloud computing allows you to increase or decrease computing resources to meet your needs at any given time.
Answer: True.
l) IoT is an example of edge computing.
Answer: True.
m) Augmented reality (AR) projects real-time computer-generated contentonto what you see in the real world.
Answer: True.
n) Ethereum is a programmable platform that enables you to “build and deploy decentralized applications (dApps) on its network that use the blockchain to store data or control what your app can do.”
Answer: True.
o) ForbesdefinesWeb3as “thecentralizedInternet builtondistributed technologies like blockchain ... rather than on servers owned by individualsor corporations.”
Answer: False. Actually, it’s the "decentralized Internet."
p) Bysomeestimates,processingjustoneBitcointransactionusesapproximately thesameamountofenergyaspoweringtheaverageAmericanhomeforone month.
Answer: False. Actually, it’s one week.
q) AI is often called a field with solutions but no problems.
Answer: False. Actually it’s often called a field with problems and no solutions.
r) In machine learning, computers are explicitly programmed with human expertise to solve a particular problem.
Answer:False.Actuallywithmachinelearning,computersareprogrammedto learn from data.
s) OpenAI’sDall-E2cangenerateoriginalimagesfromtextdescriptions.
Answer: True.
1.6 (Clock as an Object) Clocksareamongtheworld’s mostcommonobjects.Discuss howeachofthefollowingtermsandconceptsappliestothenotionofaclock:class, object,
© Copyright 1992-2023 by Pearson Education, Inc. All Rights Reserved.
instantiation, data member, reuse, member function, inheritance (consider, for example, analarmclock),baseclassandderivedclass.
Answer:Theentirewatchisanobjectthatiscomposedofmanyotherobjects (suchasthemovingparts,theband,theface,etc.)Watchattributesaretime, color,band,style(digitaloranalog),etc.Thebehaviorsofthewatchinclude settingthetimeandgettingthetime.Awatchcanbeconsideredaspecifictype of clock (ascananalarmclock). With thatin mind, itis possible thataclass called Clockcouldexistfromwhichotherclassessuchaswatchandalarmclock couldinheritthebasicfeaturesintheclock.Thewatchisanabstractionofthe mechanics needed to keep track of the time. The user of the watch does not needtoknowthemechanicsofthewatchinordertouseit;theuseronlyneeds toknowthatthewatchkeepsthepropertime.Inthissense,themechanicsof the watch are encapsulated (hidden) inside the watch. The interface to the watch (its faceand controls forsettingthe time) allows theuser to setand get thetime.Theuserisnotallowedtodirectlytouchtheinternalmechanicsofthe watch.Allinteractionwiththeinternalmechanicsiscontrolledbytheinterface to the watch. The data members stored in the watch are hidden inside the watchandthememberfunctions(lookingatthefacetogetthetimeandsetting the time) provide the interface to the data.
INSTRUCTOR NOTE: The remaining exercises in this chapter are research and thought exercises for which we do not provide answers.
1.7 (Self-Driving Cars) Just a few years ago, the notion of driverless vehicles on our streets would have seemed impossible. Many of the technologies you’ll read about in this bookaremakingself-drivingcarspossible.Today,they’realreadycommoninsomeareas.
a) Ifyou haileda taxiand adriverless taxistoppedfor you,wouldyou get into the back seat? Would you feel comfortable telling it where you want to go and trustingitwouldgetyouthere?Whatsafetymeasureswouldyouwantinplace?
b) Whatiftwoself-drivingcars approachedaone-lanebridge fromoppositedirections?Whatprotocolshouldtheygothroughtodeterminewhichcarshould proceed?
c) What if you’re behind acar stoppedat a red light, the lightturns green,and the car doesn’tmove?You honk, and nothing happens. You getoutof your car and notice that there’s no driver. What would you do?
d) Ifa police officer pullsovera speedingself-drivingcar inwhichyou’re the only passenger, who or what entity should pay the ticket?
e) One especially serious concern with self-driving vehicles is that they might be hacked.Whatifthehacker sets thespeedhigh(orlow),which couldbedangerous. What if the hacker locked all the doors then set the vehicle to drive off in the wrong direction?
1.8 (Research: Artificial General Intelligence) One of the most ambitious goals in the field of AI is to achieve artificial general intelligence the point at which machine intelligence would equal human intelligence. Research this intriguing topic. When is this forecasttohappen?Whataresomeethicalissues thisraises?Humanintelligenceseemstobe stableoverlongperiods.Powerfulcomputerswithartificialgeneralintelligencecouldcon-
© Copyright 1992-2023 by Pearson Education, Inc. All Rights Reserved.
ceivably (and quickly) evolve intelligence far beyond that of humans. Research and discuss the issues this raises.
1.9 (Research: Intelligent Assistants) Many companies now offer computerized intelligentassistants,suchas AmazonAlexa,AppleSiri,GoogleAssistantandMicrosoftCortana. Research these and others, and list uses that can improve people’s lives. Research privacy and ethics issues for intelligent assistants. Research intelligent-assistant anecdotes. Would you do what an intelligent assistant told you to?
1.10 (Research: AI in Health Care) Research the rapidly growing field of AI big-data applications in health care. For example, suppose a diagnostic medical application had access to every x-ray that’s ever been taken and the associated diagnoses that’s surely big data. “Deep Learning” computer-vision applications could work with this “labeled” data to learn to diagnose medical problems. Research deep learning in diagnostic medicine and list some of its most significant accomplishments. What are some ethical issues of having machinesinsteadofhumandoctorsperformingmedicaldiagnoses?Wouldyoutrustamachine-generated diagnosis? Would you seek a second opinion from another diagnostic machine? Would you insist on a second opinion from a human doctor?
1.11 (Research: Privacy and Data Integrity Legislation) Some key privacy laws areHIPAA (the Health Insurance Portability and Accountability Act) and the California Consumer Privacy Act (CCPA) both in the United States, and GDPR (the General Data ProtectionRegulation) in the European Union.Lawslike theseare becoming more commonandstricter. Investigatethese lawsand themajorprotections theyprovideforyour privacy.
1.12 (Research: Personally Identifiable Information) Protecting users’ personally identifiable information (PII) is an important aspectof privacy. Research and comment on this issue.
1.13 (Research: Big Data, AI and the Cloud How Companies Use These Technologies) Foramajor organizationofyourchoice, research howthey mightbeusingeach of the following technologies: AI, big data, the cloud, mobile, natural-language processing, speech recognition, speech synthesis, database, machine learning, deep learning, reinforcement learning, Internet of Things (IoT) and web services.
1.14 (Research: Raspberry Pi and the Internet of Things) It’s now possible to have a computer at the heart of just aboutany device and to connect those devices to the Internet. This has led to the Internet of Things (IoT), which is already connecting billions of devices.TheRaspberryPiis aneconomicalcomputer oftenatthe heartof IoT devices,and it can beprogrammed in C++.Researchthe Raspberry Pi and some of the many IoT applications in which it’s used.
1.15 (Research: The Ethics of Deep Fakes) Artificial intelligence deep-learning technologiesmake itpossible tocreate deepfakes realistic fakevideos ofpeoplethat capture their appearance, voice, body motions and facial expressions. You can have them say and do whatever you specify. Research the ethics of deep fakes. What would happen if you turned on your TV and saw a deep-fake video of a prominent government official or newscaster reporting that an attack was about to happen? A famous low-tech version of this was Orson Welles’s “War of the Worlds” radio broadcast of 1938, in which he created a mass panic by announcing that Martians were attacking New Jersey.
© Copyright 1992-2023 by Pearson Education, Inc. All Rights Reserved.
1.16 (Research: Blockchain A World of Opportunity) Cryptocurrencies like Bitcoin andEthereumarebasedonblockchaintechnology thathasseenexplosivegrowthoverthe lastfew years. Research blockchain’s origin, applications and how it came to be used as the basis for cryptocurrencies. Research other major applications of blockchain. It is expected thatblockchain technology willbe crucialto implementing theMetaverse.Over the next many years, there will be extraordinary opportunities for software developers who thoroughly understand blockchain application development.
1.17 (Public-Key Cryptography) Cryptography is a crucial technology for privacy and security. In this book, you’ll have the opportunity to study both secret-key and public-key cryptography.Research howpublic-key cryptography is used to implementtheBitcoin cryptocurrency.
1.18 (Programmer Responsibility and Liability) As a programmer working in the health-care industry, suppose a software bug in one of your programs caused a cancer patient to receive an excessive dose of radiation therapy resulting in severe injury or death. Discuss the issues.
1.19 (2010 “Flash Crash”) An example of the consequences of our dependency on computers was the so-called “flash crash,” which occurred on May 6, 2010, when the U.S. stock market fell precipitously in a matter of minutes, wiping out trillions of dollars of investments then recovered within minutes. Use the Internet to investigate the causes of this crash and discuss the issues it raises.