Download presentation
Presentation is loading. Please wait.
Published bySheryl Manning Modified over 7 years ago
1
Algorithms, problem solving and Introduction to C++
Day 2 Algorithms, problem solving and Introduction to C++
2
Algorithms Algorithm A sequence of precise instructions which
leads to a solution (historically, the term had a more specialized meaning) Program An algorithm expressed in a language the computer can understand
3
Consider A long list of names… Bill Sally Robert Catherine Lora
Jennifer ….. How can we determine ho many instances there are of the name “Lora”?
4
Algorithm
5
An Algorithm is precise
To qualify as an algorithm, a set of instructions must completely and unambiguously specify the steps to be taken and the order in which they are taken. The person or machine carrying out the algorithm does exactly what the algorithm says, neither more nor less.
6
Computing history The Antikythera mechanism, invented some time around 100 BC in ancient Greece, is the first known mechanical calculator utilizing gears of various sizes and configuration to perform calculations. Tracked the metonic cycle still used in lunar-to-solar calendars, and which is consistent for calculating the dates of the Olympiads.
7
History The Kurdish medieval scientist Al-Jazari built programmable automata in 1206 AD. One system employed in these devices was the use of pegs and cams placed into a wooden drum at specific locations, which would sequentially trigger levers that in turn operated percussion instruments. The output of this device was a small drummer playing various rhythms and drum patterns.
8
History The Jacquard loom, which Joseph Marie Jacquard developed in 1801, uses a series of pasteboard cards with holes punched in them. The hole pattern represented the pattern that the loom had to follow in weaving cloth. Repeatable automated proceedures.
9
History Charles Babbage adopted the use of punched cards around 1830 to control his Analytical Engine. This was an engine for calculating mathematical and astronomical tables
10
History Some believe that the first computer program was written for the Analytical Engine by mathematician Ada Lovelace to calculate a sequence of Bernoulli numbers.
11
History – The difference engine
Charles Babbage also designed the first computer that actually stored a program in memory (rather then a fixed program on cards). He was unable to complete the complex machine, but was built later, and it worked perfectly!
12
History – Difference Engine
The difference engine was built recently with Legos! video video
13
Program Design Programming is a creative process
No complete set of rules for creating a program Problem Solving Phase Algorithm Implementation Phase Program Slide 1- 13
14
Problem Solving Phase Be certain the task is completely specified
What is the input? What information is in the output? How is the output organized? Develop the algorithm before implementation Experience shows this saves time in getting your program to run. Test the algorithm for correctness Slide 1- 14
15
Implementation Phase Translate the algorithm into a programming language Easier as you gain experience with the language Compile the source code Locates errors in using the programming language Run the program on sample data Verify correctness of results Results may require modification of the algorithm and program Slide 1- 15
16
Display 1.7 Slide 1- 16
17
Object Oriented Programming
An Object Abbreviated OOP Memory or State The program for the object Slide 1- 17
18
Object Oriented Programming
Objects represent “entities” we are modeling. An entity is a actor in a process
19
Creative Software Life Cycle Evaluate Goals Review For Planning System
Algorithms Creative Programs Slide 1- 19
20
Introduction to C++
21
Hands on 1 – NetBeans 8.1 IDE Open Netbeans (in application folder)
Select File/New Project Pick "C/C++ " on left, "C/C++" Application on right, hit next Give name "helloworld" Select a project location (your H drive is best), hit finish Open source folder, main.cpp Paste the following code into main.cpp, replacing the existing code. (See CodeDay2 on Wiki)
22
#include <iostream>
using namespace std; int main() { cout << "Hello, world." << endl; } Helloworld.cpp
23
Hands on – ideone (web based)
Go to ideone.com This is a web page that allows quick testing of simple programs At the bottom left corner set to C++ 14 Paste in the hello world code from sample code into main code area. Hit run button What happens?
24
Introduction to C++ Where did C++ come from?
Derived from the C language C was derived from the B language B was derived from the BCPL language Why the ‘++’? ++ is an operator in C++ and results in a cute pun Slide 1- 24
25
C++ History Bell Labs in the 1970s. Used to maintain UNIX systems
Many commercial applications written in C Bell Labs in the 1980s. Overcame several shortcomings of C Incorporated object oriented programming C remains a subset of C++ Slide 1- 25
26
A Sample C++ Program #include <iostream> using namespace std;
int main() { cout << "Hello, world." << endl; return 0; } Associates I/O libraries “main” program function Return control to operating system Program code Braces surround ALL blocks of code . Slide 1- 26
27
Display 1.9 Slide 1- 27
28
In class Make program give personnal greeting e.g. “Hello Olivia”
Make program print your address on multiple lines. Make the system print out your first name as a text banner: # # ###### # # # # #### # # # # # ## # # # # # ## # #### ##### # # # # # # # # # # # # # # # # # # # # # # # # # ## # # # # ## # # ###### # # # #### # #
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.