0% found this document useful (0 votes)
4 views15 pages

Procedures For Programming

The presentation outlines the step-by-step process of programming: analyzing a problem, creating a flowchart, writing pseudocode, coding, and debugging. It demonstrates these steps with examples in Python and C/C++, then provides practice problems for students to apply the concepts.

Uploaded by

tjenks106
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views15 pages

Procedures For Programming

The presentation outlines the step-by-step process of programming: analyzing a problem, creating a flowchart, writing pseudocode, coding, and debugging. It demonstrates these steps with examples in Python and C/C++, then provides practice problems for students to apply the concepts.

Uploaded by

tjenks106
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

Procedures for

Programming
Dr. Yili Tseng
Computer Science Program
Ferrum College
Phases for Programming
1. Think of the steps for solving the problem.
2. Draw the flow chart.
3. Convert the flow chart to pseudocode. Also identify what
variables will be used.
4. Code the program.
5. Run and debug the program.
Flow Chart
Pseudocode
Example of Developing a Python
Program
• The problem:
• Write a program which determines whether a person can
purchase alcohol in Virginia.
Develop the Problem-solving Steps

• Think and reason about the problem.


• Determine the major steps required to solve the problem.
(Based on math operations and decisions to make.)
• Two major steps are required:
• Calculate the customer’s age.
• Decide whether he can purchase alcohol based on his age.
• Draw the flow chart.
Determine What Actions Required
(Conversion to Pseudocode)
• Determine what detailed math operations and decisions are required for each major step.
• Identify variables in the meanwhile.
• Determine where to get the data.

• Calculate the customer’s age:


• age = current_year – birth_year
• Decide whether he can purchase alcohol based on his age:
• if age>=21:
print(‘eligible’)
else:
print(‘ineligible’)
Determine Where to Get Data
• Two sources of data:
• Provided by the programmer
• Ask the user to input data
Determine Where to Get Data
age = current_year – birth_year
if age>=21:
print(‘eligible’)
else:
print(‘ineligible’)

current_year=2024
birth_year = int(input(‘Enter your birth year’))
First Python Program –
Determine Eligibility for Alcohol
current_year = 2022  data input
birth_year = int(input(‘Enter your birth year.’))  data input
age = current_year - birth_year  data processing
if age>=21:
print(‘eligible’)
else:
print(‘ineligible’) data processing and data output
First C/C++ Program –
Determine Eligibility for Alcohol
#include <iostream>
using namespace std;
int main( ) {
int current_year = 2022;  data input
int birth_year;
int age;
cout << "Enter your birth year." << endl;
cin>>birth_year;  data input
age = current_year - birth_year;  data processing
Continued
if age>=21data processing
cout << “Eligible" << endl;  data output
else
cout << “Ineligible" << endl;
return 0;
}
Passing Arguments to C/C++
Programs
./test a1 b2 c4

int main(int argc, char** argv) {


……..
}

argc: argument count argv: argument vector


Practice 1
• Write a program to determine the ticket price for a
fictional Ferrum Park.
• The regular price is $30 while the price for seniors over
65 is $25.
Practice 2
• Write a program which calculate the price for a duty-free
store at an airport.
• First, it should ask whether the customer has a boarding
pass for eligibility.
• If yes, there is no tax.
• If no, the tax is 7%.
• Second, calculate the final price after tax.

You might also like