lecture 4 Flashcards

1
Q

what is a class ??

A
  • class is a data type (like string or double),
  • its variables are called objects.
  • some predefined classes :- int , char , iostream
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

whats included in a class definition ?

A
  • description of the kinds of values that the variables (objects) can hold
    for example :- double gpa , string student_name
  • description of the member functions
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

whats a struct ?

A

struct is like a class but with no member functions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

put labels on this struct:-

struct CDAccount
{
double balance ;
double interest ;
int term ;
} ;

A

struct CDAccount //struct definition
// CDaccount is the structure tag /type
{
double balance ;
double interest ; // member names are identifiers
int term ;
} ;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

does the struct have a value ?

A

it consists of the values of its member variables

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

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 ;

A

my_account . balance
your_account . rate
my_ account . term

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

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.

A

void GET_DATA (CDaccount & acc1 ) ;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

writea function named SHRINK_WRAP that takes 2 arguments of type double named balance and rate and returns a structure data type named CDaccount

A

CDaccount SHRINK_WRAP (double balance, double rate)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

what does the following line do ??

CDaccount my_account , your_account ;
your_account = my_account ;

A

Assigns all member variables (balance , rate ,interest) in your_account the
corresponding values in my_account

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

what are heirarchical strutures?

A

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;
};

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

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

A

date due_date = { 12, 31,2004}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

what does the ennumeration data type represent ?

A

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
};

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

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’.

A

struct
{
double wage_rate ;
int accured_vacation ;
char status ;
};

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

what numeric values are assigned to the following enum ?

enum Direction {NORTH, SOUTH, EAST, WEST}

A

the numeric values are not specified,so, the identifiers (north , south ,east,west) are assigned consecutive values starting with 0 till 3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q
  • By default, the first enumerator has a value of ……?
  • Each successive enumerator is ………..larger than
    the value of the previous one, unless you ………….?
A
  • zero
  • one
  • explicitly specify
    a value for a particular enumerator
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Why are the following illegal declarations?
enum grades{‘A’, ‘B’, ‘C’, ‘D’, ‘F’} ;
enum places{1st, 2nd, 3rd, 4th} ;

A

first one should be
enum grades{A, B, C, D, F};

second one , variables identifiers can’t start with numbers

17
Q

what is a typedef statement ? and what’s its syntax ?

A

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

18
Q

what is a class ?

A

a data ype with object as variables

19
Q

whatdoes the definition of a class include ?

A
  • Description of the kinds of values of the member
    variables
  • Description of the member functions
20
Q

syntax for member function definition ??

A

Returned_Type Class_Name :: Function_Name (Parameter_List)
{
Function Body Statements
}

Example :-

void DayOfYear :: output( )
{
cout < < “month = “ < < month
< < “day = “ < < day < < endl ;
}

21
Q

Member function definitions identify the ………….
in which the function is a member

A
  • class
22
Q

◼ ‘::’ 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 ………………

A
  • scope resolution
  • class , function
  • type qualifier
23
Q

◼ ‘::’ used with …………. to identify a …………………..
void DayOfYear::output( )
{
// function body
}
◼ ‘.’ used with ……….. to identify a ………….
DayOfYear birthday;
birthday.output( )

A
  • classes
  • member function
  • variables
  • member functions
24
Q

what is encapsulation??

A

Encapsulation is
Combining a number of items, such as :-
variables + functions
into a single package
such as :-
an object of a class

25
Q

private members of a class can only be referenced
within the ………………………….

……………………….cannot be accessed directly
by the program

Changing their values requires the use of ………………………. of the class

Private variables require member functions to
perform all changing and retrieving of values
like ……….functions allow you to obtain the
values of member variables
and …………functions allow you to change the values
of member variables

A
  • definitions of member functions
  • private variables
  • public
    member functions
  • accessor
  • mutator
26
Q
  • Calling Public Members: object . publicFunction () ;
  • When a member function calls a private
    member function, object name is NOT used
A

fraction (double percent);
void BankAccount::update( )
{
balance = balance + fraction(interest_rate)* balance;
}

//fraction is a private member of the BankAccount class
// fraction is called by member function update