Вы находитесь на странице: 1из 9

INTRODUCTION

Computers work with data


 Capture (eg. cin>>age;)
 Process (eg. temp = 5+10;)
 Store/output (eg. cout << age;)
 Retrieve (eg. file.open(“myFile.txt”);)
In memory, data values are stored as
 Single or stand-alone memory slot (simple
Slot address value
variable)
23
 Eg. int age = 23;
 Related memory slots that represent a single
aggregate data (data structure).
 Eg. Student student1 = new Student(“Juma”,
“Hamisi”, ‘M’, 23); Slot address value
… …
Juma
Hamisi
M
23
… …
 The main differences between a simple
variable and a data structure.
 Simple variables stores a single value
 Example 23 stored in variable age

 Data structure variable stores multiple


values using the same variable name
 Example both surname=Juma, firstName =
Hamisi, gender=M and age = 23 are stored under
the variable name student1
 The main differences between a simple
variable and a data structure.

 Simple variables are used for


primitive/built-in data types such as int,
float, double, etc.

 Datastructure variables are for user-defined


data types such as Student

 In C++, a user can define his/her own data by


collecting the primitive types into enum, struct,
union or class to construct a new data type
 Most of computer data is based on real-life data
sources such as a person’s information
 Using several variables is OK if representing one student
 string student1Surname;
 string student1Firstname;
 int student1Age
 char student1Gender;

 What if its 100 students?


 String student1Surname;
 …
 String student100Gender;

 That is 400 lines of code just


declaring variables!!!!!!!!!
 User-defined data types allows for a more concise
way of doing the job
struct Student{
string surname;
string firstname;
int age;
char gender;
};
 Then
 Student student1;
 Student student2;
 ….
 Student student100;

 That will be 106 lines of code…


 You already know one of them … ARRAY
 Others will be QUEUE, LIST, STACK, B-TREE,
GRAPH
 You will also learn operations on data structures
 Inserting an item
 Removing an item
 Sorting the items
 Searching
 Walking through/traversing a collection of data
structures

 These and others makes up the algorithms you will


learn in this course.

Вам также может понравиться