Top-Rated Free Essay
Preview

Intro to programming

Good Essays
534 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Intro to programming
Ch. 2: Short Answer 1-3

1. What does a professional programmer usually do first to gain an understanding of a problem?
Work directly with the customer.

2. What is pseudocode?
Fake code as known as an informal language that has no syntax rules, and is not meant to be compiled or executed.

3. Computer programs typically perform what three steps?
Input, process, and output.

Chapter 2: Algorithm Workbench 1-2

1. Design an algorithm that prompts the user to enter his or her height and stores the user’s input in a variable named height.
Display “What is your height?”
Input height

2. Design an algorithm that prompts the user to enter his or her favorite color and stores the user’s input in a variable named color.
Display “What is your favorite color?”
Input Color

Chapter 2: Programming Exercises 1, 4

1. Personal Information
Design a program that displays the following information:
• Your name
• Your address, with city, state, and ZIP
• Your telephone number
• Your college major

Pseudocode:
Display “Enter your name”
Input name
Display “Enter your address, with city, state, and zip”
Input address, city, state, zip
Display “Enter your telephone number”
Input Telephone number
Display “Enter college major”
Input college major

Flowchart: Visual Basic Code:
Sub Main() 'Declarations for variables Dim name As String Dim addressCityStateZip As String Dim telephoneNumber As String Dim collegeDegree As String

'Input Imformation Console.Write("Enter your full name: ") name = Console.ReadLine() Console.Write("Enter your address, city, state, and zip: ") addressCityStateZip = Console.ReadLine() Console.Write("Enter your Telephone Number: ") telephoneNumber = Console.ReadLine() Console.Write("Enter your College Degree: ") collegeDegree = Console.ReadLine()

'Displaying personal Information Console.Write("Your name is: " & name & "," & " your address is: " & addressCityStateZip & "," & " your telephone number is: " & telephoneNumber & ", and" & " your college degree is: " & collegeDegree & ".") Console.ReadLine() End Sub

4. Total Purchase
A customer in a store is purchasing five items. Design a program that asks for the price of each item, and then displays the subtotal of the sale, the amount of sales tax, and the total. Assume the sales tax is 6 percent.

Purpose: To calculate the total amount of a purchase.

Input:
• Cost of items
• Subtotal of the sale
• Amount of sale tax 6%
• Total price

Process:
• Subtotal
• Sale tax = 6%
• Total price

Output:
• Display subtotal
• Display sale tax = 6%
• Display Total price

Pseudocode:
Display “cost of item1”
Input price
Display “cost of item2”
Input price
Display “cost of item3”
Input price
Display “cost of item4”
Input price
Display “cost of item5”
Input price
Display “Subtotal”
Subtotal = item1 + item2 + item3 + item4 + item5
Set Tax = subtotal * 0.06
Set TotalCost = subtotal + Tax
Display “Subtotal, Tax, and TotalCost

Flowchart:

Visual Basic Code:
Sub Main() 'Declarations for variables Dim costItem1 As Double Dim costItem2 As Double Dim costItem3 As Double Dim costItem4 As Double Dim costItem5 As Double Dim subtotal As Double Dim tax As Double Dim totalCost As Double

'Request for price Console.Write("Enter Price: ") costItem1 = Console.ReadLine() Console.Write("Enter Price: ") costItem2 = Console.ReadLine() Console.Write("Enter Price: ") costItem3 = Console.ReadLine() Console.Write("Enter Price: ") costItem4 = Console.ReadLine() Console.Write("Enter Price: ") costItem5 = Console.ReadLine()

'Calculations for subtotal subtotal = costItem1 + costItem2 + costItem3 + costItem4 + costItem5 tax = subtotal * 0.06 totalCost = subtotal + tax

'Total for customer Console.Write("Your Subtotal was: " & subtotal & "." & " Your Tax was: " & tax & "." & " Your purchase amount is: " & totalCost & ".") Console.ReadLine() End Sub

You May Also Find These Documents Helpful