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