Students will · know how to perform file input and output · learn how to write algorithm for a problem and covert it to C++ source · learn problem solving in C++ · Learn merging of 2 ascending list of data · know basic sorting and searching algorithms

Course content overview

The contents are: · File input/output commands · Writing Algorithm · Problem solving using C++, students will be given a number of problems and they will write a C++ program to solve it · Merge 2 files with data stored in ascending order · Sorting method: Bubble sort · Searching methods: Sequential search and binary search

Computer lab

Software: Dev C++

Assessment: · Assignment ( Simple programming ) · Project ( More challenging programming) · Quick Tests · Term Test

WK1

Students will understand and know · How to create file for input · How to read data from a file · How to write data to a file · How to close a file

File input/output · Use <fstream.h> · To define input file using ifstream eg. ifstream(fin,”input.txt”) · To define and create output file using ofstream, eg ofstream(fout,”output.txt”) · To read data from the file eg. fin>>a; · To write data to a file eg. fout<<a; · Close files fin.close(), fout.close()

Computer lab

C++ compiler

Assignment #1: Simple file input and output problem, read data from file and output to another file

Project #1: Simple file processing, read data from file and perform counting and summation.

Quick Test #1

WK2

Students will learn: · The purpose of algorithm · How to write a easy to understand algorithm · The identification of variables before writing the algorithm

Writing algorithm before coding program

Using the listing of prime numbers problem to illustrate the writing of algorithm. Base on the algorithm, covert it into the C++ source program.

Computer lab

C++ compiler

Hands On #1:

Write algorithm to list prime numbers up to an integer N (to be input ) and list them in the format of 10 primes per line.

Hands On #1: Code the program base on the above algorithm.

WK3

Students will learn: · Read and understand the requirement of the problem · Formulation of steps to solve the problem · Writing algorithm · Convert to C++ source

Problem Solving 1: Soccer match results problem: ( Version 1 ) Given N number of soccer matches results in the file, determine - The number of drawn games - The biggest score difference among the game

Soccer match results problem: ( Version 2 ) Same problem as above, but students are required to produce the details of matches, i.e. at which game and what is the score. This is more challenging, the files need to be processed more than 1 time.

Alt method: Use array, in this case file is processed only 1 time.

Computer lab

C++ compiler

Assignment #2 Soccer match results problem (version 1)

Project #2 Soccer match results problem (version 1)

Quick Test #2

WK4

Students will learn: · Read and understand the requirement of the problem · Formulation of steps to solve the problem · Writing algorithm

Convert to C++ source

Problem Solving 2 ( string handling) Word processing problem:

Given a text file, process the text file to find number of words, sentences and produce a frequency table showing the number of occurrences for words of various length.

Requirement: - use of string functions - how to identify a sentence, by using length function and determine the word ends with punctuation - Use of array to store the frequency

Computer lab

C++ compiler

Project #3 Numbers game problem

Quick Test #3

WK5

Students will learn: · Read and understand the requirement of the problem · Formulation of steps to solve the problem · Writing algorithm

Convert to C++ source

Problem Solving 3 ( Read 2 input files)

Numbers game problem: Two Players A and B have created two files "data1.txt" and "data2.txt" , each store five integers between 1 and 5 in any order. You are to determine which player will win the game by comparing the corresponding integers in the file.

Computer lab

C++ compiler

Project #3 Numbers game problem

Quick Test #3

WK6

To test the understanding of the following: · Writing algorithm · Convert to C++ source · Problem Solving 1-3

Term Test: Algorithm and problem solving Format:

Multiple choice

True or False

Fill in the blanks

Practical ( programming )

Computer lab

C++ compiler

Test question papers

WK7

Student will learn:

Read data from two input files and merge them into a single file.

Merging Merging problem: · Write the algorithm for merging · Convert into C++ program

Computer lab

C++ compiler

Project #4

Sequential and Binary search problem

WK8

Students will learn · How to perform a sequential search using array · How to perform a binary search of ascending data in an array

Searching

· Implement of sequential search using array. · Write algorithm for binary search of ascending data stored in array · Covert to C++ source

Computer lab

C++ compiler

Project #4

Sequential and Binary search problem

WK9

Students will learn: · Bubble sort algorithm · Quick sort algorithm

Sorting methods Lesson and Demo of · Bubble sort · Quick Sort Show the students the use of recursive programming to accomplish Quick sort. The contents are: · Explaining the algorithm of bubble sort, passes, swapping and number of passes require to sort data items of size N

Explain the algorithm of quick sort, partitioning and using stacksto storethe partitions.

Computer lab

C++ compiler

Project #5:

Use random numbers to generate 20 integers, then display a bubble-sorted list in ascending and descending order.

Assessment Components: 1. There will be no End Of Year examination, assessment will be based on the following:

Assessment Methods

Weighting

Remarks

Type 1 - Term Tests

30%

Consists of several small tests and a major term test

Practical hands-On (Programming assignments and projects )

70%

Marks (base 100) will be awarded for each of the Term 1 to Term 3.

2. Marks for assignments & projects

Students will be given about 5 programming assignments (simple) and 5 programming projects( more advance) , and must be completed during the lesson period. Six to ten marks will be awarded for correct programming results, the earlier submission will score higher marks. A rough marks distribution can be as follow:

1st 10% of students completed (or those who can complete within a minimum required time ) will get 10 marks

Next 15% of students completed will get 9 marks

Next 30% of students completed will get 8 marks

Next 30% of students completed will get 7 marks

Next 15% of students completed will get 6 marks

Partially Correct: 5 marks

Did not attempt: 0 mark

The average mark is computed by total marks divided by number of assignments/projects, say M. Practical hands-on mark (base 100) will be 10xM (Round up to integer).

Topic: Problem solving in C++ObjectiveTopicResourcesRemarks· know how to perform file input and output

· learn how to write algorithm for a problem and covert it to C++ source

· learn problem solving in C++

· Learn merging of 2 ascending list of data

· know basic sorting and searching algorithms

Course content overviewThe contents are:

· File input/output commands

· Writing Algorithm

· Problem solving using C++, students will be given a number of problems and they will write a C++ program to solve it

· Merge 2 files with data stored in ascending order

· Sorting method: Bubble sort

· Searching methods: Sequential search and binary search

Software:Dev C++

· Assignment ( Simple programming )

· Project ( More challenging programming)

· Quick Tests

· Term Test

· How to create file for input

· How to read data from a file

· How to write data to a file

· How to close a file

File input/output· Use <fstream.h>

· To define input file using ifstream eg. ifstream(fin,”input.txt”)

· To define and create output file using ofstream, eg ofstream(fout,”output.txt”)

· To read data from the file eg. fin>>a;

· To write data to a file eg. fout<<a;

· Close files fin.close(), fout.close()

C++ compiler

Simple file input and output problem, read data from file and output to another file

Project #1:

Simple file processing, read data from file and perform counting and summation.

Quick Test #1

· The purpose of algorithm

· How to write a easy to understand algorithm

· The identification of variables before writing the algorithm

Writing algorithm before coding programUsing the listing of prime numbers problem to illustrate the writing of algorithm. Base on the algorithm, covert it into the C++ source program.

C++ compiler

Write algorithm to list prime numbers up to an integer N (to be input ) and list them in the format of 10 primes per line.

Hands On #1:

Code the program base on the above algorithm.

· Read and understand the requirement of the problem

· Formulation of steps to solve the problem

· Writing algorithm

· Convert to C++ source

Problem Solving 1:Soccer match results problem: ( Version 1 )

Given N number of soccer matches results in

the file, determine

- The number of drawn games

- The biggest score difference among the game

Soccer match results problem: ( Version 2 )

Same problem as above, but students are required to produce the details of matches, i.e. at which game and what is the score.

This is more challenging, the files need to be processed more than 1 time.

Alt method: Use array, in this case file is processed only 1 time.

C++ compiler

Soccer match results

problem (version 1)

Project #2

Soccer match results

problem (version 1)

Quick Test #2

· Read and understand the requirement of the problem

· Formulation of steps to solve the problem

· Writing algorithm

Problem Solving 2 ( string handling)Word processing problem:

Given a text file, process the text file to find number of words, sentences and produce a frequency table showing the number of occurrences for words of various length.

Requirement:

- use of string functions

- how to identify a sentence, by using length function and determine the word ends with punctuation

- Use of array to store the frequency

C++ compiler

Numbers game problem

Quick Test #3

· Read and understand the requirement of the problem

· Formulation of steps to solve the problem

· Writing algorithm

Problem Solving 3 ( Read 2 input files)Numbers game problem:

Two Players A and B have created two files "data1.txt" and

"data2.txt" , each store five integers between 1 and 5 in any

order. You are to determine which player will win the game by comparing the corresponding integers in the file.

C++ compiler

Numbers game problem

Quick Test #3

· Writing algorithm

· Convert to C++ source

· Problem Solving 1-3

Term Test: Algorithm and problem solvingFormat:

C++ compiler

Test question papers

Read data from two input files and merge them into a single file.

MergingMerging problem:

· Write the algorithm for merging

· Convert into C++ program

C++ compiler

Sequential and Binary search problem

· How to perform a sequential search using array

· How to perform a binary search of ascending data in an array

Searching· Implement of sequential search using array.

· Write algorithm for binary search of ascending data stored in array

· Covert to C++ source

C++ compiler

Sequential and Binary search problem

· Bubble sort algorithm

· Quick sort algorithm

Sorting methodsLesson and Demo of

· Bubble sort

· Quick Sort

Show the students the use of recursive programming to accomplish Quick sort.

The contents are:

· Explaining the algorithm of bubble sort, passes, swapping and number of passes require to sort data items of size N

C++ compiler

Use random numbers to generate 20 integers, then display a bubble-sorted list in ascending and descending order.

Assessment Components:1. There will be no End Of Year examination, assessment will be based on the following:2. Marks for assignments & projects

Students will be given about 5 programming assignments (simple) and 5 programming projects( more advance) , and must be completed during the lesson period. Six to ten marks will be awarded for correct programming results, the earlier submission will score higher marks. A rough marks distribution can be as follow:

The average mark is computed by total marks divided by number of assignments/projects, say M.

Practical hands-on mark (base 100) will be 10xM (Round up to integer).