Documente Academic
Documente Profesional
Documente Cultură
Anan Osothsilp
Semester: 2- 2014
Object Oriented Programming
Lab #1
Cover topics:
-Data vs Information
-Minimal Class Structure
-Information declaration (memory allocation for basic data type)
-Object creation
-Data getter and setter statements
Student has
gpa as Information
has
Business Entity/Class gender as Information
gpa
Information Data memory
Name Andy
name 0x38afd
Gpa 3.0 gender
string name ; //memory allocation for name. Use string to support Text type
double gpa; //memory allocation for gpa, double is data type to support real number
string gender; //memory allocation for gender. Use string to support Text type
Object Oriented Programming: Memory allocation
gpa
Information Data memory
Name Andy
name 0x38afd
Gpa 3.0 gender
Information Data
Name Andy
Gpa 3.0
Gender male
2. Add memory allocation for each information inside the class structure
3. Use Object creation statement to allocate memory space for each student
Object Oriented Programming: OOP memory allocation
Information Data
Name Andy
Gpa 3.0
Gender male
double gpa;
memory
gpa gpa
name name
gender gender
s1
s2
class Student {
public string name;
public string gender;
public double gpa;
}
Step4: Make
Step5: Use the
a variable
followingdeclaration
statement to hold
create
thememory
locationspace
of allocation
for each student
To set data for each student’s information use the following statements
s1 .name = "Andy" ;
s1.gender = "male";
s1. gpa = 3.0;
s2.name = "Kathy“;
s2.gpa = 4.0;
s2.gender = "female";
The dot operator is used to access data from each student’s information
Object Oriented Programming: Data Accessment> Data Retrival
In console application, use the following command to display first student’s name
Lab #0 : Excercise
Entity diagram Data Table
Information Data Data Data
Color
Make Model Camry Ecosport Mazda3
Consider the Entity diagram and data Table above, and develop the following c#
Statements
-Class structure for Car class
-Information declaration for each car information
-Object creation statements for to support three different objects in the data table
-Create assignment statements to store data for each car.
-Draw memory allocation for each car