Solution Manual for Visual C# How to Program, 6th Edition

Take the stress out of textbook problems with Solution Manual for Visual C# How to Program, 6th Edition, a complete guide to solving every question.

Zoe Jordan
Contributor
4.2
55
10 months ago
Preview (16 of 164 Pages)
100%
Log in to unlock

Page 1

Solution Manual for Visual C# How to Program, 6th Edition - Page 1 preview image

Loading page ...

1Introduction to Computers,the Internet and Visual C#O b j e c t i v e sIn this chapter you’ll:Learn basic computerhardware, software and dataconcepts.Be introduced to the differenttypes of computerprogramming languages.Understand the history of theVisual C# programminglanguage and the Windowsoperating system.Learn what cloud computingwith Microsoft Azure is.Understand the basics ofobject technology.Be introduced to the historyof the Internet and the WorldWide Web.Understand the parts thatWindows, .NET, VisualStudio and C# play in the C#ecosystem.Test-drive a Visual C#drawing app.

Page 2

Solution Manual for Visual C# How to Program, 6th Edition - Page 2 preview image

Loading page ...

Page 3

Solution Manual for Visual C# How to Program, 6th Edition - Page 3 preview image

Loading page ...

2Chapter 1Introduction to Computers, the Internet and Visual C#Self-Review Exercises1.1Fill in the blanks in each of the following statements:a)Computers process dataunder the control of sequences of instructions called.ANS:computer programs.b)A computer consists of various devices referred to as, such as the keyboard,screen, mouse, hard disks, memory, DVD drives and processing units.ANS:hardware.c)Data items processed by computers form a(n)that becomes larger and morecomplex in structure as we progress from the simplest data items (called “bits”) to richerdata items, such as characters, fields, and so on.ANS:data hierarchy.d)Computers can directly understand only theirlanguage, which is composedonly of 1s and 0s.ANS:machine.e)The three types of computer programming languages discussed in the chapter are ma-chine languages,and.ANS:assembly languages, high-level languages.f)Programs that translate high-level-language programs into machine language are called.ANS:compilers.g)A(n)processor implements several processors on a single “microchip”—adual-core processor has two CPUs and a quad-core processor has four CPUs.ANS:multicore.h)Windows 10 introduced thefor building Windows apps that run on desktopcomputers, notebook computers, tablets, phones, Xbox and even Microsoft’s newHoloLens augmented reality holographic headset—all using nearly identical code.ANS:Universal Windows Platform (UWP).1.2Fill in the blanks in each of the following statements:a)Objects, or more precisely thethat objects come from, are essentially reusablesoftware components.ANS:classes.b)You send messages to an object. Each message is implemented as a methodthattells a method of the object to perform its task.ANS:call.c)A new class of objects can be created quickly and conveniently by; the newclass absorbs the characteristics of an existing class, possibly customizing them and add-ing unique characteristics of its own.ANS:inheritance.d)To create the best solutions, you should follow a detailed analysis process for determin-ing your project’s(i.e., defining what the system is supposed to do) and de-veloping a design that satisfies them (i.e., deciding how the system should do it).ANS:requirements.e)Visual C# isdriven. You’ll write programs that respond to mouse clicks, key-strokes, timer expirations and touches and finger swipes.ANS:event.f)A key goal of Java is to be able to write programs that will run on a great variety of com-puter systems and computer-control devices. This is sometimes called.ANS:write once, run anywhere.1.3Fill in the blanks in each of the following statements:

Page 4

Solution Manual for Visual C# How to Program, 6th Edition - Page 4 preview image

Loading page ...

Self-Review Exercises3a)Theexecutes .NET programs.ANS:Common Language Runtime (CLR) of the .NET Framework.b)The CLR provides various services tocode, such as integrating software com-ponents written in different .NET languages, error handling between such components,enhanced security and more.ANS:managed.c)The ability of a program to run without modification across multiple platforms isknown as platform.ANS:independence.d)Visual Studio is a(n)in which C# programs are developed.ANS:IDE.e)You can sell your own Windows Phone apps in the.ANS:Windows Store.1.4State whether each of the following istrueorfalse. Iffalse, explain why.a)Software objects model both abstract and real-world things.ANS:True.b)The most popular database model is therelational databasein which data is stored insimpletables. A table includesrecordsandfields.ANS:True.c)A database is a collection of data that’s organized for easy access and manipulation.ANS:True.d)Secondary storage data takes much longer to access than data in primary memory, butthe cost per unit of secondary storage is much higher than that of primary memory.ANS:False: The cost per unit of secondary storage is much lower than that of primarymemory.e)High-level languages allow you to write instructions that look almost like everyday Eng-lish and contain commonly used mathematical expressions.ANS:True.f)An object has attributes that it carries along as it’s used in a program.ANS:True.g)The Transmission Control Protocol (TCP) ensures that messages, consisting of sequen-tially numbered pieces called bytes, were properly routed from sender to receiver, ar-rived intact and were assembled in the correct orderANS:False. The pieces are called packets, not bytes.h)The information-carrying capacity of communications lines on the Internet has in-creased tremendously, while hardware costs have increased.ANS:False. Hardware costs have decreased.i)You can build web-based apps with C# and Microsoft’s ASP.NET technology.ANS:True.j)Java has become the key programming language for the Mac OS X desktop operatingsystem and all iOS-based devices, such as iPods, iPhones and iPads.ANS:False. The language is Swift, not Java.k)Microsoft’s ASP.WEB technology is used to create web apps.ANS:False. It’s ASP.NET technology.l)Microsoft’s Windows operating system is the most widely used desktop operating sys-tem worldwide.ANS:True.1.5Arrange these byte measurements in order from smallest to largest: terabyte, megabyte,petabyte, gigabyte and kilobyte.ANS:kilobyte, megabyte, gigabyte, terabyte, petabyte.

Page 5

Solution Manual for Visual C# How to Program, 6th Edition - Page 5 preview image

Loading page ...

4Chapter 1Introduction to Computers, the Internet and Visual C#1.6Describe the two-step translation process for preparing your C# code to execute on yourparticular computer.ANS:C# code is first compiled into MSIL and placed in an executable file. When the appexecutes, another compiler called the JIT (just-in-time) compiler in the CLR trans-lates the MSIL in the executable file into machine-language code (for a particularplatform).Exercises1.7Fill in the blanks in each of the following statements:a)The programs that run on a computer are referred to as.ANS:softwareb)Systems such as smartphones, appliances, game controllers, cable set-top boxes and au-tomobiles that contain small computers are called.ANS:embedded systemsc)Just as characters are composed of bits,are composed of characters or bytes.ANS:fieldsd)Information on secondary storage devices is; it’s preserved even when thecomputer’s power is turned off.ANS:persistente)Translator programs calledconvert high-level language code into machine-language code.ANS:compilersf)In object-oriented programming languages, we create a program unit called a(n)to house the set of methods that perform its tasks.ANS:classg)Use a building-block approach to creating your programs. Avoid reinventing thewheel—use existing pieces wherever possible. Such softwareis a key benefitof object-oriented programming.ANS:reuse1.8Fill in the blanks in each of the following statements:a)Although many different OOAD processes exist, a single graphical language for com-municating the results ofanyOOAD process has come into wide use. This language,known as the, is now the most widely used graphical scheme for modeling ob-ject-oriented systems.ANS:UMLb)Tim Berners-Lee developed thefor sharing information via “hyperlinked”text documents on the web.ANS:HyperText Markup Language (HTML)c)The CLR is a(n)machine. It is software that manages the execution of pro-grams and hides from them the underlying operating system and hardware.ANS:virtuald)Converting a program to run on a different platform from which it was originally in-tended is called.ANS:porting.e)Microsoft’s Windowsis a cloud-computing platform that allows you to de-velop, manage and distribute your apps in the cloud.ANS:Azure. (Instructor Note: "Microsoft’s Windows" should be simply "Microsoft" inthis exercise.)

Page 6

Solution Manual for Visual C# How to Program, 6th Edition - Page 6 preview image

Loading page ...

Exercises5f)By using existing controls—which are objects—you can create powerful apps muchfaster than if you had to write all the code yourself. This is a key benefit of software.ANS:reuse1.9State whether each of the following istrueorfalse. Iffalse, explain why.a)The smallest data item in a computer can assume the value1or the value2. Such a dataitem is called abit(short for “binary digit”—a digit that can assume either oftwoval-ues).ANS:False. Such items have the value 0 or 1.b)The Unicode character set is a popular subset of ASCII that represents uppercase andlowercase letters, digits and some common special characters.ANS:False. ASCII is a subset of Unicode.c)Each of the following is a form of computer output: data displayed on screens, printedon paper, played as audio or video on PCs and media players, used to control other de-vices, such as robots, 3D printers and “intelligent” appliances.ANS:True.d)Reuse helps you build more reliable and effective systems, because existing classes andcomponents often have gone through extensive testing, debugging and performancetuning.ANS:True.e)One of the W3C’s primary goals is to make the web universally accessible to everyoneregardless of disabilities, language or culture.ANS:True.f)C# is available only on Microsoft Windows.ANS:False. There are ports of C# for other platforms, such as Linux.g)The .NET Framework Class Library has millions of valuable prebuilt classes that havebeen tested and tuned to maximize performance.ANS:False. Thousands, not millions, of prebuilt classes.h).NET programs can run on any platform.ANS:False. .NET prorgrams run on the Common Language Runtime, which is a virtualmachine.i)The Universal Windows Platform (UWP) is designed to provide a common platform(the underlying system on which apps run) and user experience across all of your devicesincluding personal computers, smartphones, tablets and Xbox Live.ANS:True.1.10What is a key advantage of interpreters over compilers? What is a key disadvantage?ANS:A key advantage is that interpreters can execute high-level language programs directly(without the need for compilation). A key disadvantage is that interpreted programsexexute more slowly than compiled programs.1.11What is the key advantage of using the newasyncfeature in preference to using old-stylemultithreading?ANS:The new features simplify asynchronous programming, because the compiler hidesmuch of the associated complexity from the developer.1.12What are operating systems?ANS:Operating systems are software systems that make using computers more convenientfor users, app developers and system administrators. They provide services that alloweach app to execute safely, efficiently and concurrently (i.e., in parallel) with otherapps.

Page 7

Solution Manual for Visual C# How to Program, 6th Edition - Page 7 preview image

Loading page ...

6Chapter 1Introduction to Computers, the Internet and Visual C#1.13Why is using cloud-computing resources sometimes preferable to purchasing all the hard-ware you need for your own computer?ANS:Cloud computing gives you the flexibility to increase or decrease computing resourc-es to meet your resource needs at any given time, making it more cost effective thanpurchasing expensive hardware to ensure that you have enough storage and process-ing power at their occasional peak levels.1.14Categorize each of the following items as either hardware or software:a)CPUANS:Hardware.b)CompilerANS:Softwarec)Input unitANS:Hardware.d)A word-processor programANS:Softwaree)A C# programANS:Software1.15Translator programs, such as assemblers and compilers, convert programs from one lan-guage (referred to as the source language) to another language (referred to as the target language).Determine which of the following statements aretrueand which arefalse:a)An assembler translates source-language programs into machine-language programs.ANS:True.b)High-level languages are generally machine dependent.ANS:False. A high-level language must be compiled into machine-dependent language be-fore it can be executed. This allows high-level languages to be used on all computerswith appropriate compilers.c)A machine-language program requires translation before it can be run on a computer.ANS:False. A machine-language program is native to a specific machine.d)The C# compiler translates high-level-language programs into SMIL.ANS:False. It translates C# into MSIL.1.16Expand each of the following acronyms:a)W3CANS:World Wide Web Consortiumb)OOPANS:Object-Oriented Programmingc)CLRANS:Common Language Runtimed)MSILANS:Microsoft Intermediate Languagee)UMLANS:Unified Modeling Languagef)IDEANS:Integrated Development Environment1.17What are the key benefits of the .NET Framework and the CLR? What are the drawbacks?ANS:The key benefits are portability between operating systems and interoperability be-tween languages. As long as a CLR exists for a platform, it can run any .NET pro-gram. Programmers can concentrate on program logic instead of platform-specificdetails. Thus, the double compilation (code-to-MSIL, and MSIL-to-machine code)allows for platform independence: Programs can be written once and executed on any

Page 8

Solution Manual for Visual C# How to Program, 6th Edition - Page 8 preview image

Loading page ...

Exercises7platform supporting the CLR—this is known as platform independence. Code writ-ten once could easily be used on another machine without modification, saving timeand money. A second benefit of the .NET framework is language interoperability—software components written in different languages can interact (language indepen-dence). A drawback associated with these features is that .NET programs cannot berun until the .NET Framework is developed for a platform. Another is the overheadof the double compilation that is needed before a .NET-language program can be ex-ecuted.1.18What are the advantages to using object-oriented techniques?ANS:Programs that use object-oriented programming techniques are easier to understand,correct and modify. The key advantage with using object-oriented programming isthat it tends to produce software that is more understandable, because it is better or-ganized and has fewer maintenance requirements than software produced with earliermethodologies. OOP helps the programmer build applications faster by reusing ex-isting software components that model items in the real world. OOP also helps pro-grammers create new software components that can be reused on future softwaredevelopment projects. Building software quickly, correctly, and economically hasbeen an elusive goal in the software industry. The modular, object-oriented designand implementation approach has been found to increase productivity while reduc-ing development time, errors, and cost.1.19You are probably wearing on your wrist 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 and behaviors.ANS:The entire watch is an object that is composed of many other objects (the movingparts, the band, the face, etc.) Watch attributes are time, color, band style, technology(digital or analog), and the like. The behaviors of the watch include setting the timeand getting the time. A watch can be considered a specific type of clock (as can analarm clock).1.20What is the key accomplishment of the UML?ANS:It replaced the many different graphical modeling languages with a single (unified)language for modeling that can be used by developers regardless of the differentOOAD processes they may use.1.21What did the chief benefit of the early Internet prove to be?ANS:Communication by e-mail. Today, that communication is also facilitated by appli-cations such as instant messaging and file transfer.1.22What is the key capability of the web?ANS:It allows computer users to locate and view multimedia-based documents on almostany subject over the Internet.1.23What is the key vision of Microsoft’s .NET initiative?ANS:To embrace the Internet and the web in the development and use of software.1.24How does the .NET Framework Class Library facilitate the development of .NET apps?ANS:First, the Framework Class Library is a large library of reusable classes that reducesdevelopment time. Programmers can build software quickly by reusing framework’sclasses, rather than building new classes “from scratch.” Second, the Framework ClassLibrary is shared by all of the .NET languages, which means that programmers whowork in multiple languages have to learn only one class library.

Page 9

Solution Manual for Visual C# How to Program, 6th Edition - Page 9 preview image

Loading page ...

8Chapter 1Introduction to Computers, the Internet and Visual C#1.25Besides the obvious benefits of reuse made possible by OOP, what do many organizationsreport as another key benefit of OOP?ANS:That OOP tends to produce software that is more understandable, better organized,and easier to maintain, modify and debug.Making-a-Difference ExercisesThe Making-a-Difference exercises will ask you to work on problems that really matter to individ-uals, communities, countries and the world.1.26(Test Drive: Carbon Footprint Calculator)Some scientists believe that carbon emissions,especially from the burning of fossil fuels, contribute significantly to global warming and that thiscan be combatted if individuals take steps to limit their use of carbon-based fuels. Various organi-zations and individuals are increasingly concerned about their “carbon footprints.” Websites suchas TerraPasshttp://www.terrapass.com/carbon-footprint-calculator-2/and Carbon Footprinthttp://www.carbonfootprint.com/calculator.aspxprovide carbon-footprint calculators. Test drive these calculators to determine your carbon foot-print. Exercises in later chapters will ask you to program your own carbon-footprint calculator. Toprepare for this, research the formulas for calculating carbon footprints.1.27(Test Drive: Body-Mass-Index Calculator)By recent estimates, two-thirds of the people inthe United States are overweight and about half of those are obese. This causes significant increasesin illnesses such as diabetes and heart disease. To determine whether a person is overweight or obese,you can use a measure called the body mass index (BMI). The United States Department of Healthand HumanServicesprovidesa BMIcalculator athttp://www.nhlbi.nih.gov/guidelines/obesity/BMI/bmicalc.htm. Use it to calculate your own BMI. An exercise in Chapter 3 will ask youto program your own BMI calculator. To prepare for this, research the formulas for calculating BMI.1.28(Attributes of Hybrid Vehicles)In this chapter you learned the basics of classes. Now you’llbegin “fleshing out” aspects of a class called “Hybrid Vehicle.” Hybrid vehicles are becoming increas-ingly popular, because they often get much better mileage than purely gasoline-powered vehicles.Browse the web and study the features of four or five of today’s popular hybrid cars, then list as manyof their hybrid-related attributes as you can. For example, common attributes include city-miles-per-gallon and highway-miles-per-gallon. Also list the attributes of the batteries (type, weight, etc.).ANS:ManufacturerType of Hybrid—Battery hybrid (Hybrid Electric Vehicles), Plug-in hybrid, Fuel cell etc.Driver feedback system—so the driver can monitor fuel efficiency based on their drivingEnergy recovery—for example, regenerative breakingCarbon footprint—tons of CO2per yearFuel capacityCity-miles-per-gallonHighway-miles-per-gallonTwo-mode hybrid propulsion systemEngine size—V6, V8, etc.Vehicle type—SUV, crossover, compact, mid-size, etc.

Page 10

Solution Manual for Visual C# How to Program, 6th Edition - Page 10 preview image

Loading page ...

Making-a-Difference Exercises9Seating capacityHorse powerDrive train (front wheel drive, all wheel drive)Top speedTorquePrice1.29(Gender Neutrality)Some people want to eliminate sexism in all forms of communication.You’ve been asked to create a program that can process a paragraph of text and replace gender-spe-cific words with gender-neutral ones. Assuming that you’ve been given a list of gender-specificwords and their gender-neutral replacements (e.g., replace “wife” with “spouse,” “man” withper-son,” “daughter” with “child” and so on), explain the procedure you’d use to read through a para-graph of text and manually perform these replacements. How might your procedure generate astrange term like “woperchild,” which is actually listed in the Urban Dictionary (www.urbandic-tionary.com)? In Chapter 5, you’ll learn that a more formal term for “procedure” is “algorithm,”and that an algorithm specifies the steps to be performed and the order in which to perform them.ANS:Search through the entire paragraph for a word such as “wife” and replace every oc-currence with “spouse.” Repeat this searching process for every gender specific wordin the list. You could accidentally get a word like “woperchild” if you are not carefulabout how you perform replacements. For example, the word “man” can be part ofa larger word, like “woman.” So, replacing every occurrence of “man” can yieldstrange results. Consider the process of 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 asubsequent pass you’d encounter “woperson” and replace “son” with “child” result-ing in the “woperchild.”

Page 11

Solution Manual for Visual C# How to Program, 6th Edition - Page 11 preview image

Loading page ...

2Introduction to Visual Studioand Visual ProgrammingO b j e c t i v e sIn this chapter you’ll:Learn the basics of the VisualStudio Community 2015Integrated DevelopmentEnvironment (IDE) forwriting, running anddebugging your apps.Create a new project usingVisual Studio’sWindowsForms Applicationtemplate.Be introduced to WindowsForms and the controls you’lluse to build graphical userinterfaces.Use key commandscontained in the IDE’s menusand toolbars.Understand the purpose ofthe various windows in theVisual Studio.Use Visual Studio’s helpfeatures.Use visual app developmentto conveniently create,compile and execute a simpleVisual C# app that displaystext and an image.

Page 12

Solution Manual for Visual C# How to Program, 6th Edition - Page 12 preview image

Loading page ...

2Chapter 2Introduction to Visual Studio and Visual ProgrammingSelf-Review Exercises2.1Fill in the blanks in each of the following statements:a)The technique ofallows you to create GUIs without writing any code.ANS:visual app development.b)A(n)is a group of one or more projects that collectively form a Visual C# app.ANS:solution.c)Thefeature hides a window in the IDE.ANS:auto-hide.d)A(n)appears when the mouse pointer hovers over an icon.ANS:tool tip.e)Thewindow allows you to browse solution files.ANS:SolutionExplorer.f)The properties in thePropertieswindow can be sortedor.ANS:alphabetically, categorically.g)AForm’sproperty specifies the text displayed in theForm’s title bar.ANS:Text.h)Thecontains the controls that you can add to aForm.ANS:Toolbox.i)displays relevant help articles, based on the current context.ANS:context-sensitive help.j)Theproperty specifies how text is aligned within aLabel’sboundaries.ANS:TextAlign.2.2State whether each of the following istrueorfalse. Iffalse, explain why.a)toggles auto-hide for a window.ANS:False. The pin icon()toggles auto-hide.closes a window.b)The toolbar icons represent various menu commands.ANS:True.c)The toolbar contains icons that represent controls you can drag onto aForm.ANS:False. TheToolboxcontains icons that represent such controls.d)BothFormsandLabelshave a title bar.ANS:False.Formshave a title bar butLabelsdo not (although they do haveLabeltext).e)Control properties can be modified only by writing code.ANS:False. Control properties can be modified using thePropertieswindow.f)PictureBoxestypically display images.ANS:True.g)Visual C# files use the file extension.csharp.ANS:False. Visual C# files use the file extension.cs.h)AForm’sbackground color is set using theBackColorproperty.ANS:True.ExercisesNote: Solutions to the code exercises are located in thesol_ch02folder2.3Fill in the blanks in each of the following statements:a)When an ellipsis button is clicked, a(n)is displayed.ANS:dialog.b)Usinghelp immediately displays a relevant help article.ANS:context-sensitive help.

Page 13

Solution Manual for Visual C# How to Program, 6th Edition - Page 13 preview image

Loading page ...

Exercises3c)GUI is an acronym for.ANS:graphical user interface.d)Theproperty specifies which image aPictureBoxdisplays.ANS:Image.e)Themenu contains commands for arranging and displaying windows.ANS:Window.2.4State whether each of the following istrueorfalse.Iffalse,explain why.a)You can add a control to aFormby double clicking its control icon in theToolbox.ANS:True.b)TheForm,LabelandPictureBoxhave identical properties.ANS:False. Each type of control has a different set of properties, although controls canhave common properties.c)If your machine is connected to the Internet, you can browse websites from the VisualStudio IDE.ANS:True.d)Visual C# app developers usually create complex apps without writing any code.ANS:False. C# programming usually involves a combination of writing a portion of theprogram code and having Visual Studio generate the remaining code.e)Sizing handles are visible during execution.ANS:False. Sizing handles are present only inDesignview when aFormor control is select-ed.2.5Some features that appear throughout Visual Studio perform similar actions in differentcontexts. Explain and give examples of how the ellipsis buttons, down-arrow buttons and tool tipsact in this manner. Why do you think the Visual Studio IDE was designed this way?ANS:An ellipsis button indicates that a dialog will be displayed when the button isclicked. The down-arrow button indicates that there are more options, both fortoolbar icons and for items in thePropertieswindow. Moving the mouse pointerover most icons displays the icon’s name as a tool tip. These features make theVisual Studio IDE easier to learn and use.2.6Briefly describe each of the following terms:a)toolbarANS:A toolbar contains icons that, when clicked, execute a command.b)menu barANS:A menu bar contains menus, which are groups of related commands.c)ToolboxANS:TheToolboxcontains controls used to customize forms.d)controlANS:A control is a component, such as aPictureBoxorLabel.Controls are added to aForm.e)FormANS:AFormrepresents the Windows Forms application that you are creating. TheFormand controls collectively represent the program’s GUI.f)solutionANS:A solution is a group of projects.

Page 14

Solution Manual for Visual C# How to Program, 6th Edition - Page 14 preview image

Loading page ...

3Introduction to C# AppProgrammingO b j e c t i v e sIn this chapter you’ll:Write simple C# apps usingcode rather than visualprogramming.Input data from the keyboardand output data to thescreen.Use C# 6’sstringinterpolation to createformattedstringsbyinserting values intostringliterals.Declare and use data ofvarious types.Store data in memory andretrieve it.Use arithmetic operators.Determine the order in whichoperators are applied.Write decision-makingstatements with equality andrelational operators.

Page 15

Solution Manual for Visual C# How to Program, 6th Edition - Page 15 preview image

Loading page ...

2Chapter 3Introduction to C# App ProgrammingSelf-Review Exercises3.1Fill in the blanks in each of the following statements:a)A(n)begins the body of every method, and a(n)ends the body ofevery method.ANS:left brace ({), right brace (}).b)Most statements end with a(n).ANS:semicolon (;).c)Thestatement is used to make decisions.ANS:if.d)begins a single-line comment.ANS://.e),andare called whitespace. Newline characters are alsoconsidered whitespace.ANS:Blank lines, space characters, tab characters.f)are reserved for use by C#.ANS:Keywords.g)C# apps begin execution at method.ANS:Main.h)Methodsanddisplay information in the console window.ANS:Console.WriteLineandConsole.Write.i)enables you to insert values directly into a string literal.ANS:stringinterpolation.3.2State whether each of the following istrueorfalse. Iffalse, explain why.a)Comments cause the computer to display the text after the//on the screen when theapp executes.ANS:False. Comments do not cause any action to be performed when the app executes.They’re used to document apps and improve their readability.b)C# considers the variablesnumberandNuMbErto be identical.ANS:False. C# is case sensitive, so these variables are distinct.c)The remainder operator (%) can be used only with integer operands.ANS:False. The remainder operator also can be used with noninteger operands in C#.d)The arithmetic operators*,/,%,+and-all have the same level of precedence.ANS:False. The operators*,/and%are on the same level of precedence, and the operators+and-are on a lower level of precedence.e)An interpolated string must begin with a$before the string literal.ANS:True.3.3Write statements to accomplish each of the following tasks:a)Declare variablesc,thisIsAVariable,q76354andnumberto be of typeint.ANS:intc;intthisIsAVariable;intq76354;intnumber;b)Prompt the user to enter an integer.ANS:Console.Write("Enteraninteger:");c)Input an integer and assign the result tointvariablevalue.ANS:value=int.Parse(Console.ReadLine());

Page 16

Solution Manual for Visual C# How to Program, 6th Edition - Page 16 preview image

Loading page ...

Self-Review Exercises3d)If the variablenumberis not equal to7, display"Thevariablenumberisnotequalto7".ANS:if(number!=7){Console.WriteLine("Thevariablenumberisnotequalto7");}e)Display"ThisisaC#app"on one line in the console window.ANS:Console.WriteLine("ThisisaC#app");f)Display"ThisisaC#app"on two lines in the console window. The first line shouldend withC#. Use methodConsole.WriteLine.ANS:Console.WriteLine("ThisisaC#\napp");g)Write a statement that usesstringinterpolation to display the sum of the variablesxandy. Assume variablesxandyof typeintexist and already have values.ANS:Console.WriteLine($"Thesumof {x}and{y}is{x+y}");3.4Identify and correct the errors in each of the following statements:a)if(c<7);{Console.WriteLine("cislessthan7");}ANS:Error:Semicolon after the right parenthesis of the condition(c<7) in theifstate-ment.Correction:Remove the semicolon after the right parenthesis. [Note: With the semi-colon, the output statement executes regardless of whether the condition in theifistrue.]b)if(c=>7){Console.WriteLine("cisequaltoorgreaterthan7");}ANS:Error:The relational operator=>is incorrect.Correction:Change=>to>=.3.5Write declarations, statements or comments that accomplish each of the following tasks:a)State that an app will calculate the product of three integers.ANS://Calculatingtheproductofthreeintegersb)Declare the variablesx,y,zandresultto be of typeint.ANS:intx;inty;intz;intresult;c)Prompt the user to enter the first integer.ANS:Console.Write("Enterfirstinteger:");d)Read the first integer from the user and store it in the variablex.ANS:x=int.Parse(Console.ReadLine());e)Prompt the user to enter the second integer.ANS:Console.Write("Entersecondinteger:");f)Read the second integer from the user and store it in the variabley.ANS:y=int.Parse(Console.ReadLine());g)Prompt the user to enter the third integer.ANS:Console.Write("Enterthirdinteger:");h)Read the third integer from the user and store it in the variablez.ANS:z=int.Parse(Console.ReadLine());
Preview Mode

This document has 164 pages. Sign in to access the full document!