Imperative Programs
- Array of integers example
Write a program that stores the integer marks of a student for several
items of assessment, each of equal value. The program outputs the
total and average mark.
- A Monolithic Solution
-
Marks.cpp - Marks program, version 1
(Monolithic)
- A Library Solution
- An integer array library for the Marks program
-
MarksLib.cpp - Marks program, version 2
(Library)
- Problems with these Solutions
- User has to use (unfriendly) 0 ... indexing of arrays
- Number of items is the user's responsibility
- Marks can be directly changed
- Using
struct
s
-
MarksStruct.cpp - Marks program with structs
(Monolithic)
- Smart library solution - Lab work
- But the problems are not all gone (which remain?)
- A Class Solution
Exercises
Lab Tasks