SlideShare ist ein Scribd-Unternehmen logo
1 von 16
Downloaden Sie, um offline zu lesen
Visual Logic - Project 1

Introduction

       This project lays the foundation for programming as a problem-
solving technique. Basic concepts of input and output are covered, as well
as the distinction between logic and syntax of a particular programming
language.

In this project you will learn that…
   • Variables are storage locations used for holding input and processing
       information.
   • Each variable has two components: its name and its value.
   • Input statements are used to get data into variables.
   • Expressions are value-returning code elements.
   • Assignment statements are used to perform calculations and store the
       result.
   • Output statements are used to display information.
   • Input, assignment, and output statements are sufficient to write small
       programs.

Case Study (Grocery Checkout)

       This project covers input, processing, and output statements, the
minimum functions necessary for a useful computer information system.
After discussing these three statements, we will develop a working grocery
checkout program. Our solution will input the purchase price of three items
in the store. The program will determine the total price of all three items,
add 6 percent sales tax, and display the resulting totals. The solution is
presented later in this project.

1-1“Hello World”
       It is a time-honored tradition that your first program in any language
be the output message ''Hello World.” We will follow suit and write a Hello
World program using Visual Logic.
       Begin by running the Visual Logic program contained on with this
text. When the program begins, you will see two flowcharting elements,
Begin and End, connected by a flow-arrow. Click the left mouse button on
the flow- arrow; the Flowchart Elements menu should pop up (Figure 1-1).
Select Output from the popup menu to add an output element to your
flowchart. Then double-click on the newly added output element, opening
the output dialog box. Type “Hello World'' (make sure that you include the
double quotes) in the text box, and then click the OK button. Figure 1-2
shows how your flowchart should look after closing the dialog box.
Press F5 to run the program. The program executes, generating an
output dialog box that appears with the text “Hello World'' (Figure 1-3).
Congratulations! You have just written your first computer program!


1-2 Logic and Syntax
       A computer program is a solution to a problem, such as, how can
customers view and purchase products over the Internet?” or, “How can
sales representatives have immediate and accurate access to inventory data?”
Each program (or solution) has two components, its algorithm and its syntax.
An algorithm is the logical design used to accomplish a specific objective.
Various tools for representing computing algorithms are available, the two
most common being flowcharts and pseudocode. In this part of the course
we will use Visual Logic, which combines the utility of flowcharts
(graphical representations of algorithms) and pseudocode (a nontechnical
description of an algorithm) with computer simulation. Using Visual Logic,
computer algorithms may be written, saved, edited, executed, and debugged.
       Once an algorithm has been developed, it must be communicated in
an appropriate language. To communicate actions to a computer, developers
use a programming language like Visual Basic, Cs#, C++, Java, Pascal, or
Cobol (among others). Syntax refers to the specific rules of a programming
language. There are literally hundreds of programming languages to choose
from, each with its own unique syntax. Therefore, writing a computer
program involves creating a logical design to solve a problem and then
implementing that design in an appropriate syntax.
       An information system is a combination of people and technology
(computers) that collect, organize and process data to produce information.
For any information system to be useful, it must do at least three things:
input data into the system, process data within the system, and output
resulting information from the system. For example, an online catalog
information system might have input that includes the product ID for the
items a customer wishes to purchase, along with the customer’s mailing
address and credit card number. The processing could include referencing a
database to determining the cost of each item, calculating the sales tax,
computing the shipping charge based on the customer’s mailing address, and
billing the customer’s credit card the appropriate amount. The output might
include a customer receipt and reports for the sales department and the
warehouse.
1-3 Input Statements
       Remember that an information system must input data into the
system, process data within the system, and output resulting information
from the system. The first of those three tasks, inputting data into the
system, is accomplished by means of an input statement. An input statement
accepts data from the user and stores that data into a variable. A variable is a
storage location that can be accessed and changed by developer code. A
variable has a name (which does not change) and an associated data value
(which may change during execution).
       To understand the input statement, consider the following
modification to the Hello World program you just wrote. Click on the flow-
arrow above the output statement and add an input element. Double-click on
the input element, opening the input element dialog box. Type “Name”
(without the quotes) in the variable textbox and press OK. Then double-click
on the output element and change the text in the dialog box to read “Hello “
& Name (using quotes around “He1lo '' but not around Name). Your
solution should now look like Figure 1-4.




      Run the program. You will be prompted to type a value for Name.
Enter your name inside double quotes (e.g., “Dave”'). The program will then
display a message box with the appropriate greetings (e.g., “Hello Dave”;
see Figure 1-5).



Simple Programming Formats
       The Hello Name program uses an input statement to prompt the user
for a value that is stored and then reused in an output statement. The value
entered at the input prompt can be either numeric (e.g., 42 or 3.14159) or a
string (e.g., “Dave'' or “Go Big Red''). Be aware that string input data must
be entered within double quotes.
       There are some constraints with numeric data as well. Most
programming languages do not allow numeric input to include symbols such
as the percent symbol (%) or dollar sign ($) or even commas (,). Numeric
input should consist of only digits and possibly one decimal point. You will
quickly get used to using proper numeric notations for programming. Table
1-1 summarizes some common numeric notations and the correct
programming format.
Variable Summary
    • Variables are storage locations used for holding data and information.
    • Each variable has two components: its name (which does not change)
       and its value (which may change during execution).
    •
Input Statement Summary
    • Input statements are used to get data into variables.
    • In Visual Logic, the input flowchart element is a parallelagram with
       the keyword Input followed by the variable name.
    • When the input statement is executed, the user is prompted to enter a
       value using the keyboard. The value typed is then stored in the
       variable for later use.
    • String input must be placed inside double quotes.
    • Numeric input must contain only digits and possibly one decimal
       point. Percent symbols (%), dollar signs ($), and commas (,), among
       other symbols, are not allowed.
    •
1-4 Weekly Paycheck Program
       You have now written your first two computer programs, Hello World
and Hello Name. Your third program will be a bit more complicated. You
will now write a weekly paycheck program that accepts the hours worked
and the hourly rate for an employee and the program will calculate and
display the appropriate pay amount due to the employee for the current
week. This weekly paycheck program will use all three basics of an
information system-input, processing, and output-and will be developed in
steps.
       The weekly paycheck program has two input variables, Hours and
Rae. Start the Visual Logic System. (If it is already running, under the menu
click File, then New) Click on the flow-arrow and select the input element.
Repeat to add a second input element. Then double-click on each element to
add the variable names Hours and Rate (Figure 1-6). The input for the
weekly paycheck program is now complete.
1-5 Assignment Statements
       The assignment statement can be used to perform a calculation and
store the result. Addition ( + ), subtraction ( -), multiplication (*), and
division (/) are common arithmetic operations found in almost every high-
level programming language. Note that the multiplication operator is
typically an asterisk (*) rather than the traditional times operator ( X ),
because X could be mistaken as a variable name.
       To illustrate the use of the assignment statement, we return to the
weekly pay- check program. You have already used two input statements to
accept the data Hours and Rate. An assignment statement will be added to
process that data. The required calculation is straightforward. Hours times
rate produces the pay amount due.
       Returning to Visual Logic, click on a flow-arrow below the two input
statements, and then select an assignment element from the menu. Double-
click the assignment element to open the assignment edit dialog. The text
box on the left is labeled Variable, and the text box on the right is labeled
Expression. An expression is a value-returning code element, such as a
variable or mathematical formula. Most programming languages follow this
tradition of specifying the expression on the right hand side (RHS) of the
assignment statement, and the variable to store the result on the left hand
side (LHS) of the assignment statement. When executed, the right hand side
expression is evaluated first. The result of the expression is then stored into
the left hand side variable.
       Enter “Hours * Rate” (without the quotes) in the right hand expression
text box and PayAmount in the left hand text box. When finished, your
solution should look like Figure 1-7. Your program now accepts two input
values and performs an appropriate
calculation based on those input values.

Assignment Statement Summary
  • Assignment statements are used to
      perform calculations and store the
      result.
  • In Visual Logic, the assignment
      flowchart element is a rectangle with a
      variable on the left hand side (LHS)
      and an expression on the right hand
      side (RHS).
  • When executed, the expression is
      evaluated and the result is stored in the
      variable.

How to Write Arithmetic Expressions
       The calculation in the weekly paycheck program is rather
straightforward (hours times rate). As a developer, you will often have to
perform calculations that are significantly more complex. Visual Logic
supports seven arithmetic operators, evaluated in the order of operator
precedence shown in Table 1-2. Operators of the same precedence are
evaluated left-to-right. Parentheses can be used to override the default
precedence order.
There are three operators related to division. Regular division (/)
produces a decimal value if necessary. Integer division (  ) and integer
remainder (Mod) require integer arguments and produce an integer answer.
Integer division is the integer result, throwing away any remainder. Integer
remainder is the amount leftover after taking out as many whole occurrences
of the numerator from the divisor as possible.

1-6 Output Statements
       Output can occur in many forms. Two common types of output are
screen output and printed output, both of which are visual. Sound output is
common through speakers. Eventually we will probably have output
involving the other senses (touch, smell, and taste) as well. Information
saved to a storage device such as a floppy disk, hard disk, or CD is also
considered to be a form of output.
       An output statement uses a dialog box to display an expression. We
conclude the paycheck program by adding an output dialog that displays an
appropriate message to the user. Add an output element to your flowchart,
and then double-click the element to enter the output expression. In the text
box, type:
       “Pay amount do. is “ & FormatCurrency(PayAmount)
Save this output expression. Your completed flowchart should look like
Figure 1-8.
Press F5 to run the program. The program prompts the user to enter a
value for hours, and then prompts the user again for a value for rate. The
calculation is made and the information is displayed to the user in an output
dialog box. For example, Figure 1-9 shows the output generated by input
values of 30 hours and 8 dollars per hour rate.




       Congratulations! You have just written your third computer program!
From the Visual Logic menu, select File->Save to save this program. We
will revise this program in Project 2.
Intrinsic Functions
       The Weekly Paycheck Solution uses the intrinsic emotion
FormatCurrency() to display a numeric value in a currency format, including
a leading dollar sign, two decimal places, and delimiting commas as
necessary. Intrinsic functions are predefined commands that provide
developers with common, helpful functionality. Intrinsic functions are
divided into several categories, including math functions, business functions,
string functions, time and date functions, conversion functions, file access
functions, and so on. Another intrinsic function is FormatPercent(), which
takes a decimal percent value and converts it to its equivalent value with a
percent symbol and two decimal places. Abs() accepts a numeric value and
produces the absolute value equivalent. Int() accepts a decimal value and
produces the integer whole value. Round() accepts a decimal value and
produces the nearest integer value. Finally, Random() accepts an integer
value N and produces a random integer between O and (N-1). Table 1-4
shows examples of these intrinsic functions.
Output Statement Summary
  • Output statements are used to display information.
  • In Visual Logic, the output flowchart element is a parallelogram with
     the keyword Output followed by an output expression.
  • When executed, string literals are displayed exactly as typed inside
     the containing quotes.
  • When executed, expressions are evaluated and the result is displayed.

1-7 Debugging with Visual Logic
      Even the best developers will eventually make mistakes. A
programming mistake is often called a bug, although the term error is
probably more appropriate. Visual Logic provides debugging support to help
you track down and fix your errors. Figure 1-10 shows the execution and
debugging portion of the Visual Logic standard toolbox. Note that these
functions are also available under the Debug menu item. Run is the
command that executes the simulator. Pause stops the simulation on the
current command. Terminate ends the execution of the current program.




       The last two options, Step Into and Step Over, allow a paused
program to execute one step at a time. When the program's paused, the
Variable Watch window appears displaying the current values for all
program variables. Step into takes you to the next command, and will go into
a structure like a condition or a loop (which we discuss in the following
projects). Step Over takes you to the next command at the same level as the
current command. Using the step commands to study the program variable
values as each statement executes can be helpful in determining why your
program is generating an error.
Case Study – Grocery Checkout
       Our grocery checkout problem requires three input values (the prices
of the three items), three calculations (the subtotal of the three items the
appropriate sales tax, and the resulting total), and a single output (the
resulting total). Let us see how this can be done in Visual Logic. Below are
the steps we use when solving this problem.
1 . From the visual Logic menu, select File->New to start a new program.
Add three input elements to your flowchart. Enter the variable names Iteml,
Item2, and Item3 respectively.
2. Add an assignment element to your flowchart.
Enter subtotals as the result variable, and enter
Iteml + Item2 + Item3 as the expression.
3. Add a second assignment element to your
flowchart. Set the variable salesTax to be the
result of the expression subtotal * 0.06 .
4. Add c third assignment element that sets Total
to be the sum of SubTotal + SalesTax.
5. Display the Total with an appropriate output
statement. Your solution should look something
like Figure 1-11
6. Run your program to see if it works. If the input
values ore 10, 20, and 30, the output should be
“Your purchase total is $63.60.”

       After finishing the program, you might ask,
“There are three assignment statements in the
solution. Can it be done with only one assignment
statement?''
       The answer is yes. You could have set Total
equal to the following:

      Total = (Item l + Item2 + Item3) * 1.06

Both solutions are right because they both produce
the correct result. It is a subjective question as to
which, if either, is the better solution.
Review Questions
1. Consider the similarities and differences between developing an algorithm
and developing syntax. What skills are required for each activity? What is
the added value for each activity?

2. Identify possible input, processing, and output for a video store's rental
checkout system.

3. Imagine you are an entrepreneur with access to some of the Innovative
output technologies regarding smell, touch, and taste. Identify some business
uses of these technologies that you think might become profitable.
Programming Exercises

1-1. Run the Numbers. Write a program with two input valued. The
program should display the sum, difference, quotient, product, and average
of the two numbers.

1-2. A Rose by any Other Name. Paulette has just planted a large rose
garden that she wants to fertilize. She knows the area of her rose garden in
square feet, but the fertilizer is measured by the square yard. Write a
program that converts square feet (input) to square yards (output).

1-3. “As I was gong to St. Ives . . .” consider the following nursery rhyme:

      As I was going to St. Ives, I met a man with seven wives. Every wife
      had seven sacks, every sack had seven cats, and every cat had seven
      kittens. Kittens, cats, sacks, and wives, how many were going to St.
      Ives?

The question at the end of the rhyme is a trick question because only the
narrator is going to St. Ives. Write a program to determine the total number
of things (including people, animals, and sacks) that were met by the
narrator.

1-4. Twenty thousand Leagues Under the Sea. Jules Verne's Twenty
Thousand Leagues Under the Sea is the story of Captain Nemo and his
fantastic submarine Nautilus. The story is told from the perspective of
Professor Aronnax, who entered the Nautilus as a prisoner but later is treated
as a guest. It is a story of intrigue and suspense, of respect and revenge. At
one point the professor writes, “I have crossed 20,000 leagues in that
submarine tour of the world, which has revealed so many wonders.'' You can
read the book online at The University of Virginia's Electronic Text Center,
http'//etext.lib.virginia.edu
        Perform an Internet search to find the conversion ratios between
leagues and nautical miles. Then write a program that converts leagues into
nautical miles and run your program to see how many nautical miles
Professor Aronnax traveled.

1-5. Jake's Problem. Jake has a car with an 8-gallon fuel tank. Jake fills his
tank with gas and then drives 60 miles to a friend's house. When he gets to
his friend's house, he has 6 gallons left in his fuel tank. Write a program that
uses three input elements to enter values for tank size, miles traveled and
gallons left. The program should calculate and display how many miles Jake
can drive on a full tank of gas. (Note: Be sure to use Input elements to accept
the values 8, 60, and 6 rather than hard coding them into your solution.)

1-6. Correct Change. Write a program to assist a cashier with determining
correct change. The program should have one input, the number of cents to
return to the customer. The output should be the appropriate change m
quarters, dimes, nickels and cents. Hint: Consider how integer division (  )
and integer remainder (Mod) can be used as part of your solution.

Weitere ähnliche Inhalte

Was ist angesagt?

Introduction to systems programming
Introduction to systems programmingIntroduction to systems programming
Introduction to systems programmingMukesh Tekwani
 
Types of Programming Errors
Types of Programming ErrorsTypes of Programming Errors
Types of Programming ErrorsNeha Sharma
 
Fundamentals of Computers
Fundamentals of ComputersFundamentals of Computers
Fundamentals of ComputersAnkur Kumar
 
Fundamentals of Language Processing
Fundamentals of Language ProcessingFundamentals of Language Processing
Fundamentals of Language ProcessingHemant Sharma
 
Raster scan system
Raster scan systemRaster scan system
Raster scan systemMohd Arif
 
file handling c++
file handling c++file handling c++
file handling c++Guddu Spy
 
Let us C (by yashvant Kanetkar) chapter 3 Solution
Let us C   (by yashvant Kanetkar) chapter 3 SolutionLet us C   (by yashvant Kanetkar) chapter 3 Solution
Let us C (by yashvant Kanetkar) chapter 3 SolutionHazrat Bilal
 
OpenGurukul : Language : C Programming
OpenGurukul : Language : C ProgrammingOpenGurukul : Language : C Programming
OpenGurukul : Language : C ProgrammingOpen Gurukul
 
Présentation ios Ragheb Gmira
Présentation ios  Ragheb GmiraPrésentation ios  Ragheb Gmira
Présentation ios Ragheb GmiraRagheb Gmira
 
2. operators in c
2. operators in c2. operators in c
2. operators in camar kakde
 
Clipping in Computer Graphics
Clipping in Computer GraphicsClipping in Computer Graphics
Clipping in Computer GraphicsLaxman Puri
 
Presentation on mini dictionary using C language
Presentation on  mini dictionary using C languagePresentation on  mini dictionary using C language
Presentation on mini dictionary using C languagePriya Yadav
 
introduction to c language
 introduction to c language introduction to c language
introduction to c languageRai University
 

Was ist angesagt? (20)

Introduction to systems programming
Introduction to systems programmingIntroduction to systems programming
Introduction to systems programming
 
Graphics in C++
Graphics in C++Graphics in C++
Graphics in C++
 
Programming Language
Programming LanguageProgramming Language
Programming Language
 
Enums in c
Enums in cEnums in c
Enums in c
 
Types of Programming Errors
Types of Programming ErrorsTypes of Programming Errors
Types of Programming Errors
 
Fundamentals of Computers
Fundamentals of ComputersFundamentals of Computers
Fundamentals of Computers
 
Dynamic Memory Allocation in C
Dynamic Memory Allocation in CDynamic Memory Allocation in C
Dynamic Memory Allocation in C
 
Fundamentals of Language Processing
Fundamentals of Language ProcessingFundamentals of Language Processing
Fundamentals of Language Processing
 
Raster scan system
Raster scan systemRaster scan system
Raster scan system
 
file handling c++
file handling c++file handling c++
file handling c++
 
Let us C (by yashvant Kanetkar) chapter 3 Solution
Let us C   (by yashvant Kanetkar) chapter 3 SolutionLet us C   (by yashvant Kanetkar) chapter 3 Solution
Let us C (by yashvant Kanetkar) chapter 3 Solution
 
OpenGurukul : Language : C Programming
OpenGurukul : Language : C ProgrammingOpenGurukul : Language : C Programming
OpenGurukul : Language : C Programming
 
SPL 5 | scanf in C
SPL 5 | scanf in CSPL 5 | scanf in C
SPL 5 | scanf in C
 
Présentation ios Ragheb Gmira
Présentation ios  Ragheb GmiraPrésentation ios  Ragheb Gmira
Présentation ios Ragheb Gmira
 
2. operators in c
2. operators in c2. operators in c
2. operators in c
 
Clipping in Computer Graphics
Clipping in Computer GraphicsClipping in Computer Graphics
Clipping in Computer Graphics
 
Header files in c
Header files in cHeader files in c
Header files in c
 
Presentation on mini dictionary using C language
Presentation on  mini dictionary using C languagePresentation on  mini dictionary using C language
Presentation on mini dictionary using C language
 
introduction to c language
 introduction to c language introduction to c language
introduction to c language
 
Programming in c
Programming in cProgramming in c
Programming in c
 

Ähnlich wie Visual Logic Project - 1

Program logic and design
Program logic and designProgram logic and design
Program logic and designChaffey College
 
Cis 115 week 7 i lab sales tax solution
Cis 115 week 7 i lab sales tax solutionCis 115 week 7 i lab sales tax solution
Cis 115 week 7 i lab sales tax solutionarnitaetsitty
 
COM 211 PRESENTATION.pptx
COM 211 PRESENTATION.pptxCOM 211 PRESENTATION.pptx
COM 211 PRESENTATION.pptxAnasYunusa
 
Programming Presentation.pptx
Programming Presentation.pptxProgramming Presentation.pptx
Programming Presentation.pptxAungMyintTun3
 
What is algorithm
What is algorithmWhat is algorithm
What is algorithmmshoaib15
 
Comp 122 lab 6 lab report and source code
Comp 122 lab 6 lab report and source codeComp 122 lab 6 lab report and source code
Comp 122 lab 6 lab report and source codepradesigali1
 
Chapter 2(1)
Chapter 2(1)Chapter 2(1)
Chapter 2(1)TejaswiB4
 
AOA Week 01.ppt
AOA Week 01.pptAOA Week 01.ppt
AOA Week 01.pptINAM352782
 
Fundamentals of Programming Lecture #1.pptx
Fundamentals of Programming Lecture #1.pptxFundamentals of Programming Lecture #1.pptx
Fundamentals of Programming Lecture #1.pptxEyasu46
 
Problem Solving Techniques
Problem Solving TechniquesProblem Solving Techniques
Problem Solving TechniquesAshesh R
 
Algorithm and c language
Algorithm and c languageAlgorithm and c language
Algorithm and c languagekamalbeydoun
 
INTRODUCCIÓN A LA PROGRAMACIÓN
INTRODUCCIÓN A LA PROGRAMACIÓNINTRODUCCIÓN A LA PROGRAMACIÓN
INTRODUCCIÓN A LA PROGRAMACIÓNBenjaminAnilema
 
Csc 130 class 2 problem analysis and flow charts(2)
Csc 130 class 2   problem analysis and flow charts(2)Csc 130 class 2   problem analysis and flow charts(2)
Csc 130 class 2 problem analysis and flow charts(2)Puneet narula
 
1. User InterfaceCreate a simple text-based user interface wher.pdf
1. User InterfaceCreate a simple text-based user interface wher.pdf1. User InterfaceCreate a simple text-based user interface wher.pdf
1. User InterfaceCreate a simple text-based user interface wher.pdfConceptcreations1
 
Week 2 iLab TCO 2 — Given a simple problem, design a solutio.docx
Week 2 iLab TCO 2 — Given a simple problem, design a solutio.docxWeek 2 iLab TCO 2 — Given a simple problem, design a solutio.docx
Week 2 iLab TCO 2 — Given a simple problem, design a solutio.docxmelbruce90096
 

Ähnlich wie Visual Logic Project - 1 (20)

Chapter 2- Prog101.ppt
Chapter 2- Prog101.pptChapter 2- Prog101.ppt
Chapter 2- Prog101.ppt
 
ArduinoWorkshop2.pdf
ArduinoWorkshop2.pdfArduinoWorkshop2.pdf
ArduinoWorkshop2.pdf
 
Program logic and design
Program logic and designProgram logic and design
Program logic and design
 
PRELIM-Lesson-2.pdf
PRELIM-Lesson-2.pdfPRELIM-Lesson-2.pdf
PRELIM-Lesson-2.pdf
 
Cis 115 week 7 i lab sales tax solution
Cis 115 week 7 i lab sales tax solutionCis 115 week 7 i lab sales tax solution
Cis 115 week 7 i lab sales tax solution
 
COM 211 PRESENTATION.pptx
COM 211 PRESENTATION.pptxCOM 211 PRESENTATION.pptx
COM 211 PRESENTATION.pptx
 
Programming Presentation.pptx
Programming Presentation.pptxProgramming Presentation.pptx
Programming Presentation.pptx
 
What is algorithm
What is algorithmWhat is algorithm
What is algorithm
 
Comp 122 lab 6 lab report and source code
Comp 122 lab 6 lab report and source codeComp 122 lab 6 lab report and source code
Comp 122 lab 6 lab report and source code
 
Chapter 2(1)
Chapter 2(1)Chapter 2(1)
Chapter 2(1)
 
AOA Week 01.ppt
AOA Week 01.pptAOA Week 01.ppt
AOA Week 01.ppt
 
Fundamentals of Programming Lecture #1.pptx
Fundamentals of Programming Lecture #1.pptxFundamentals of Programming Lecture #1.pptx
Fundamentals of Programming Lecture #1.pptx
 
Problem Solving Techniques
Problem Solving TechniquesProblem Solving Techniques
Problem Solving Techniques
 
Intro To C++ - Class 14 - Midterm Review
Intro To C++ - Class 14 - Midterm ReviewIntro To C++ - Class 14 - Midterm Review
Intro To C++ - Class 14 - Midterm Review
 
Algorithm and c language
Algorithm and c languageAlgorithm and c language
Algorithm and c language
 
INTRODUCCIÓN A LA PROGRAMACIÓN
INTRODUCCIÓN A LA PROGRAMACIÓNINTRODUCCIÓN A LA PROGRAMACIÓN
INTRODUCCIÓN A LA PROGRAMACIÓN
 
Csc 130 class 2 problem analysis and flow charts(2)
Csc 130 class 2   problem analysis and flow charts(2)Csc 130 class 2   problem analysis and flow charts(2)
Csc 130 class 2 problem analysis and flow charts(2)
 
1. User InterfaceCreate a simple text-based user interface wher.pdf
1. User InterfaceCreate a simple text-based user interface wher.pdf1. User InterfaceCreate a simple text-based user interface wher.pdf
1. User InterfaceCreate a simple text-based user interface wher.pdf
 
Week 2 iLab TCO 2 — Given a simple problem, design a solutio.docx
Week 2 iLab TCO 2 — Given a simple problem, design a solutio.docxWeek 2 iLab TCO 2 — Given a simple problem, design a solutio.docx
Week 2 iLab TCO 2 — Given a simple problem, design a solutio.docx
 
C Programming Unit-1
C Programming Unit-1C Programming Unit-1
C Programming Unit-1
 

Mehr von Programming Techniques and Algorithms (12)

Visual Logic User Guide
Visual Logic User GuideVisual Logic User Guide
Visual Logic User Guide
 
Visual Logic - Process
Visual Logic - ProcessVisual Logic - Process
Visual Logic - Process
 
Visual Logic - Output
Visual Logic - OutputVisual Logic - Output
Visual Logic - Output
 
Visual Logic - Introduction
Visual Logic - IntroductionVisual Logic - Introduction
Visual Logic - Introduction
 
Visual Logic - Input
Visual Logic - InputVisual Logic - Input
Visual Logic - Input
 
ตัวอย่างการพัฒนาโปรแกรมคำนวณเงินกู้
ตัวอย่างการพัฒนาโปรแกรมคำนวณเงินกู้ตัวอย่างการพัฒนาโปรแกรมคำนวณเงินกู้
ตัวอย่างการพัฒนาโปรแกรมคำนวณเงินกู้
 
Chapter 2
Chapter 2Chapter 2
Chapter 2
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
 
01 - Introduction to Computer
01 - Introduction to Computer01 - Introduction to Computer
01 - Introduction to Computer
 
01 - Software
01 - Software01 - Software
01 - Software
 
01 - Computer System
01 - Computer System01 - Computer System
01 - Computer System
 
01 - Introduction to Computer
01 - Introduction to Computer01 - Introduction to Computer
01 - Introduction to Computer
 

Kürzlich hochgeladen

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 

Kürzlich hochgeladen (20)

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 

Visual Logic Project - 1

  • 1. Visual Logic - Project 1 Introduction This project lays the foundation for programming as a problem- solving technique. Basic concepts of input and output are covered, as well as the distinction between logic and syntax of a particular programming language. In this project you will learn that… • Variables are storage locations used for holding input and processing information. • Each variable has two components: its name and its value. • Input statements are used to get data into variables. • Expressions are value-returning code elements. • Assignment statements are used to perform calculations and store the result. • Output statements are used to display information. • Input, assignment, and output statements are sufficient to write small programs. Case Study (Grocery Checkout) This project covers input, processing, and output statements, the minimum functions necessary for a useful computer information system. After discussing these three statements, we will develop a working grocery checkout program. Our solution will input the purchase price of three items in the store. The program will determine the total price of all three items, add 6 percent sales tax, and display the resulting totals. The solution is presented later in this project. 1-1“Hello World” It is a time-honored tradition that your first program in any language be the output message ''Hello World.” We will follow suit and write a Hello World program using Visual Logic. Begin by running the Visual Logic program contained on with this text. When the program begins, you will see two flowcharting elements, Begin and End, connected by a flow-arrow. Click the left mouse button on the flow- arrow; the Flowchart Elements menu should pop up (Figure 1-1).
  • 2. Select Output from the popup menu to add an output element to your flowchart. Then double-click on the newly added output element, opening the output dialog box. Type “Hello World'' (make sure that you include the double quotes) in the text box, and then click the OK button. Figure 1-2 shows how your flowchart should look after closing the dialog box.
  • 3. Press F5 to run the program. The program executes, generating an output dialog box that appears with the text “Hello World'' (Figure 1-3). Congratulations! You have just written your first computer program! 1-2 Logic and Syntax A computer program is a solution to a problem, such as, how can customers view and purchase products over the Internet?” or, “How can sales representatives have immediate and accurate access to inventory data?” Each program (or solution) has two components, its algorithm and its syntax. An algorithm is the logical design used to accomplish a specific objective. Various tools for representing computing algorithms are available, the two most common being flowcharts and pseudocode. In this part of the course we will use Visual Logic, which combines the utility of flowcharts (graphical representations of algorithms) and pseudocode (a nontechnical description of an algorithm) with computer simulation. Using Visual Logic, computer algorithms may be written, saved, edited, executed, and debugged. Once an algorithm has been developed, it must be communicated in an appropriate language. To communicate actions to a computer, developers use a programming language like Visual Basic, Cs#, C++, Java, Pascal, or Cobol (among others). Syntax refers to the specific rules of a programming language. There are literally hundreds of programming languages to choose from, each with its own unique syntax. Therefore, writing a computer program involves creating a logical design to solve a problem and then implementing that design in an appropriate syntax. An information system is a combination of people and technology (computers) that collect, organize and process data to produce information. For any information system to be useful, it must do at least three things: input data into the system, process data within the system, and output resulting information from the system. For example, an online catalog information system might have input that includes the product ID for the items a customer wishes to purchase, along with the customer’s mailing address and credit card number. The processing could include referencing a database to determining the cost of each item, calculating the sales tax, computing the shipping charge based on the customer’s mailing address, and billing the customer’s credit card the appropriate amount. The output might include a customer receipt and reports for the sales department and the warehouse.
  • 4. 1-3 Input Statements Remember that an information system must input data into the system, process data within the system, and output resulting information from the system. The first of those three tasks, inputting data into the system, is accomplished by means of an input statement. An input statement accepts data from the user and stores that data into a variable. A variable is a storage location that can be accessed and changed by developer code. A variable has a name (which does not change) and an associated data value (which may change during execution). To understand the input statement, consider the following modification to the Hello World program you just wrote. Click on the flow- arrow above the output statement and add an input element. Double-click on the input element, opening the input element dialog box. Type “Name” (without the quotes) in the variable textbox and press OK. Then double-click on the output element and change the text in the dialog box to read “Hello “ & Name (using quotes around “He1lo '' but not around Name). Your solution should now look like Figure 1-4. Run the program. You will be prompted to type a value for Name. Enter your name inside double quotes (e.g., “Dave”'). The program will then display a message box with the appropriate greetings (e.g., “Hello Dave”;
  • 5. see Figure 1-5). Simple Programming Formats The Hello Name program uses an input statement to prompt the user for a value that is stored and then reused in an output statement. The value entered at the input prompt can be either numeric (e.g., 42 or 3.14159) or a string (e.g., “Dave'' or “Go Big Red''). Be aware that string input data must be entered within double quotes. There are some constraints with numeric data as well. Most programming languages do not allow numeric input to include symbols such as the percent symbol (%) or dollar sign ($) or even commas (,). Numeric input should consist of only digits and possibly one decimal point. You will quickly get used to using proper numeric notations for programming. Table 1-1 summarizes some common numeric notations and the correct programming format.
  • 6. Variable Summary • Variables are storage locations used for holding data and information. • Each variable has two components: its name (which does not change) and its value (which may change during execution). • Input Statement Summary • Input statements are used to get data into variables. • In Visual Logic, the input flowchart element is a parallelagram with the keyword Input followed by the variable name. • When the input statement is executed, the user is prompted to enter a value using the keyboard. The value typed is then stored in the variable for later use. • String input must be placed inside double quotes. • Numeric input must contain only digits and possibly one decimal point. Percent symbols (%), dollar signs ($), and commas (,), among other symbols, are not allowed. • 1-4 Weekly Paycheck Program You have now written your first two computer programs, Hello World and Hello Name. Your third program will be a bit more complicated. You will now write a weekly paycheck program that accepts the hours worked and the hourly rate for an employee and the program will calculate and display the appropriate pay amount due to the employee for the current week. This weekly paycheck program will use all three basics of an information system-input, processing, and output-and will be developed in steps. The weekly paycheck program has two input variables, Hours and Rae. Start the Visual Logic System. (If it is already running, under the menu click File, then New) Click on the flow-arrow and select the input element. Repeat to add a second input element. Then double-click on each element to add the variable names Hours and Rate (Figure 1-6). The input for the weekly paycheck program is now complete.
  • 7. 1-5 Assignment Statements The assignment statement can be used to perform a calculation and store the result. Addition ( + ), subtraction ( -), multiplication (*), and division (/) are common arithmetic operations found in almost every high- level programming language. Note that the multiplication operator is typically an asterisk (*) rather than the traditional times operator ( X ), because X could be mistaken as a variable name. To illustrate the use of the assignment statement, we return to the weekly pay- check program. You have already used two input statements to accept the data Hours and Rate. An assignment statement will be added to process that data. The required calculation is straightforward. Hours times rate produces the pay amount due. Returning to Visual Logic, click on a flow-arrow below the two input statements, and then select an assignment element from the menu. Double- click the assignment element to open the assignment edit dialog. The text box on the left is labeled Variable, and the text box on the right is labeled Expression. An expression is a value-returning code element, such as a variable or mathematical formula. Most programming languages follow this tradition of specifying the expression on the right hand side (RHS) of the assignment statement, and the variable to store the result on the left hand side (LHS) of the assignment statement. When executed, the right hand side expression is evaluated first. The result of the expression is then stored into
  • 8. the left hand side variable. Enter “Hours * Rate” (without the quotes) in the right hand expression text box and PayAmount in the left hand text box. When finished, your solution should look like Figure 1-7. Your program now accepts two input values and performs an appropriate calculation based on those input values. Assignment Statement Summary • Assignment statements are used to perform calculations and store the result. • In Visual Logic, the assignment flowchart element is a rectangle with a variable on the left hand side (LHS) and an expression on the right hand side (RHS). • When executed, the expression is evaluated and the result is stored in the variable. How to Write Arithmetic Expressions The calculation in the weekly paycheck program is rather straightforward (hours times rate). As a developer, you will often have to perform calculations that are significantly more complex. Visual Logic supports seven arithmetic operators, evaluated in the order of operator precedence shown in Table 1-2. Operators of the same precedence are evaluated left-to-right. Parentheses can be used to override the default precedence order.
  • 9. There are three operators related to division. Regular division (/) produces a decimal value if necessary. Integer division ( ) and integer remainder (Mod) require integer arguments and produce an integer answer. Integer division is the integer result, throwing away any remainder. Integer remainder is the amount leftover after taking out as many whole occurrences of the numerator from the divisor as possible. 1-6 Output Statements Output can occur in many forms. Two common types of output are screen output and printed output, both of which are visual. Sound output is common through speakers. Eventually we will probably have output involving the other senses (touch, smell, and taste) as well. Information saved to a storage device such as a floppy disk, hard disk, or CD is also considered to be a form of output. An output statement uses a dialog box to display an expression. We conclude the paycheck program by adding an output dialog that displays an appropriate message to the user. Add an output element to your flowchart, and then double-click the element to enter the output expression. In the text box, type: “Pay amount do. is “ & FormatCurrency(PayAmount) Save this output expression. Your completed flowchart should look like Figure 1-8.
  • 10. Press F5 to run the program. The program prompts the user to enter a value for hours, and then prompts the user again for a value for rate. The calculation is made and the information is displayed to the user in an output dialog box. For example, Figure 1-9 shows the output generated by input values of 30 hours and 8 dollars per hour rate. Congratulations! You have just written your third computer program! From the Visual Logic menu, select File->Save to save this program. We will revise this program in Project 2.
  • 11. Intrinsic Functions The Weekly Paycheck Solution uses the intrinsic emotion FormatCurrency() to display a numeric value in a currency format, including a leading dollar sign, two decimal places, and delimiting commas as necessary. Intrinsic functions are predefined commands that provide developers with common, helpful functionality. Intrinsic functions are divided into several categories, including math functions, business functions, string functions, time and date functions, conversion functions, file access functions, and so on. Another intrinsic function is FormatPercent(), which takes a decimal percent value and converts it to its equivalent value with a percent symbol and two decimal places. Abs() accepts a numeric value and produces the absolute value equivalent. Int() accepts a decimal value and produces the integer whole value. Round() accepts a decimal value and produces the nearest integer value. Finally, Random() accepts an integer value N and produces a random integer between O and (N-1). Table 1-4 shows examples of these intrinsic functions.
  • 12. Output Statement Summary • Output statements are used to display information. • In Visual Logic, the output flowchart element is a parallelogram with the keyword Output followed by an output expression. • When executed, string literals are displayed exactly as typed inside the containing quotes. • When executed, expressions are evaluated and the result is displayed. 1-7 Debugging with Visual Logic Even the best developers will eventually make mistakes. A programming mistake is often called a bug, although the term error is probably more appropriate. Visual Logic provides debugging support to help you track down and fix your errors. Figure 1-10 shows the execution and debugging portion of the Visual Logic standard toolbox. Note that these functions are also available under the Debug menu item. Run is the command that executes the simulator. Pause stops the simulation on the current command. Terminate ends the execution of the current program. The last two options, Step Into and Step Over, allow a paused program to execute one step at a time. When the program's paused, the Variable Watch window appears displaying the current values for all program variables. Step into takes you to the next command, and will go into a structure like a condition or a loop (which we discuss in the following projects). Step Over takes you to the next command at the same level as the current command. Using the step commands to study the program variable values as each statement executes can be helpful in determining why your program is generating an error.
  • 13. Case Study – Grocery Checkout Our grocery checkout problem requires three input values (the prices of the three items), three calculations (the subtotal of the three items the appropriate sales tax, and the resulting total), and a single output (the resulting total). Let us see how this can be done in Visual Logic. Below are the steps we use when solving this problem. 1 . From the visual Logic menu, select File->New to start a new program. Add three input elements to your flowchart. Enter the variable names Iteml, Item2, and Item3 respectively. 2. Add an assignment element to your flowchart. Enter subtotals as the result variable, and enter Iteml + Item2 + Item3 as the expression. 3. Add a second assignment element to your flowchart. Set the variable salesTax to be the result of the expression subtotal * 0.06 . 4. Add c third assignment element that sets Total to be the sum of SubTotal + SalesTax. 5. Display the Total with an appropriate output statement. Your solution should look something like Figure 1-11 6. Run your program to see if it works. If the input values ore 10, 20, and 30, the output should be “Your purchase total is $63.60.” After finishing the program, you might ask, “There are three assignment statements in the solution. Can it be done with only one assignment statement?'' The answer is yes. You could have set Total equal to the following: Total = (Item l + Item2 + Item3) * 1.06 Both solutions are right because they both produce the correct result. It is a subjective question as to which, if either, is the better solution.
  • 14. Review Questions 1. Consider the similarities and differences between developing an algorithm and developing syntax. What skills are required for each activity? What is the added value for each activity? 2. Identify possible input, processing, and output for a video store's rental checkout system. 3. Imagine you are an entrepreneur with access to some of the Innovative output technologies regarding smell, touch, and taste. Identify some business uses of these technologies that you think might become profitable.
  • 15. Programming Exercises 1-1. Run the Numbers. Write a program with two input valued. The program should display the sum, difference, quotient, product, and average of the two numbers. 1-2. A Rose by any Other Name. Paulette has just planted a large rose garden that she wants to fertilize. She knows the area of her rose garden in square feet, but the fertilizer is measured by the square yard. Write a program that converts square feet (input) to square yards (output). 1-3. “As I was gong to St. Ives . . .” consider the following nursery rhyme: As I was going to St. Ives, I met a man with seven wives. Every wife had seven sacks, every sack had seven cats, and every cat had seven kittens. Kittens, cats, sacks, and wives, how many were going to St. Ives? The question at the end of the rhyme is a trick question because only the narrator is going to St. Ives. Write a program to determine the total number of things (including people, animals, and sacks) that were met by the narrator. 1-4. Twenty thousand Leagues Under the Sea. Jules Verne's Twenty Thousand Leagues Under the Sea is the story of Captain Nemo and his fantastic submarine Nautilus. The story is told from the perspective of Professor Aronnax, who entered the Nautilus as a prisoner but later is treated as a guest. It is a story of intrigue and suspense, of respect and revenge. At one point the professor writes, “I have crossed 20,000 leagues in that submarine tour of the world, which has revealed so many wonders.'' You can read the book online at The University of Virginia's Electronic Text Center, http'//etext.lib.virginia.edu Perform an Internet search to find the conversion ratios between leagues and nautical miles. Then write a program that converts leagues into nautical miles and run your program to see how many nautical miles Professor Aronnax traveled. 1-5. Jake's Problem. Jake has a car with an 8-gallon fuel tank. Jake fills his tank with gas and then drives 60 miles to a friend's house. When he gets to his friend's house, he has 6 gallons left in his fuel tank. Write a program that
  • 16. uses three input elements to enter values for tank size, miles traveled and gallons left. The program should calculate and display how many miles Jake can drive on a full tank of gas. (Note: Be sure to use Input elements to accept the values 8, 60, and 6 rather than hard coding them into your solution.) 1-6. Correct Change. Write a program to assist a cashier with determining correct change. The program should have one input, the number of cents to return to the customer. The output should be the appropriate change m quarters, dimes, nickels and cents. Hint: Consider how integer division ( ) and integer remainder (Mod) can be used as part of your solution.