Search Header Logo
DCS1101 - Week 12 (Structures)

DCS1101 - Week 12 (Structures)

Assessment

Presentation

Computers

University

Practice Problem

Easy

Created by

Yasmin Basiran

Used 1+ times

FREE Resource

30 Slides • 8 Questions

1

media

2

Learning Contents

  • Introduction to structures

  • Structure syntaxes

  • The application of syntaxes

3

media

4

media

5

media

6

media

7

Multiple Choice

A structure in C++ is best described as:

1
A predefined class that cannot be modified.
2
A built-in data type that only holds integers.
3
A collection of functions that perform operations.
4
A user-defined data type that groups variables of different types.

8

Multiple Choice

Which keyword is used to declare a structure?

1
define
2
class
3
object
4
struct

9

Multiple Choice

A structure can contain:

1

Only integers

2

Only floating numbers

3

Any combination of data types

4

Only characters

10

media

11

media

12

media

13

media

14

media

15

media

16

media

17

media

18

media

19

media

20

media

21

media

22

media

23

media

24

media

25

media

26

Multiple Choice

What is the output of the following code?

struct Box { int w; int h; };

int main() {

Box b = {5, 8};

cout << b.w + b.h;

}

1
10
2
12
3
13
4
15

27

Multiple Choice

What is the error of the following?

struct Person {

int age;

string name;

};

int main() {

cout << Person.age;

}

1
Can access member 'age' directly from struct type 'Person'.
2
The struct definition is missing a constructor for 'Person'.
3
The 'cout' statement is incorrectly formatted with '<<' operator.
4
Cannot access member 'age' directly from struct type 'Person'; need an instance.

28

Multiple Choice

What is the output of this?

struct Num { int n; };

int main() {

Num x = {7};

Num y = x;

y.n = 20;

cout << x.n;

}

1
7
2
10
3
20
4
7.0

29

Multiple Choice

What is the error of this code?

struct Item {

string name;

float price;

};

Item item("Soda", 2.5);

1
The struct 'Item' lacks a constructor for initialization.
2
The struct 'Item' is missing a destructor.
3
The 'price' field should be an integer type.
4
The 'name' field should be declared as a char array.

30

Previous Topic

Relation to Structures

Variables

Structures contain multiple variable types.

Arrays

Structures allow arrays as members, and arrays of structures.

Functions

Structures can be passed to functions by value or reference.

Loops

Often used to process structure arrays (for, while).

Selection (if/switch)

To compare structure members (e.g., highest price).

File Processing

Structures store data that can later be written to files.

31

Real Programming Uses

  • To group different info about one item (student, car, book).

  • To create arrays of objects easily.

  • To pass related data into functions without many parameters.

  • To create more complex data types before learning classes/objects.

32

Real Programming Uses

  • Games (player stats)

  • Finance apps (transaction records)

  • University systems (student database)

  • Inventory systems (products)

  • File handling records

33

34

The first inventory systen

media

35

Material Requirements Planning (MRP) – Late 1960s

  • Developed by IBM and large manufacturing companies.

  • Used on early mainframe computers.

  • Helped factories track inventory, production schedules, and materials needed.

  • Companies like Black & Decker were among the first major adopters (1964).

36

Timeline for MRP

Year

System

Notes

Pre-1960s

Manual, paper forms

No software; physical cards & ledgers.

1960s

MRP (Material Requirements Planning)

First computerized inventory system on mainframes.

1970s

MRP II (Manufacturing Resource Planning)

Added scheduling, capacity planning.

1990s

ERP (Enterprise Resource Planning)

Integrated inventory with HR, finance, logistics (SAP, Oracle).

2000s–Today

Cloud-based inventory tools

QuickBooks, Zoho Inventory, Odoo, etc.

37

Open Ended

Imagine your college needs a system to keep track of student attendance.

How could structures and functions be used together to simplify the program design?

38

Thank you!

media

Show answer

Auto Play

Slide 1 / 38

SLIDE