What We Will Cover
^ top
1.1: Introduction to Programming Concepts and Methodology, C++
Learner Outcomes
At the end of the lesson the student will be able to:
- Describe what they will learn in this course
|
^ top
1.1.1: Computers and Programming
- How many people are computer science majors?
- How many people are engineering majors?
- What other kinds of majors are people pursuing?
Definitions
Computer: a machine that can manipulate data following a list of instructions
Program: a list of instructions carried out by a computer
- A computer cannot function without a program
- Despite the science fiction movies, developing computer programs requires people
- What are the people who develop computer programs called?
Developing Programs
Goal Setting Exercise
- Take about 90 seconds to complete the following exercise:
What do you want to get from this course?
Why is it important to you?
^ top
1.1.2: Examples of What You Will Learn
- As we learn how to program, we will solve some interesting problems
- Let us take a look at some examples of what you will learn in this course
- First we have some samples from homework assignments:
- printsquares: Draw shapes with ASCII text
- postal: Explore how postal bar codes work
- store: Develop our own virtual business
- madlibs: Play a game of Mad Libs
More Examples
- During the course you will learn how to develop programs like these:
- While these are not assignments this semester, you will be capable of solving these types of programming problems
Student Projects
- Toward the end of the course you will complete a project
- The purpose of the project is to utilize what you learned during the course to produce your own unique program
- In previous semesters students have completed many fascinating projects including:
- 3D shape displays
- Address books
- Ant farm simulation
- Astronomy calculations and simulations
- Bank account programs
- Battleship games (text and graphical versions)
- Dart games
- Database programs (store and retrieve selected data)
- Card games
- Digital photo manipulation (like Photoshop)
- Fortune tellers
- Enhanced Mad Libs game programs
- Mine sweeper
- Spectrographic analysis
- You too will be able to create programs like these
- Which of these look the most interesting to you?
- What would be a more interesting program for you to develop?
^ top
1.1.3: C++ and Programming
- There are many programming languages for computers
- In this course we learn how to program using C++
- C++ is one of the most popular programming languages
- It is used in many problem domains including Engineering and game programming
- Examples of programs written in C++ include:
C++ and Compilers
- C++ is a compiled language
- We must use a program known as a compiler to produce C++ programs
- A compiler is a program that translates C++ (or other programming language) into the language of the computer
- There are hundreds or thousands of different C++ compilers
- Unfortunately, they are not interchangeable and do not all work the same
- To solve this problem, we will use only one compiler for this course: g++
- The g++ compiler is a standard conformant compiler that runs on Apple, Linux and MS Windows computers
- We will discuss compilers in more depth next week
- However, you can get set up now and it is best if you start early
- For Windows, you need to install Cygwin, which contains the
g++ compiler
- Cygwin is the environment available in the CTC and our classroom
- Follow my instructions on How To Install Cygwin for best results
- For Apple Mac users, Apple's tools include the GCC
g++ compiler
- For Linux/UNIX users, you can install GCC and
g++ compilers from your distribution CD
- If you do not have a computer at home (or work) to use for assignments, then you can use the CTC
- To use the CTC, you will need a login and password
- You are automatically assigned a login and password after you enroll in this course
Check Yourself
- True or false: C++ is a popular and widely used programming language.
- What is a compiler?
- True or false: you can use any compiler you want for this course.
- Where can you find a computer for programming C++ at Cabrillo?
More Information
^ top
1.1.4: Why Study Computing and Computer Science?
- In this course we study computing and learn how to program
- There are many reasons to study and understand computing
- The following are a few good ones
Computing Puts You in Control
- Why merely create a FaceBook page when you can create the next FaceBook?
- Programming gives you the power to solve problems and eliminate repetitive, boring tasks
- Most major applications and devices, from cell phones to MS Office, are programmable
- By creating a custom program you can improve your life, or other people's lives, by putting better ideas into practice
- Computing gives you new ways of improving our lives by putting better ideas into practice
Computing Opens Doors
- There are over one billion personal computers in use (source: WikiAnswers.com, Forester Research)
- In addition, there are many billions more computers embedded in everything from cell phones to car engines, iPods and video games
- Because the number of computers is growing so fast, few careers open as many doors as computing
- Also, computer science pays well with average starting salaries of $62,328 for new grads in 2011 (source: NACE)
Computing Empowers You to do Good
- Computers are a tool to help solve problems
- With computers, you can connect technology to your community and make a world of difference
- Computers can help us improve the environment by reducing energy consumption and pollution
- With computers we can improve health care and reduce medical costs
- The human genome is analyzed and searched for patterns using computers
- Also, computers give us new ways to learn things, some of which you will experience in this course
More Information
^ top
Exercise 1.1: Introductions and Questions
Use the next 10 minutes to complete the following.
- Join a group of 3-4 people and introduce yourself to each other.
- As a group, develop one "burning question" about the course.
- Write the single question on the board.
- Select one member from your group as a spokesperson to describe your single question to the class.
Note: You do not have to turn in the answers to this exercise. However, you are expected to submit answers to subsequent exercises.
^ top
1.2: Exploring the Course
Learner Outcomes
At the end of the lesson the student will be able to:
- Navigate the course web site
- Discuss how the course is administered
- Know when assignments are due
|
^ top
1.2.1: How to be Successful in the Course
 Even Einstein had to work to learn!
- Each of us has the capability to learn the material of this course
- To learn you need to take an active part in the learning process
- As an active learner, you take responsibility for your own learning
- As the instructor, I present ideas and examples
- As the learner, you will need to work with the ideas to truly learn them
Optimizing Your Learning
- Go to class and participate.
Turn off your cell phones and pay attention to the lecture and participate in the activities. Ask questions in class. Establish good rapport with your classmates and the instructor. Get to know other students in the class during activities and breaks.
- Take notes and study them.
Take notes during the lecture. Jot down information that seems helpful in understanding the material. Read over your notes once or twice a week to reinforce what you learn.
- Complete all your homework on time.
Take responsibility for your learning and do your best with your homework. Expect assignments to take time to complete, so start working on them long before they are due.
- Seek answers to your questions.
Ask your classmates or the instructor for help when you have questions. If something in the lecture or textbook does not make sense to you, ask the instructor to explain.
- Study for tests.
Prepare for tests. No one can ace a test without studying and understanding the material.
Discussion Questions
- What should you include in your notes?
- Where do you go when you have questions?
- Who is responsible for your learning the material?
^ top
1.2.2: Useful Information and Course Resources
Email
- Please make sure your email address is correct in WebAdvisor
- When sending me an email please state your name, course number and if you are in the day or evening section
- I really do not know who you are from an email address like: fandango246@hotmail.com
- Please make sure your emails are professional, that words are spelled correctly and that you use good grammar
Online Lab Hours
- The schedule of classes lists, "4 hr 5 min online lab per week".
- You are graded, in part, on completing the online labs each week
- These online lab hours are there to complete the lab exercises in CodeLab
- You must sign up for and later purchase a CodeLab subscription
- If you do not have access to a computer, you may use one in the Computer Technology Center (CTC)
- The CTC is open, supervised and available for use as shown here: Computer Technology Center Hours
Cell Phones and Texting
- Cell phones are wonderful devices but are dispruptive in the classroom
- Texting and cell phone use are prohibited during class
Discussion Question
- How should we implement our cell phone policy for the classroom?
^ top
1.2.3: Using a Text Editor
- In the following exercise we need to use a text editor
- A text editor is a basic tool used by programmers like a word processor is used by writers
- Programmers use a text editor, rather than a word processor, because:
- A word processor saves extra characters to control formatting whereas a text editor saves text with minimal formatting
- Not all word processor files are interchangeable but text files generally are interchangeable
- Word processors tend to be slow to start and complex to use while text editors are fast and simple to use
- Most word processors can save files as plain text but we have to take care to specify the plain text format
- Some of the text editors we can use are:
- Windows: TextPad, Notepad (not recommended), WordPad
- Linux/Unix: EMACS, XEmacs, VIM, pico, nano, ...
- Mac: TextEdit, BBEdit, Text Wrangler, ...
- More information: List of text editors
- We use TextPad in the classroom and we can download it free for evaluation at home
- Since we need to learn how to use programming tools, we will use text editors in this course
- Do not use word processing programs like Word or OpenOffice for assignments
- To get us started, we will work together to use a text editor for the next exercise
^ top
Exercise 1.2: Treasure Hunt!
In this exercise we explore the course web site to see how many of our questions we can answer. We will break into teams to find answers to the questions. The first team to find all the answers and to notify the instructor wins!
To find the answers, look at the section we just covered: Useful Information and Course Resources. We will discuss the questions and answers after the first team wins.
Specifications
- With your team, find the answers to the following Exercise Questions.
- Prepare a text file named:
questions.txt with the following questions copied into the file.
- Record the answers to the questions in the text file.
- Add a comment to the top of the file that contains the name of the people on your team
- When finished, save your file to upload to Blackboard as part of assignment 1
Note: You must save your file somewhere besides a classroom computer. Your classroom computer will delete your file when you logout.
Exercise Questions
- Why do we use a text editor rather than a word processor for this exercise?
- What is your personal Blackboard login (NOT your password)?
- What do you do if you are late to class?
- Where is the instructor's contact information located?
- What is the closest building next to the instructor's office?
- What is the URL where all homework assignments are listed?
- Where are lab assignments posted?
- Where do you turn in homework assignments?
- What course should you take before this one if you are not familiar with computers?
- What Math class is needed as preparation for this class?
- What is CodeLab and why must you spend $25 to purchase it?
- What compiler must you use for this course?
- What is scholastic dishonesty?
- What is an example of acceptable help and an example of unacceptable help on assignments?
- Why is eating and drinking prohibited in the classroom?
- What are three things you should do to succeed in this course?
- How many late assignments are accepted?
- How many hours per week can you expect to spend on this course outside of the classroom?
- What is the cell phone policy for the classroom?
- When emailing the instructor, what two pieces of information should you include at a minimum?
^ top
1.3: Programming and Problem Solving
Learner Outcomes
At the end of the lesson the student will be able to:
- Describe the activity of programming
- Develop algorithms to solve simple computational problems
|
^ top
Exercise 1.3
- A computer is a machine that mechanically follows a list of instructions
- As programmers, we develop the list of instructions
- To get an idea of what programming is like, we are going to develop a simple program for your instructor
Specifications
- Join a group of 3-4 people for this exercise.
- Analyze the following problem and create a list of instructions to solve it.
- Record your instructions in text file named
walk.txt as a numbered list of steps.
- Select one member from your group as a representative to describe your answer to the class.
- Do not forget that everyone in your group must upload the text file to Blackboard when finished.
Walking Problem
Develop a precise list of instructions for walking from a spot in front of the instructor's computer to the door of the classroom. You can only use the following commands to describe the algorithm:
- face direction
- forward amount
- backward amount
- turnLeft amount
- turnRight amount
Where:
- direction is a compass heading like north or south
- amount is a number and a unit of measure like feet, paces, degrees or turns
Discussion Questions
- What was the first thing you did when you started working on the problem?
- What did you do to develop the list of instructions?
- What was the last thing you did to complete the exercise?
^ top
1.3.1: The Activity of Programming
- Programming is about developing a list of instructions for a computer to follow in solving a problem
- We could try to enter our instructions to the computer first thing
- However, software engineers have learned from experience that it is often better to do some preparatory work first
- In general, we should develop programs in two phases as shown below

- Problem definition
- Like in our exercise, the first step is to analyze and understand the problem
- Algorithm design
- Desktop testing
- After developing an algorithm, we need to verify it is correct
- To test, we develop a sample problem
- We then walk through each step mentally or manually
- If there is an error, we change the algorithm
- Translate to C++
- After we are sure the algorithm works, we then write the program code
- Code is written using a programming language
- The language we use for this course is called C++
- As we write the program code, we use a compiler to further translate our code to machine language
- Testing
- After our code compiles, we test it to make sure it:
- Does what it is supposed to do
- Does not do what it is not supposed to do
- If we are making changes, then we check that it does what it used to do
- Working program
- When it works well, we document and deliver the program
Check Yourself
- A sequence of precise instructions to accomplish a task is called a(n) ________.
- The two phases of program design are the problem solving phase followed by the ________ phase.
- The output of the problem solving phase is a(n) ________.
- Why is the problem-solving phase important?
^ top
1.3.2: Analyzing Problems
- Let us discuss some of the problem solving phase in more detail
- The first step in solving a problem is to understand it
- We need to examine the data and conditions of the problem
- The topics in this section suggest some ways to help you analyze the problem and gain an understanding
Write Down the Problem
- A good way to start analyzing a problem is to write it down in our own words
- Often times writing down the problem will lead to other ways of analyzing it
- See: Feynman Problem-Solving Algorithm
Ask Questions
- If we are given a problem, we naturally ask questions like: What? When? Why? Where? How?
- Here are some questions that are often useful to ask when faced with a programming problem:
- What output is expected?
- What format is required for the output?
- What calculation must be performed?
- What data is needed for the calculations?
- What data do I have to work with?
- Where will I get the data I do not have?
- What do the data items look like?
- How will I know when I have processed all the data?
- How many times is the process going to repeat?
- What special error conditions might happen?
- Start by reviewing this list and answering the questions that seem pertinent to the problem
- Ask more questions as the analysis continues
Draw a Diagram
- We have heard the old saying, "a picture is worth a thousand words"
- Sometimes a visualization of the problem can help us understand it
- For example, if the problem is about a rectangle then we draw a rectangle
Look for Similarities
- Often a problem reminds us of other problems we have seen before
- Recognizing similarities can give us insight into understanding the current problem
- For example, if we have seen a problem for a list of numbers then we may see similarities when given a problem dealing with a list of names
Separate the Parts
- If we have a large or complex problem, we can often break it into smaller pieces that are easier to understand
- For example, if we have to travel from one location to another, we can plan the journey in steps
More Information
Check Yourself
- The first thing we should do when developing a computer program is to ________.
- Start typing C++ code into a text editor.
- Check our compiler to verify it is fully functional and up-to-date..
- Search the Internet to see if someone else has already solved the problem.
- Investigate and understand the problem we are trying to solve.
- What are three techniques we can use to help us understand a problem?
- What are two good questions we might ask to help us understand a problem?
^ top
1.3.3: Developing Computer Algorithms
- A computer algorithm is a set of steps that a computer can use to perform a task
- Coming up with a step-by-step method for solving a problem is not always easy
- It is often a trial-and-error process requiring many attempts and refinements
- This is made more complicated because the computer can only do certain things
- Our algorithm must only contain steps that a computer can perform
Operations a Computer Can Perform
- Get data from a keyboard or other input device
- Display data on a screen or other output device
- Move data from one location to another
- Store data into and retrieve data from memory
- Perform arithmetic, such as addition and subtraction, very quickly
- Compare two data values for equality or inequality
- Process instructions in a sequence (in order)
- Process different instructions depending on conditions that are met (if this is true then do that)
- Repeat a set of instructions while certain conditions are met
Devising a Plan
- The plan for solving a problem with a computer is the algorithm
- The following section describes how to develop a computer algorithm
Check Yourself
- True or false: a computer can perform any step of an algorithm we can write down.
- A computer program often has three general steps:
- Input data
- Process the data
- Output a result
Which of the above Operations a Computer Can Perform matches each of these steps?
^ top
1.3.4: How to Develop a Computer Algorithm
1. Start with an understanding of the problem
- The first thing we need to do is write down the essence of the problem in our own words
- For our example, we can state the problem as, "Compute the average of a list of salaries"
- Once we have stated the problem we ask questions and refine our understanding
- Also, we can use the other tools we discussed for Analyzing Problems
2. Identify the inputs and the desired output
- Most computer problems have inputs and outputs
- The inputs are the data our algorithm uses
- The output is the answer to the problem
- In our example we have as input a list of numbers
- The output we want is the average of the list of numbers
3. Work out the problem by hand
- Work through an example problem by hand and understand the steps for solving the problem
- For our example, we need to compute an average of a list of numbers
- To compute an average we need the sum of all the numbers and a count of the numbers
- Thus for each number input we need to:
- Add the number to a total
- Add one to the count
- When we are done, we need to divide the total by the count
- Note that we have broken the main problem down into smaller tasks or steps
4. Describe the steps in psuedocode
- To solve the problem by hand, we worked through a series of steps
- To record the steps, we list the steps in psuedocode
- Psuedocode is an informal description of the steps for solving a problem
- Psuedocode is often used to describe computer algorithms because we can omit details the computer needs but humans do not
- This makes psuedocode easier for humans to work with than a programming language
- Working through the problem we have steps like:
Set total and count to 0
Get the first number
Add the number to total
Add 1 to count
Get the second number
Add the number to total
Add 1 to count
Get the third number
Add the number to total
Add 1 to count
- By this time we see a trend and realize we need to repeat a set of steps indefinitely
- Thus we rewrite our algorithm to show repetition:
Set total and count to 0
For each number
Add the number to the total
Add 1 to the count
Divide total by count
- Note that we are only using operations that a computer can perform
5. Test your psuedocode by working a problem
- To test our algorithm, we use example data for which we can compute the answer easily
- For instance, we may use the numbers:
100
200
300
- The average is 200, so we work through our algorithm step-by-step and verify the output
Check Yourself
- Assume that there are several numbered photos each with a price. Does the following psuedocode allow a computer to find the highest priced photo?
Set photoNum to the number of the first photo
Set price to the cost of the first photo
For each photo in the sequence
If the photo is more expensive than price
Set photoNum to the current photo number
Set price to the cost of the current photo
Declare photoNum the most expensive photo
- Assume that we wanted a computer to find the most attractive photo instead of the highest priced. What changes would we need to make to the above data and psuedocode?
^ top
Exercise 1.3b
In this exercise we analyze a problem and develop an algorithm that solves the problem. The algorithm can only use Operations a Computer Can Perform.
Specifications
- Work with no more than one other person on this exercise.
- Prepare a text file named:
algorithm.txt.
- Analyze the following problem and find an algorithm to solve it.
- Record both your analysis and algorithm in the text file.
- Do not forget to save your file to upload to Blackboard as part of assignment 1.
Note: You must save your file somewhere besides a classroom computer. Your classroom computer will delete your file when you logout.
What is the paycheck amount (before taxes) for an employee who is paid hourly? You may assume that the employee does not get paid extra for overtime.
Check your answer
^ top
1.3.5: Summary
- Programming is about solving problems using a computer program
- Programs are best developed in two phases:
- Problem-solving phase
- Implementation phase
- In this section we looked at the first phase: problem solving:
- We will look at the second phase in the next section
- First step to take when solving a problem is to analyze the problem
- Second step is to develop an algorithm that solves the problem
- Only after verifying that the algorithm works do you translate it to C++
Check Yourself
Answer these questions to check your understanding. You can find more information by following the links after the question.
- What are the two main phases of the program design process? (1.3.1)
- A sequence of precise instructions which leads to a solution is called an ________________. (1.3.1)
- What is the output of the problem solving phase? (1.3.1)
- What is the first thing we should do when developing a computer program? (1.3.2)
- Start typing C++ code into a text editor.
- Check our compiler to verify it is fully functional and up-to-date..
- Search the Internet to see if someone else has already solved the problem.
- Investigate and understand the problem we are trying to solve.
- What are three techniques we can use to help us understand a problem? (1.3.2)
- What are two good questions we might ask to help us understand a problem? (1.3.2)
- What is an algorithm? (1.3.3)
- What are the steps for developing a computer algorithm? (1.3.4)
- Consider the following psuedocode for finding the best (most attractive) photo:
Pick the first photo and call it "best so far"
For each photo in the sequence
If it is more attractive than the "best so far"
Discard the "best so far"
Call this photo the "best so far"
Declare the photo "best so far" is the best photo
Is this an algorithm for finding the best photo? (1.3.4)
- Assume that each photo has a price. Give an algorithm for finding the most expensive photo. (1.3.4)
^ top
Wrap Up
Due Next: A1-Introductions and Algorithms (2/16/12)
- When class is over, please shut down your computer
- You may complete unfinished exercises at the end of the class or at any time before the next class.
^ top
Home
| Blackboard
| Day Schedule
| Eve Schedule
Syllabus
| Help
| FAQ's
| HowTo's
| Links
Last Updated: April 14 2012 @21:53:08
|