Lab 2

.pdf

School

Austin Community College District *

*We aren’t endorsed by this school

Course

1336-018

Subject

Computer Science

Date

Apr 3, 2024

Type

pdf

Pages

8

Uploaded by SuperHumanCrocodile1969

Starting Out with Programming Logic and Design 1 Lab 2: Input, Processing, and Output This lab accompanies Chapter 2 of Starting Out with Programming Logic & Design . Name: ___________________________ Lab 2.1 Algorithms This lab requires you to think about the steps that take place in a program by writing algorithms. Read the following program prior to completing the lab. Write a program that will take in basic information from a student, including student name, degree name, number of credits taken so far, and the total number of credits required in the degree program. The program will then calculate how many credits are needed to graduate. Display should include the student name, the degree name, and credits left to graduate. Step 1: Examine the following algorithm. (Reference: Designing a Program, page 31). 1. Get the student name. 2. Get the degree program name. 3. Subtract the number of credits taken so far from the required credits for the degree. 4. Get the number of credits required for the degree program. 5. Get the number of credits the student has taken so far. 6. Display the input information in Step 1 and 2. 7. Display the calculated information. Step 2: What logic error do you spot and how would you fix it? Critical Review An algorithm is a set of well-designed logical steps that must take place in order to solve a problem. The flow the algorithm takes is sequential. For example, before you process calculations, all data needed should be retrieved. Help Video: Double click the file to view video
Starting Out with Programming Logic and Design 2 Step 3: What steps require user interaction (Ex: user must type in some input)? Lab 2.2 Pseudocode Critical Review Pseudocode is an informal language that has no syntax rules and is not meant to be compiled or executed. The flow the program takes is sequential. For example, before you ask for input, you should display what information you want from the user. //Comments are done by putting two forward slashes before the lines you want to //document. Comments are used to explain code. Variables are named storage locations. "Declare" is the keyword used before naming a variable. Data types are: Real for decimal numbers, Integer for whole numbers, and String for a series of characters. Follow the rules for naming variables: (1) must be one word, no spaces, (2) usually no punctuation characters, only letters and numbers, and (3) name cannot start with a number. "Display" is the keyword used to print something to the screen. Any information needed to be displayed to the user should be put inside quotation marks such as Display “This is how you print something to the screen” . When using display to print both a string and the value of a variable, a comma is used, such as Display “Here is the average”, average . "Input" is the keyword used to get the user to enter data. The data value entered by the user will be placed in the variable that follows the keyword input such as Input variableName . "Set" is the keyword used before a calculation. Standard math operators are used, such as + - * / MOD ^. Operators can be combined in one calculation, but it is wise to group expressions together using parentheses. Remember the order of operations. Some examples are Set sale = price discount and Set average = (test1 + test2 + test3) / 3 . Help Video: Double click the file to view video
Starting Out with Programming Logic and Design 3 This lab requires you to think about the steps that take place in a program by writing pseudocode. Read the following program prior to completing the lab. Write a program that will take in basic information from a student, including student name, degree name, number of credits taken so far, and the total number of credits required in the degree program. The program will then calculate how many credits are needed to graduate. Display should include the student name, the degree name, and credits left to graduate. Step 1 : This program is most easily solved using just five variables. Identify potential problems with the following variables declared in the pseudocode. Assume that the college has the ability to offer half credits. (Reference: Variable Names, page 39-40). Variable Name Problem (Yes or No) If Yes, what’s wrong? Declare Real creditsTaken Declare Real credits Degree Declare Int creditsLeft Declare Real studentName Declare String degreeName Step 2: Complete the pseudocode by writing the two missing lines. (Reference: Prompting the User, page 42). Display “Enter student name.” Display “Enter degree program.” Input degreeName Input creditsDegree Display “Enter the number of credits taken so far.” Step 3 : What two things are wrong with the following calculation? (Reference: Variable Assignment and Calculations, page 43). creditsLeft = creditsTaken creditsDegree Step 4: Write the exact output you would expect from the following line of code if the user of the program enters “Bill Jones”. (Reference: Displaying Items, page 40 41). Display “The student’s name is “, studentName
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help