Lecture_Notes_18

# Lecture_Notes_18 - Problem Solving 1 Understand the problem...

This preview shows pages 1–4. Sign up to view the full content.

Problem Solving 1. Understand the problem What is unknown? What should the program do? What is known? Part of problem definition Background knowledge 2. Plan Have you seen this problem before? or related problem? Look at the unknowns? Can it be broken into smaller and simple sub-problems 3. Carry out the plan Design a flow-chart or pseudo-code Design various test cases 4. Check results Run various test cases

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Example: Arrays and Loops Check for Numbers in a list Objective: Compare the data of two files and output the numbers those appear in both files Pseudo code 1. Open both of the files 2. Read data from file 1 and store in an array ( assume max size 200 ) 3. Read a number from file 2 4. Check the number in the array 5. if found, stop finding further and output that number to console 6. To read next number, go back to step 3
Example: Arrays and Loops Check for Numbers in a list 1. #include <iostream> 2. #include <cstdlib> 3. #include <fstream> 4. #include <cmath> 5. using namespace std; 6. int main() 7. { 8. const int MAX = 200; 9. int data[MAX]; 10. ifstream fin1( "data1.txt" ), fin2( "data2.txt" ); 11. if (!fin1 || !fin2) //if any of two file can not open 12. { 13. cout << "Unable to open files" ; 14. system( “PAUSE” ); 15. return -1; 16. }

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 04/01/2012 for the course GENE 121 taught by Professor Smucker during the Winter '11 term at Waterloo.

### Page1 / 11

Lecture_Notes_18 - Problem Solving 1 Understand the problem...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online