Вы находитесь на странице: 1из 37

O F F I C I A L

M I C R O S O F T

L E A R N I N G

2667A

P R O D U C T

Introduction to Programming
Companion Content

Information in this document, including URL and other Internet Web site references, is subject to change
without notice. Unless otherwise noted, the example companies, organizations, products, domain names,
e-mail addresses, logos, people, places, and events depicted herein are fictitious, and no association with
any real company, organization, product, domain name, e-mail address, logo, person, place or event is
intended or should be inferred. Complying with all applicable copyright laws is the responsibility of the
user. Without limiting the rights under copyright, no part of this document may be reproduced, stored in
or introduced into a retrieval system, or transmitted in any form or by any means (electronic, mechanical,
photocopying, recording, or otherwise), or for any purpose, without the express written permission of
Microsoft Corporation.
Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual property
rights covering subject matter in this document. Except as expressly provided in any written license
agreement from Microsoft, the furnishing of this document does not give you any license to these
patents, trademarks, copyrights, or other intellectual property.
The names of manufacturers, products, or URLs are provided for informational purposes only and
Microsoft makes no representations and warranties, either expressed, implied, or statutory, regarding
these manufacturers or the use of the products with any Microsoft technologies. The inclusion of a
manufacturer or product does not imply endorsement of Microsoft of the manufacturer or product. Links
may be provided to third party sites. Such sites are not under the control of Microsoft and Microsoft is not
responsible for the contents of any linked site or any link contained in a linked site, or any changes or
updates to such sites. Microsoft is not responsible for webcasting or any other form of transmission
received from any linked site. Microsoft is providing these links to you only as a convenience, and the
inclusion of any link does not imply endorsement of Microsoft of the site or the products contained
therein.
2002 Microsoft Corporation. All rights reserved.
Microsoft and the trademarks listed at
http://www.microsoft.com/about/legal/en/us/IntellectualProperty/Trademarks/EN-US.aspx are trademarks
of the Microsoft group of companies. All other marks are property of their respective owners.

Product Number: 2667A


Released: 09/2002

Introduction to Computer Programs

Module 1
Introduction to Computer Programs
Contents:
Question and Answers

Lab: Question and Answers

1-1

1-2

Introduction to Programming

Question and Answers


Practice: Identifying Program Phases
Introduction
In this practice, you will identify the components of each program phase.

Identifying the program phases


In the airline reservation application, the airline reservation clerk uses the mouse and keyboard in the
_______ phase. In the ______ phase, the computer uses the CPU and the memory to determine flight
availability. In the _____ phase, the monitor displays seat availability. Also, during the ______ phase, if a seat
is available, the ticket is printed.
Answer:
input
process
output
output

Practice: Calculating the Total Sales


Identify the output and input elements
1.

Identify the output and input elements of the scenario.

2.

Open the InputOutput.htm file located in install_folder\Practices\Mod01\Mod01_2\Solution and


compare your results.
Answer: To calculate the sale value, you need output element - Total Sale Value.
To calculate the sale value, you need the input elements - Units Sold and Unit Price.

Identify the processes involved


1.

Identify the processes involved in the scenario.

2.

Open the Processes.htm file located in install_folder\Practices\Mod01\Mod01_2\Solution and


compare your results.
Answer:
Accept Units Sold.
Accept Unit Price.
Multiply the number of Units Sold with the Unit Price.
Display the Total Sale Value.

Introduction to Computer Programs

1-3

Draw the Flowchart


1.

Draw a flowchart that represents the scenario.

2.

Open the FlowChart.gif file located in install_folder\Practices\Mod01\Mod01_2\Solution and


compare your results.
Answer:

Introduction to Computer Programs


Question: When executing a program, you are prompted to type Hello World and press Enter. After you
perform the necessary steps, the message "Hello! It is a beautiful world" is displayed on the monitor.
Identify the phases in the execution of this program.
Answer: Input phase: Typing Hello World
Process phase: Converting the message "Hello World" to "Hello! It is a beautiful world"
Output phase: Displaying the message "Hello! It is a beautiful world"
Question: What do you use to indicate a block of instructions in PseudoCompiler?
Answer: To indicate a block of instructions in pseudocode, you use the begin-end keyword.

1-4

Introduction to Programming

Question: What is the purpose of a flowchart?


Answer: A flowchart is used to represent the algorithm of a program graphically.
Question: Draw a flowchart to input any number, multiply it by 2, and display the result.
Answer:

Introduction to Computer Programs

Lab: Question and Answers


Lab 1, Exercise 1: Determining Program Phases
Draw a flowchart to represent the program phases
Answer:

1-5

Introduction to Scripting

Module 2
Introduction to Scripting
Contents:
Question and Answers

2-1

2-2

Introduction to Programming

Question and Answers


Introduction to Scripting
Question: Define the term Internet and explain the relationship between the Internet and the Web.
Answer: The Internet is a global network of smaller computer networks. It is the single largest
network of computers with many available services. The Internet has grown into a vast resource
for information and communication.
The Web is a subset of the Internet.
Question: What markup language would you use to create Web pages?
Answer: HTML
Question: List the two types of Web scripts and state the key difference between the two.
Answer:

Client-side scripts

Server-side scripts

Client-side scripts are run by the Web browser whereas server-side scripts are run on the Web
server.
Question: You have been asked to format a number of Word documents in a similar manner. How would
you speed up the formatting and ensure that the documents are formatted correctly?
Answer: Create macros to automate the formatting tasks.
Question: How can you automate an administrative task, such as configuring the profiles of all the
employees in your organization?
Answer: You can create and use a Windows script to perform the task.

Using Data and Variables

Module 3
Using Data and Variables
Contents:
Question and Answers

3-1

3-2

Introduction to Programming

Question and Answers


Practice: Identifying, Declaring, and Initializing Variables
Draw the Flowchart
Answer:

Write the pseudocode


Answer:
// Pseudocode to identify, declare, and initialize
// variables
begin
character cCode
character cName
numeric nAge
display "Enter candidate code: "
accept cCode
display "Enter candidate name: "
accept cName
display "Enter candidate age: "
accept nAge
display cCode
display cName
display nAge
end

Using Data and Variables

Practice: Using Operators


Question: Consider four variables set to the following values:

IntA = 3

IntB = 4

IntC = 4

IntD = 5

Question: Predict the results for the comparisons listed in the following table.

Comparison

Results

IntA < IntB

Answer
True

IntB = IntD

Answer
False

IntB != IntC

Answer
False

IntB >= IntD

Answer
False

IntC >= IntB

Answer
True

IntB = IntC

Answer
True

Using Data and Variables


Question: To store values in memory and refer to those values later, what do you use?
Answer: Variables
Question: List the types of variables.
Answer:

Loop variables

Summation variables

Program variables

Question: To assign meaningful names to variables, what naming conventions do you follow?
Answer: The first letter of the variable must indicate the data type. Use n for numeric variables
and c for character variables. The name of the variable should reflect the value that it is storing.
For example, the variable nAge can be used to store a numeric value of age.

3-3

3-4

Introduction to Programming

Question: You must declare all variables before you can use them so that memory is allocated before it is
used in a program. Does the order in which you declare the variables matter?
Answer: No. However, a variable cannot be used if it is not declared already.
Question: What are operators?
Answer: Operators are symbols or other characters that indicate an operation that acts upon one
or more elements.
Question: What are keywords?
Answer: Keywords are reserved words in any programming language that have a special meaning.
Question: Which data type would you use for storing country codes for telephone numbers? For
example, 1 for United States.
Answer: Numeric

Using Program Logic

Module 4
Using Program Logic
Contents:
Question and Answers

Lab: Question and Answers

4-1

4-2

Introduction to Programming

Question and Answers


Practice: Printing the Product of the First 8 Even Numbers
Write the pseudocode
Question: Write the pseudocode to display the product of the first 8 even numbers.
Answer: The pseudocode to display the product of the first 8 even numbers is as follows:
// pseudocode to display the product of the first 8
// even numbers
begin
numeric nNumber
numeric nProduct
numeric nCounter
nNumber = 2
nProduct = 1
for nCounter = 1 to 8 step 1
begin
nProduct = nNumber * nProduct
nNumber = nNumber + 2
end
display nProduct
end

Using Program Logic


Question: Complete the following pseudocode to check the password. This code prompts the user to
enter a user name and password. If the password is incorrect, it displays the message "Password is
incorrect. Exiting". If the password is correct, it displays the message "Welcome to Northwind Traders".
The password should be northwind.
Note This pseudocode focuses on the concepts taught in this module and as a result may not comply
with Microsoft security recommendations.

// program to check for password


begin
character cUserName
character cPassword
display "Enter username"
accept cUserName
display "Enter password"
accept cPassword
if ___________________________
begin
display "Welcome to Northwind Traders"
end
_____
begin
display "Password is incorrect.... Exiting"
end
end

Using Program Logic

4-3

Answer:
cPassword = "northwind"
else

Question: For applications that accept input data from the user, you must validate the data. For example,
an application requires the name and test score of an employee and displays a message depending upon
the test score. Complete the pseudocode to evaluate written test scores and display the messages based
on the values given in the following table.

Criteria

Message

Test score greater than or equal to 40

Pass

Test score less than 40

Fail

Test score is negative

ERROR: Score cannot be negative

Test score is more than 100

ERROR: Score cannot be more than 100

// Pseudocode to evaluate the written test scores and


// display appropriate messages
begin
character cName
numeric nScore
accept cName
accept nScore
if___________________________
begin
display "Pass"
end
else
begin
if nScore < 40 and nScore >= 0
begin
display "Fail"
end
else
begin
if ______________
begin
display "ERROR: Score cannot be more than 100"
end
else
begin
display "ERROR: Score cannot be negative"
end
end
end
end

Answer:
nScore >= 40 and nScore <= 100
nScore > 100

4-4

Introduction to Programming

Question: You must run a set of statements repeatedly until the user decides to discontinue. Which loop
do you use to solve this problem?
Answer: When you do not know how many times that you must repeat a task, use the WHILE loop.
Question: What are the different types of looping constructs? What are the guidelines for using each
type?
Answer: There are two types of looping constructs: the FOR loop and the WHILE loop. Use the FOR
loop when the number of iterations is known beforehand. Use the WHILE loop when you do not
know how many times a loop must execute.
Question: What are logic errors?
Answer: Logic errors arise because of incorrect implementation of business rules or incorrect
program logic. They may cause an abnormal termination of the program or cause the program to
return abnormal results.

Using Program Logic

Lab: Question and Answers


Draw the Flowchart
Answer:

Implement the solution


Question: Write the pseudocode.
Answer:
// Pseudocode to select candidates based on interview scores
begin
character cCode
character cName
numeric nRound1
numeric nRound2
display "Enter candidate code"
accept cCode
display "Enter candidate name"
accept cName

4-5

4-6

Introduction to Programming

display "Enter Round 1 interview score"


accept nRound1
if nRound1 < 1 or nRound1 > 10
begin
display "ERROR: Round 1 score has to be in the range of 1 to 10"
end
else
begin
if nRound1 < 6
begin
display "Round 1 score must be greater than 5. Send rejection letter."
end
else
begin
display "Candidate is eligible for Round 2 interview"
display "Enter Round 2 interview score"
accept nRound2
if nRound2 < 1 or nRound2 > 10
begin
display "ERROR: Round 2 score must be in the range of 1 to 10"
end
else
begin
if nRound2 > 7
begin
display " Interviews completed successfully. Send offer to
candidate."
end
else
begin
display "Round 2 score must be greater than 7. Send
rejection letter."
end
end
end
end
end

Note The solution code for this exercise is provided in the Mod4_Ex1.txt file in the
install_folder\Labfiles\Lab04\Solution folder.

Using Procedures and Functions

Module 5
Using Procedures and Functions
Contents:
Question and Answers

5-1

5-2

Introduction to Programming

Question and Answers


Review Answers
Using Procedures and Functions
Question: What are procedures?
Answer: Procedures are the executable code statements in a program. The statements in a
procedure are enclosed by a declaration statement and an End statement.
Question: What are the different types of procedures?
Answer: There are three types of procedures:

Sub procedure

Function procedure

Property procedure

Question: What is the main difference between a Sub procedure and a Function procedure?
Answer: A Function procedure has a return type and always returns a value. A Sub procedure does
not have any return type and does not return a value.
Question: Give examples of functions.
Answer:

String function

Len function

Left function

Trim function

Question: The Function procedure sends back a value to the calling program. What is that value called?
Answer: Return value
Question: What is the syntax for a Sub procedure?
Answer:
[accessibility] Sub subname[(argumentlist)]
' Statements of the Sub procedure go here
End Sub

Introduction to Developing a User Interface

Module 6
Introduction to Developing a User Interface
Contents:
Question and Answers

6-1

6-2

Introduction to Programming

Question and Answers


Review Answers
Introduction to Developing a User Interface
Question: You are developing a large application that is to be used by advanced users. You have been
told to keep the application simple. However, because the users are experienced, user-friendliness is not
particularly important. Would you design a command-based interface or graphical user interface?
Answer: Command-based interface.
Question: List three key features of a good interface.
Answer: Intuitive design, ease of navigation, and input validation.
Question: How do you build a user interface for a Windows-based application?
Answer: Add controls from the Toolbox to the Windows Forms Designer.

Introduction to Working with Data

Module 7
Introduction to Working with Data
Contents:
Question and Answers

7-1

7-2

Introduction to Programming

Question and Answers


Practice: Representing Data as Tables
Exercise 1

Identify the entity


Answer: In this situation, the entity is Employee.

Exercise 2
In this exercise, you will identify the attributes for the entity that you have identified.

Identify the attributes


Answer:
In this situation, the attributes are:
EmployeeName
Address
City
Zip
Country
Phone
Qualification
BirthDate
Sex
Designation
EmailId
Dept
Region
Photograph
JoiningDate
ResignationDate

Introduction to Working with Data

Exercise 3
In this exercise, you will represent the entity and its attributes in the form of a table.

Represent the entity and its attributes in a table structure


Question: Create a table structure to represent the entity and its attributes. List all the column
headings for the table in a column.
Answer:

EmployeeName
Address
City
Zip
Country
Phone
Qualification
BirthDate
Sex
Designation
EmailID
Dept
Region
Photograph
JoiningDate
ResignationDate

Introduction to Working with Data


Question: What is a database?
Answer: A database is a collection of data. A computer system uses a database to store and
manage data.
Question: What is a relationship?
Answer: A relationship describes the connection between a pair of logically related entities.
Question: What is a candidate key?

7-3

7-4

Introduction to Programming

Answer: A candidate key is an attribute or set of attributes that uniquely identifies a row in a data
table. A candidate key is also called a surrogate key.
Question: Define XML.
Answer: XML is a markup syntax that defines the structure of data in an open and self-describing
manner. XML enables you to transfer data easily over a network and ensure that the data is
processed consistently by the applications that use it. Because XML is used to describe and
structure information, XML is like a data-description language. You can use XML to describe data
components, records, and other complex data structures, such as purchase orders, catalogs, and
documents.

Programming Approaches

Module 8
Programming Approaches
Contents:
Question and Answers

8-1

8-2

Introduction to Programming

Question and Answers


Review Answers
Programming Approaches
Question: What is the limitation of the procedural approach to programming?
Answer: Applications developed by using the procedural approach are interdependent and not
resilient to change. In addition, you cannot reuse the procedures of one application in another
application.
Question: What are three components of an object?
Answer: An object has:

State

Behavior

Identity

Question: What is the relationship between objects and classes?


Answer: Objects are instances of classes. An object has the attributes and behavior of its class.
Question: What is inheritance?
Answer: Inheritance is a feature of object-oriented programming. You can generalize the
attributes and behavior of objects and create a parent class. You can then create subclasses that
inherit the attributes and behavior of the parent class and have their own specific attributes and
behavior as well.
Question: How are object-oriented applications resilient to change?
Answer: In object-oriented applications, you do not need to change the entire application when
you change part of the application. You can update a specific class or add more classes to the
application.

Introduction to the Software Development Process

Module 9
Introduction to the Software Development Process
Contents:
Question and Answers

9-1

9-2

Introduction to Programming

Question and Answers


Review Answers
Introduction to the Software Development Process
Question: What are the primary design goals of UML?
Answer: The primary design goals of UML are:

To provide a simple and ready-to-use expressive modeling language that enables the user
to visualize, develop, and exchange meaningful models of a system

To integrate best practices of other modeling approachesTo help all software system
stakeholders understand how the system will work and what options are available

To provide a formal basis for understanding the modeling language

To support high-level development concepts such as components, collaborations,


frameworks and patterns

Question: What are the features of UML?


Answer: The features of UML are:

Simple, extensible, and expressive visual modeling language

A set of notations and rules for modeling software systems of varying complexities

The creation of simple, well documented, and easy to understand software models

Language and platform independence

Question: Which UML diagram represents a set of classes, and the messages sent and received by those
classes?
Answer: Collaboration diagram
Question: What are actors?
Answer: Actors are elements that are outside the system. They are also called the external entities
of a system. External entities that do not interact directly with the system are not actors.
Question: List the categories of actors.
Answer: There are four categories of actors: principal actors, secondary actors, external hardware,
and other systems
Question: What is a use case?
Answer: A use case is a set of transactions that the system performs when an actor initiates an
event or action. Use cases represent all the possible events that can occur in all possible scenarios.
They represent all interactions that can take place between an actor and the system.

Introduction to the Software Development Process

9-3

Question: What is the purpose of a use-case diagram?


Answer: The purpose of the use-case diagram is to establish the scope of the project and provide
structure for the system. The use-case diagram describes the behavior of the system from the
point of view of its end users and developers. It also describes their expectations of the system.
Question: How do you represent use cases in a use-case diagram?
Answer: You represent use cases as ellipses in a use-case diagram.
Question: How do you identify the behavior of a class?
Answer: To identify the behavior of a class, you study the use case to determine the actions that
the class will perform.
Question: How do you identify the attributes of a class?
Answer: To identify the attributes of a class, you study the use case to determine the
characteristics of the class.
Question: How do you represent a class name in a class diagram?
Answer: A class name is depicted in the top section of a rectangle. The class name is always
centered and in bold typeface.
Question: What are links in an object diagram?
Answer: Links are instances of associations between classes. Links depict the relationship between
two objects in a system at any instant.
Question: Do you always need to create three sections in the rectangle to represent an object in an
object diagram?
Answer: No. Display the information relevant to current scenario for every object. If there are no
relevant behavior names for an object, you need not include them in the object diagram.

Introduction to Programming

1-1

Send Us Your Feedback


You can search the Microsoft Knowledge Base for known issues at Microsoft Help and Support before
submitting feedback. Search using either the course number and revision, or the course title.

Note Not all training products will have a Knowledge Base article if that is the case, please ask
your instructor whether or not there are existing error log entries.

Courseware Feedback
Send all courseware feedback to support@mscourseware.com. We truly appreciate your time and effort.
We review every e-mail received and forward the information on to the appropriate team. Unfortunately,
because of volume, we are unable to provide a response but we may use your feedback to improve your
future experience with Microsoft Learning products.

Reporting Errors
When providing feedback, include the training product name and number in the subject line of your email. When you provide comments or report bugs, please include the following:

Document

Page number or location

Complete description of the error or suggested change

Please provide any details that are necessary to help us verify the issue.

Important All errors and suggestions are evaluated, but only those that are validated are added
to the product Knowledge Base article.

Вам также может понравиться