Instant Access to (eBook PDF) Microsoft Visual C#: An Introduction to Object-Oriented Programming 7th Edition ebook Full Chapters
Instant Access to (eBook PDF) Microsoft Visual C#: An Introduction to Object-Oriented Programming 7th Edition ebook Full Chapters
com
https://ebooksecure.com/product/ebook-pdf-
microsoft-visual-c-an-introduction-to-object-
oriented-programming-7th-edition/
https://ebooksecure.com/download/c-programming-an-object-oriented-
approach-1e-ise-ebook-pdf/
ebooksecure.com
https://ebooksecure.com/product/ebook-pdf-introduction-to-programming-
using-visual-basic-10th-edition/
ebooksecure.com
https://ebooksecure.com/download/clearly-visual-basic-programming-
with-microsoft-visual-basic-2010-second-edition-ebook-pdf/
ebooksecure.com
https://ebooksecure.com/product/ebook-pdf-marketing-2016-18th-edition-
by-william-m-pride/
ebooksecure.com
(eBook PDF) Cengage Advantage: American Foreign Policy and
Process 6th Edition
https://ebooksecure.com/product/ebook-pdf-cengage-advantage-american-
foreign-policy-and-process-6th-edition/
ebooksecure.com
https://ebooksecure.com/product/ebook-pdf-organic-chemistry-6th-
edition/
ebooksecure.com
https://ebooksecure.com/download/basic-clinical-pharmacology-15th-
edition-ebook-pdf/
ebooksecure.com
https://ebooksecure.com/download/ethics-discovering-right-and-wrong-
ebook-pdf/
ebooksecure.com
https://ebooksecure.com/product/ebook-pdf-fundamentals-of-corporate-
finance-13th-edition/
ebooksecure.com
(eBook PDF) Data Analysis and Decision Making 4th Edition
https://ebooksecure.com/product/ebook-pdf-data-analysis-and-decision-
making-4th-edition/
ebooksecure.com
Joyce Farrell
Joyce Farrell
Microsoft Visual C# 2017
An Introduction to Object-Oriented Programming
Microsoft®
®
Visual C# 2017
An Introduction to
Object-Oriented Programming
Seventh Edition
Copyright 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
Copyright 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
C o ntents Contents
Copyright 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
CHAPTER 7 U s in g M et h o ds . . . . . . . . . . . . . . 265
Understanding Methods and Implementation Hiding . . . . . 266
Understanding Implementation Hiding . . . . . . . . . . . 267
Writing Methods with No Parameters
and No Return Value . . . . . . . . . . . . . . . . . . 268
An Introduction to Accessibility . . . . . . . . . . . . . 269
An Introduction to the Optional static Modifier . . . . . 270
An Introduction to Return Types . . . . . . . . . . . . . 271
Understanding the Method Identifier . . . . . . . . . . . 271
Placing a Method in a Class . . . . . . . . . . . . . . . 272
Declaring Variables and Constants in a Method . . . . . . 273
Writing Methods That Require a Single Argument . . . . . . 276
Writing Methods That Require Multiple Arguments . . . . . . 280
Writing Methods That Return a Value . . . . . . . . . . . . 282
Writing a Method That Returns a Boolean Value . . . . . . 284
Analyzing a Built-In Method . . . . . . . . . . . . . . . 285
Passing Array Values to a Method . . . . . . . . . . . . . 289
Passing a Single Array Element to a Method . . . . . . . 289
Passing an Array to a Method . . . . . . . . . . . . . . 290
Copyright 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
C o ntents Contents
Copyright 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
Copyright 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
Glo s s ar y . . . . . . . . . . . . . . . . 711
In dex . . . . . . . . . . . . . . . . . . 729
Copyright 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
Preface
xv
Microsoft Visual C# 2017, Seventh Edition provides the beginning programmer with a guide to
developing programs in C#. C# is a language developed by the Microsoft Corporation as part
of the .NET Framework and Visual Studio platform. The .NET Framework contains a wealth
of libraries for developing applications for the Windows family of operating systems.
With C#, you can build small, reusable components that are well-suited to Web-based
programming applications. Although similar to Java and C++, many features of C# make it
easier to learn and ideal for the beginning programmer. You can program in C# using a simple
text editor and the command prompt, or you can manipulate program components using
Visual Studio’s sophisticated Integrated Development Environment. This book provides you
with the tools to use both techniques.
This textbook assumes that you have little or no programming experience. The writing is
nontechnical and emphasizes good programming practices. The examples are business
examples; they do not assume mathematical background beyond high school business math.
In addition, the examples illustrate one or two major points; they do not contain so many
features that you become lost following irrelevant and extraneous details. This book provides
you with a solid background in good object-oriented programming techniques and introduces
you to object-oriented terminology using clear, familiar language.
Copyright 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
Visit https://testbankfan.com
now to explore a rich
collection of testbank or
solution manual and enjoy
exciting offers!
P re f ace Organization and Coverage
In Chapters 4, 5, and 6, you learn about the classic programming structures—making decisions,
looping, and manipulating arrays—and how to implement them in C#. Chapters 7 and 8
provide a thorough study of methods, including passing parameters into and out of methods
and overloading them.
xvi Chapter 9 introduces the object-oriented concepts of classes, objects, data hiding, constructors,
and destructors. After completing Chapters 10 and 11, you will be thoroughly grounded in
the object-oriented concepts of inheritance and exception handling, and will be able to take
advantage of both features in your C# programs. Chapter 12 continues the discussion of GUI
objects from Chapter 3. You will learn about controls, how to set their properties, and how to
make attractive, useful, graphical, and interactive programs. Chapter 13 takes you further into
the intricacies of handling events in your interactive GUI programs. In Chapter 14, you learn to
save data to and retrieve data from files.
Copyright 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
Features
This text focuses on helping students become better programmers and
understand C # program development through a variety of key
features. In addition to chapter Objectives, Summaries, and Key Terms,
these useful features will help students regardless of their learning styles.
xvii
CHAPTER 1
YOU DO IT follows each major
concept. Each “You Do It” section
walks students through program
You Do It
development step by step.
32 Compiling and Executing a Program from the Command Line
If you do not plan to use the command line to execute programs, you can skip to the next part of
this “You Do It” section: “Compiling and Executing a Program Using the Visual Studio IDE.”
CHAPTER 2 Using Data
When allinyou
1. Go to the command prompt on your system. For example, want to10,
Windows accomplish is to increase a variable’s value by 1, there is no apparent
start to type Developer Command Prompt in thedif ference
“Ask me between
anything”using the prefix and postfix increment operators. However, these operators
search
function differently. When you use the prefix 11, the result is calculated and stored and then
box, and then click the option.
the variable is used. For example, in the following code, both b and c end up holding 5. The
2. Change the current directory to the name of the folder that holdsstatement
WriteLine() your displays 5 and 5. In this example, 4 is assigned to b, then b becomes 5,
66
program. You can type cd\ and then press Enter toandreturn
thento5 the root to c.
is assigned
directory. You can then change the path to the one where
b = 4;your program
resides. For example, if you stored your program file
c in
= a++b;
folder named
Chapter01 within a folder named CSharp, then you WriteLine("{0}
can type the following:
and {1}", b, c);
cd CSharp\Chapter01 In contrast, when you use the postfix 11, the variable is used, and then the result is calculated
The command cd is short for change directory. and stored. For example, in the second line of the following code, 4 is assigned to c; then, after
the assignment, b is increased and takes the value 5.
3. Type the command that compiles your program:
b = 4;
csc Hello.cs c = b++;
WriteLine("{0} and {1}", b, c);
If you receive no error messages and the prompt returns, it means that the
compile operation was successful, that a file namedThisHello.exe has been statement displays 5 and 4. In other words, if b = 4, then the value of
last WriteLine()
created, and that you can execute the program. If you b++do receive
is also error
4, and, in the second statement above, that value is assigned to c. However, after the
messages, check every character of the program you 4 is typed
assigned to to c, b is
make increased to 5.
sure
NOTES provide additionalit matches Figure 1-9 in the last “You Do It” section. Remember, C#need
When you is case
to add 1 to a variable in a standalone statement, the results are the same whether you use
sensitive, so all casing must match exactly. When you have corrected theincrement operator. However, many programmers routinely use the postfix operator when
information—for example,errors, repeat this step to compile the program again.
a prefix or postfix
they could use either operator. This is probably a mistake because the prefix operator is more efficient. You
to watch out. stored your program, verifying that two Hello files are listed.Watch the video Using Shortcut Arithmetic Operators.
(continues)
TWO TRUTHS & A LIE
Using Arithmetic Operators
1. The value of 26 % 4 * 3 is 18.
2. The value of 4 / 3 1 2 is 3.
VIDEO LESSONS help 3. If price is 4 and tax is 5, then the value of price – tax++ is –1.
explain important chapter
concepts. Videos are
26. Then 2 * 3 is 6.
of the expression, 26 % 4, is 2, because 2 is the remainder when 4 is divided into
instructor download at
CengageBrain.com.
Copyright 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
Feat u res
CHAPTER 1
Named computer memory locations that hold data, such as hoursWorked and pay, are called
variables because they hold values that might vary. In programming languages, a variable is
referenced by using a one-word name (an identifier) with no embedded spaces. For example,
Figure 4-4 Flowchart
the memory location referenced by the name hoursWorked and code
might contain includingvalues
different an if statement with a semicolon following the
at different times for different employees. During if expression
the execution of the payroll program, each
value stored under the name hoursWorked might have many operations performed on it—for
example, reading it from an input device, multiplying
Although it by
it isa customary,
pay rate, and
andprinting it onto
good style, paper.
indent any statement that executes when an if
Boolean expression evaluates as true, the C# compiler does not pay any attention to the
indentation.
Examples of procedural programming languages include C andEach
Logo.of the following if statements displays A when number is less than 5. The
first shows an if statement written on a single line; the second shows an if statement on two
lines but with no indentation. The third uses conventional indentation. All three examples
execute identically.
THE DON’T DO IT ICON illustrates
how NOT to do something—for if(number < 5) WriteLine("A");
if(number < 5)
example, having a dead code path inWriteLine("A");
Don’t Do It
if(number < 5) Although these first two formats work for
CHAPTER 1
Review Questions
1. Programming languages such as C#, Java, and Visual Basic are
_____________________ languages.
42 a. machine c. low-level
b. high-level C H A d.
P Tuninterpreted
ER 2 Using Data
a. mangler
Exercises
c. analyst
b. compactor d. compiler
Programming Exercises
3. The grammar and spelling rules of a programming language constitute its
96
_____________________. 1. What is the numeric value of each of the following expressions, as evaluated by the C#
programming language?
a. logic c. class
b. variables d. a.syntax
215*3 g. 64 % 8
b. 9 / 4 1 10 h. 5 1 2 * 4 – 3 * 4
4. Variables are _____________________ .
c. 10 / 3 i. 3 * (2 1 5) / 5
a. named memory locations c. grammar rules
d. 21 % 10 j. 28 % 5 – 2
b. unexpected results d. operations
e. (5 – 1) * 3 k. 19 / 2 / 2
5. Programs in which you create and use objects that have
f. 37attributes
/5 similar to their real- l. 28 / (2 1 4)
world counterparts are known as _____________________ programs.
2. What is the value of each of the following Boolean expressions?
a. procedural c. object-oriented
a. 5 > 4 f. 3 1 4 55 4 1 3
b. logical d. authentic
b. 3 <5 3 g. 1 !5 2
6. Which of the following pairs is an example of a class
c. and
2 1an4 object,
>5 in that order? h. 2 !5 2
a. University and Yale c. d.Clydesdale
6 55 7 and horse i. –5 55 7–2
b. Chair and desk d. e.Maple
2 1 4and
<5tree
6 j. 3 1 9 <5 0
7. The technique of packaging an object’s attributes
3. into a cohesive
Choose unit
the best that
data canfor
type beeach
usedof the following, so that no memory storage is
as an undivided entity is _____________________ .wasted. Give an example of a typical value that would be held by the variable, and
a. inheritance c. explain why you chose the type you did.
polymorphism
b. encapsulation d. a.interfacing
the number of years of school you have completed
b. your final grade in this class
8. Of the following languages, which is least similar to C#?
c. the population of China
a. Java c. C++
d. the number of passengers on an airline flight
b. Visual Basic d. machine language
e. one player’s score in a Scrabble game
f. the number of Electoral College votes received by a U.S. presidential candidate
g. the number of days with below freezing temperatures in a winter in Miami, Florida
h. one team’s score in a Major League Baseball game
REVIEW QUESTIONS test
4. In this chapter, you learned that although a double and a decimal both hold
student comprehension of the floating-point numbers, a double can hold a larger value. Write a C# program named
DoubleDecimalTest that declares and displays two variables—a double and a
major ideas and techniques decimal. Experiment by assigning the same constant value to each variable so that the
presented. Twenty questions assignment to the double is legal but the assignment to the decimal is not. In other
words, when you leave the decimal assignment statement in the program, an
follow each chapter.
Copyright 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
A ssess m ent
Debugging Exercises
1. Each of the following files in the Chapter.01 folder of your downloadable student files
CASE PROBLEMS provide opportunities
has syntax and/or logical errors. In each case, determine the problem and fix the
program. After you correct the errors, save each file using the same filename preceded
to build more detailed programs that
with Fixed. For example, DebugOne1.cs will become FixedDebugOne1.cs.
a. DebugOne1.cs c. continue to incorporate increasing
DebugOne3.cs
b. DebugOne2.cs d. DebugOne4.cs
functionality throughout the book.
Case Problems
The case problems in this section introduce two fictional businesses. Throughout this
book, you will create increasingly complex classes for these businesses that use the newest
concepts you have mastered in each chapter.
1. Greenville County hosts the Greenville Idol competition each summer during the county
fair. The talent competition takes place over a three-day period during which contestants
are eliminated following rounds of performances until the year’s ultimate winner is chosen.
Write a program named GreenvilleMotto that displays the competition’s motto, which is
“The stars shine in Greenville.” Create a second program named GreenvilleMotto2 that
displays the motto surrounded by a border composed of asterisks.
2. Marshall’s Murals is a company that paints interior and exterior murals for both
business and residential customers. Write a program named MarshallsMotto that
displays the company motto, which is “Make your vision your view.” Create a second
program named MarshallsMotto2 that displays the motto surrounded by a border
composed of repeated Ms.
Copyright 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
Exploring the Variety of Random
Documents with Different Content
step.
Father.—Well, say two feet and a half to each step.
Ernest.—Twice 32 makes 64; the half of 32 is 16; which added to
64 makes 80 feet.
Father.—Very well. Tell me now, if you recollect the proper term in
geometry for the circumference of a circle, or say of a tree, since we
are talking of trees.
Ernest.—Oh, you may be sure that I could not forget that it is
called the periphery.
Father.—Right. And what is the term for any line which may be
drawn from one point of the periphery to another, passing through
the centre? Now, Jack, you may show us what a great geometrician
you intend to be.
Jack.—I believe it is called the diameter.
Father.—So far right. Next, can you tell me what is the diameter of
a periphery of eighty feet, and what distance there is between the
extremities of the roots of the giant tree and its trunk?
The boys all began to reckon, and soon one said one number, one
said another,—at random; but Fritz called out louder than the rest,
that the distance was twenty-six feet.
Father.—You are pretty near. Tell me, did you make a calculation,
or was it a mere guess?
Fritz.—No, father, not a guess; but I will tell you. In the town in
which we lived, I have often taken notice that the hatter, when he
was about to bind the edge of a hat, always measured three times
the length of the diameter, and a trifle over, for the quantity of ribbon
he should use: thus I had no difficulty in finding that the third of
eighty was about twenty-six; and adding a couple of feet for the over
measure, we may call it twenty-eight.
Father.—I am glad to see you did not lose such an opportunity for
calculation; but a great boy like you, who have advanced in your
studies, ought not to be under obligations to the hatter for the
answer. But now let us go back to the measure of our trees, which
are really of a most extraordinary size. Height from the ground to the
branches, sixty-six feet; thickness, eight feet in diameter, and twenty-
eight feet distance from the extremities of the roots to the trunk. They
really, with propriety, may be called giant trees.
Having finished our conversation, we performed our devotions,
and retired to rest, grateful and well satisfied to find ourselves once
more together, and in health. We soon closed our eyes, and enjoyed
tranquil slumbers till break of day.
CHAPTER VIII.
Construction of a bridge.