Lecture_Notes_18

Lecture_Notes_18 - Problem Solving 1. Understand the...

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

View Full Document Right Arrow Icon
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
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
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. }
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 11

Lecture_Notes_18 - Problem Solving 1. Understand the...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online