|
CIS162AD -- C Sharp (C#) -- Section 5832
Professor: Dave Hammer dwhammer@cox.net http://members.cox.net/dwhammer/ Student: Patrick Moss patmoss@patmoss.com http://www.patmoss.com/cis162ad/ Worksheet #1 Due Thursday, February 2, 2006
I. Definitions
1. variables (p. 807)
Sing.: The representation of an area in the computer memory
in which a value of a particular data type can be stored.
2. class (p. 796)
A term denoting the encapsulation of data and behaviors
into a single package or unit. Class is the template from
which one, or more, objects can be instantiated.
3. instance of a class (p. 800)
An object is an instance of a class.
4. encapsulation (p. 798)
One of four major concepts that form the basis for an object-
oriented programming language. With encapsulation, the language
provides support for packaging data attributes and behaviors
into a single unit, thus hiding implementation details.
5. white space
Each source language statement consists of a number of "lexical
tokens", ending with a semicolon token that terminates the
statement. White space is the space between adjacent lexical tokens.
It consists of one or more space characters, tab characters, line
feed characters, carriage return characters, and most other control
characters with an ASCII value less than the space characer (32 decimal).
This means that one or more "white space" characters can be inserted
between adjacent lexical tokens. The first stage of the C# compiler
(i.e., the scanner/screener) will discard all white space characters,
and will just return individual consecutive tokens to the parser stage
of the C# compiler.
6. IDE (p. 800)
Integrated Development Environment.
Visual Studio .NET 2003 provides a GUI software development platform
that is common to all four of the .NET languages VB, C#, J#, and C++.
This platform commonly has a menu at the top of the screen, a toolbox
at the left side of the screen, a form in the center of the screen,
a properties window at the right side of the screen, and an output
window at the bottom of the screen (although most of these windows
can be moved, floating, docked, hidden, etc.).
7. intermediate language
A compiler usually processes a source language and produces object
code for a target hardware computer (e.g., an .EXE file). But the
.NET compilers produce object code for a hypothetical computer,
using an object language called "Intermediate Language". Then each
hardware machine must utilize a "run-time machine" compiler stage
to convert the Intermediate Language code into target machine code,
before the code can be executed on the target machine. Most of these
types of implementations compile the code on an "as needed" basis,
using a "Just In Time (JIT)" compiler.
8. syntax error
A compiler contains a set of parsing rules (i.e., grammar) that
define a software language, such as C#. The programmer must be
very careful to obey all of these rules in each program statement.
If one or more rules are violated, the compiler cannot determine
the "meaning" of a source program statement, and the compiler will
display a "syntax error" complaint on an output report.
9. data type
Each language defines a small set of storage/computational formats
for numeric, character, and string data. These formats usually
correspond directly to native object ALU instructions in the
target hardware computer. The common types are byte, character,
ingeger (short and long), float (short and long), string, and
decimal. Some languages also include a pointer data type, that
can contain and manipulate memory addresses. Some languages also
contain a time/date data type that can store and perform
calculations on time and date values. Some languages contain
implicit loop control, array index, and table search data types.
Many languages allow the user to create custom data types, based
upon the "primitive" native data types discussed above, as well as
upon other user-defined custom data types.
10. format string
Many languages provide the capability to use a "format string"
that contains output formatting control options, such as leading
zero suppression, decimal comma insertion, rounding to "n" decimal
places, leading or trailing arithmetic sign, etc. Then, for each
output statement, the programmer specifies both a numeric data
value and its corresponding output format string. Some languages
also provide the capability to use an input format string, to help
an input "scanner" to extract data fields from an input data string
(or "input data stream").
II. Questions or short essay
1. Explain the difference between procedural programming
and object oriented programming.
A program is generally written in order to "solve a problem"
We read input data, process it, and produce output data. The
algorithm to provide this transformation is called a procedure,
and the implementation technique is called procedural programming.
By abstracting a software specification one, or more, levels
higher, we can design "objects" that define input, data
transformations, and output. These can be written as reusable
"classes". Then each program can "instantiate" these classes
in order to create "objects", and program code that manipulates
these objects to produce an algorithm that is equivalent to
the original procedural approach.
By defining "objects", we can use information hiding, and
we can define what operations that an object can perform,
what input data it can accept, what output data it can
produce, how the user can access the object (with accessors
and mutators), etc. This is a "black box" approach to
software design and implementation.
2. What is the difference between the WriteLine() method
and the Write() method?
WriteLine() appends a CrLf (New Line) sequence at the end
of the output for a line. Write() displays only the data
itself, without adding anything extra at the end of the line.
3. What are the rules for creating an identifier? (p. 80)
Some identifiers are predefined, while others are user defined.
User defined identifers can contain letters, numeric digits,
and the special character underline(_). The first character
must not be a numeric digit. An identifier cannot contain
embedded spaces. Identifiers in C# are case sensitive, so
that "Joe" is different than "JOE" and "joe" and "jOe", etc.
4. What does it mean that the C# language is case sensitive?
(p. 60)
C# treats lower case letters (a-z) as distinct from upper case
letters (A-Z), so that "a" is distinct from "A", etc.
5. What are the common ways of adding comments to your program?
(p. 45)
We can use // at the beginning of a line to create a single
line comment. We can use /* etc. */ for a multi-line comment.
We can use /// to create an XML-style comment.
6. What are the common floating-point data types?
(p. 89-91)
double -- .NET alias type is System.Double
float -- .NET alias type is System.Single
7. How is the char data type different from the string data type?
(p. 89, 94)
The char data type stores a single 16-bit Unicode U+0000 to U+ffff.
The string is a built-in reference type, where a string represents
a sequence of one or more Unicode characters.
III. Programming Exercise
Write a program that declares five variables to hold scores
for five tests you have taken. Have the program accept five
scores from a user of the program. Display the average of
the tests to two decimal places. Turn in your source code
for this program.
|