lecture 4 Flashcards
what is a class ??
- class is a data type (like string or double),
- its variables are called objects.
- some predefined classes :- int , char , iostream
whats included in a class definition ?
- description of the kinds of values that the variables (objects) can hold
for example :- double gpa , string student_name - description of the member functions
whats a struct ?
struct is like a class but with no member functions
put labels on this struct:-
struct CDAccount
{
double balance ;
double interest ;
int term ;
} ;
struct CDAccount //struct definition
// CDaccount is the structure tag /type
{
double balance ;
double interest ; // member names are identifiers
int term ;
} ;
does the struct have a value ?
it consists of the values of its member variables
how do you specify (نحدد) memeber variables called (balance , rate , term) of a struct? write the syntax given the following struct declaration :-
CDAccount my_account, your_account ;
my_account . balance
your_account . rate
my_ account . term
how do we use structs as arguments in function calling ?
use a call by reference for a struct datetype called CDaccount with member variable named acc1, for a function called GET_DATA that doesnt return a value.
void GET_DATA (CDaccount & acc1 ) ;
writea function named SHRINK_WRAP that takes 2 arguments of type double named balance and rate and returns a structure data type named CDaccount
CDaccount SHRINK_WRAP (double balance, double rate)
what does the following line do ??
CDaccount my_account , your_account ;
your_account = my_account ;
Assigns all member variables (balance , rate ,interest) in your_account the
corresponding values in my_account
what are heirarchical strutures?
structures that contain member variables that are also structures
example:-
struct personinfo
{
double height;
int age;
date birthday; // date is a structure data type
};
struct date
{
int month;
int day;
int year;
};
given the following struct :-
struct Date
{
int month;
int day;
int year;
};
declare and initialize a due_date object of data type Date to the following values 12 /31 /2004
date due_date = { 12, 31,2004}
what does the ennumeration data type represent ?
ennum data types have values defined by a list of CONSTANTS of type int
for example :-
enum month_legnth
{
JAN = 31,
FEB = 28,
….
DEC = 31
};
Write a definition for a structure type for records
consisting of a person’s wage rate, accrued vacation
(in whole days), and status (hourly or salaried).
Represent the status as one of the two character
values ‘H’ and ‘S’.
struct
{
double wage_rate ;
int accured_vacation ;
char status ;
};
what numeric values are assigned to the following enum ?
enum Direction {NORTH, SOUTH, EAST, WEST}
the numeric values are not specified,so, the identifiers (north , south ,east,west) are assigned consecutive values starting with 0 till 3
- By default, the first enumerator has a value of ……?
- Each successive enumerator is ………..larger than
the value of the previous one, unless you ………….?
- zero
- one
- explicitly specify
a value for a particular enumerator
Why are the following illegal declarations?
enum grades{‘A’, ‘B’, ‘C’, ‘D’, ‘F’} ;
enum places{1st, 2nd, 3rd, 4th} ;
first one should be
enum grades{A, B, C, D, F};
second one , variables identifiers can’t start with numbers
what is a typedef statement ? and what’s its syntax ?
a typedef is a way of renaming a type
Syntax:
typedef existing_type_name new_type_name ;
Example:
typedef int Boolean;
the type was integer then became boolean
what is a class ?
a data ype with object as variables
whatdoes the definition of a class include ?
- Description of the kinds of values of the member
variables - Description of the member functions
syntax for member function definition ??
Returned_Type Class_Name :: Function_Name (Parameter_List)
{
Function Body Statements
}
Example :-
void DayOfYear :: output( )
{
cout < < “month = “ < < month
< < “day = “ < < day < < endl ;
}
Member function definitions identify the ………….
in which the function is a member
- class
◼ ‘::’ is the ………….operator
◼ it tells the ……… a member-………… is a member of it
◼ void DayOfYear::output( ) indicates that function
output is a member of the DayOfYear class
◼ The class name that precedes ‘::’ is a ………………
- scope resolution
- class , function
- type qualifier
◼ ‘::’ used with …………. to identify a …………………..
void DayOfYear::output( )
{
// function body
}
◼ ‘.’ used with ……….. to identify a ………….
DayOfYear birthday;
birthday.output( )
- classes
- member function
- variables
- member functions
what is encapsulation??
Encapsulation is
Combining a number of items, such as :-
variables + functions
into a single package
such as :-
an object of a class