‫محمود عزت محمود عبدربه‬:‫االسم‬
‫ كلية الحاسبات والمعلومات جامعة الفيوم‬: ‫الكلية‬
3 :‫الجروب‬
the answer of the sheet oop
1-The class is used to define the nature of an object
2- Class-----------------Object.
3- c -to member functions of that class.
4#include <iostream>
using namespace std;
class leverage {
private:
int crowbar;
public: void pry(); };
int main () {}
5fasle
6-leverage lever1;
7-a. A class member and a class object
8- lever1.pry();
9-Private
10- int getcrow() {
return crowbar;
}
11-defined
12- classlevrage(): crowbar(0){};
13-levrage(): crowbar(1){
};
14- True
15- a. in the object of which it is a member.
16-int getcrow();
17- int leverage::getcrow(){ return crowbar;}
18- members are by default public in struct, and private in class
19 -3-------1
20-passing to a function
21-(b)
22-True
23-
can modify neither const nor non-const member data
24-False
25-void aFunc(const float jerry) const;
26- an index number.
27282930-
31323334-- d. surrounded by brackets.
35-
twoD[1][3];
36-True
37-float flarr[3][3] = {52,27,83, 94,73,49, 3,6,1};
38-name
39- accesses exactly the same array as the calling program.
40-
An array called emplist that is type is eployee of size 1000
41- emplist[16].salary;
42- the last data item to be removed.
43- bird manybirds[50];
44-false
45-manybirds[26].cheep();
464748495051- strcpy(name, blank);
52- class dog{ string breed; int age;};
5354-can be copied with the assignment operator
555657- make general classes into more specific classes.
58-derived
59-avoiding the rewriting of code
6061-false
62-protect
63-Yes, It can but not the privet
64-BosworthObj.alfunc();
65-false
66-the function of the derived class
67-#include <iostream>
uing name space std;
class bosworth{};
Bosworth() : Alphonso() {
}
68-specifies a particular class
69-true
70- Derv(int arg) : Base(arg)
71- public members of Derv. 1
72-true
73- describes “is a kind of” relationships.
74- class Tire : public Wheel, public Rubber
75-- Base::func();
76-false
777879-
false
80-stronger, aggregation
Q2)
struct new
{ int a ; string mahmoud ;float s;
};
it is alwase public ;
class new{ int a ; string mahmoud; floats; public : c1(int i , string n , double d){ id = i ; name = n
; degree = d ; }
void setId(int g) {a= g;} int getId() {return a} void setName(string n ) { name = n ;} string
getName() {return name;} void setDegree(double d ) { degree = d ;} double getDegree() {return
de gree;} }
-it is alwase privat ;
Q3)
class TwoPoint { private: int x, y; public: void set(int x, int y); };
Provide the definition of the method set.
Write the method outside the class and do not change the prototype of the method.
Write a default constructor for the class that does not have an empty parameter list.
class TwoPoint { private: int x, y; public: TwoPoint() {
}
void set(int x1, int y1); }; void TwoPoint :: set (int x1 , int y1) { x = x1 ; y = y1 ; }
Q4)
a)
~Time( int );
class TwoPoint { private: int x, y; public: void set(int x, int y); };
void ~Time( int );
b)
class Time {
private:
public:
int hour = 0;
int minute = 0;
c)
int Employee( const char *, const char * );
int Employee( const int
*, const int
* );
int second = 0; };
Q5)
class Example
}
{
public:
Example( int y = 10 )
int getIncrementedData()
{
{
cout << "Data is " << data << endl;
int data;
static int count;
};
Q6)
#include <iostream>
#include<ctime>
using namespace std;
class date{
public:
date(){
time_t now ;
struct tm nowlocal;
now=time(NULL);
data = y
return data++;
return count;
}
{
int getCount()
}
private:
nowlocal=*localtime(&now);
cout<<nowlocal.tm_mday<<"/"<<nowlocal.tm_mon+1<<"/"<<nowlocal.tm_year+1900<<endl;
}
};
int main()
{
date p;
return 0;}
Q7)
class Int { private:
int num; public:
Int() :num(0){}
Int(int age) :num(age){}
int add(Int age)
{
return(num + age.num);
}
void display()
{
cout << number <<
endl;
} }; void main() {
Int s1(5), s2(3), s3;
s3 = s1.add(s2);
s3.display(); }
Q8)
class Tollbooth { private: unsigned totalCars;
:totalCars(0), totalAmount(0.0){}
void payingCar()
{
void nopayCar()
totalCars++;
{
totalCars++;
double totalAmount; public:
totalAmount += 0.50;
Tollbooth()
}
}
void display() const {
cout << "Total Cars : " << totalCars << endl;
cout << "Total
Money : " << totalAmount << endl; } }; void main() { Tollbooth t; char ch='p'; cout <<
"Press ‘p’ for pay , ‘n’ for no pay and ‘e’ for exit ..." << endl; do {
cin >> ch;
if (ch ==
'p')
t.payingCar();
else if (ch == 'n')
t.nopayCar(); }
while (ch!='e'); t.display();
}
Q9)
class Time { private:
int hor, minute, second; public:
Time() :hour(0), minute(0), second(0){}
Time(int h, int m, int s) {
hour = h;
minute = m;
second = s;
while (second >= 60)
{
second - = 60;
minute++;
}
while (minute >= 60)
{
minute - = 60;
hour++;
} } Time add(Time time) {
return Time( hour+time.hour ,
minute+time.minute , second+time.second ); } void display() const {
cout << hour <<
":" << minute << ":" << second << endl; }
};
int
main() {
return 0 ; }
Q10)
Time t1(1, 40, 30), t2(2, 30, 20), t3;
t3 = t1.add(t2);
t3.display();
string input = "AXBYCZ"; //Sample String
StringBuilder output = new StringBuilder();
char[] characters = input.ToCharArray();
for (int i = 0; i < characters.Length; i++)
{
if (i % 2 == 0)
{
if((i+1) < characters.Length )
{
output.Append(characters[i + 1]);
}
output.Append(characters[i]);
}
}
Q11)
class Employee { private:
string name;
long id; public:
void getData() {
cout << "Enter name : ";
cin>>id; } void putData() {
cout << "Name : " << name << endl;
cin>>name ;
cout << "Enter ID : ";
cout << "ID : " << id << endl;
} };
int main() {
Employee employee[5];
for (int i = 0; i < 5; i++)
{
for (int i = 0; i < 5; i++)
employee [i].putData();
{
employee [i].getData();
}
return 0 ;}
Q13)
class Publication
{
private:
string title;
float price; public:
{
cout << "Enter title : ";
void getData()
void putData()
cin >> title;
cout << "Enter price : ";
{
cout << "Title : " <<title<< endl;
cout << "Price : " <<price<< endl;
Publication p; p.putData; p.getData; }
cin >> price;
} }; void main() {
Problem 1 :
#include<iostream> using namespace std;
class Num1 {
int num1 ;
getNum1() { return num1; }
};
class Num2 {
int num2 ;
}
public: void setNum1(int n1) { Num1 = n1 ; } int
}
public:
void setNum2(int n2) { Num2 = n2 ; } int getNum2() {
return num2; }
};
void main (){ Num1 n1 ; Num2 n2 ; n1.setNum1(); n2.setNum2();
cout<<"sum =
"<<getNum1+getNum2 <<endl; cout<<"subtraction = "<< getNum1-getNum2 <<endl;
cout<<"multiplication = "<< getNum1*getNum2 <<endl; cout<<"division = "<<
getNum1/getNum2 <<endl; cout<<"module = "<< getNum1%getNum2 <<endl;}
Problem 2 :
#include<iostream> #include<string> using namespace std;
class Name {
private:
string first,second,last ;
public:
Name (){
cout<<"enter your first name "<<endl;
cin>>first;
cout<<"enter your second name "<<endl;
cin>>second;
cout<<"enter your last name
"<<endl;
cin>>last;
}
void display (){
"<<first<<" "<< second<<""<<last<<endl;
}
cout<<"welcome to our programe my dear
~Name(){}
};
class Time {
private:
int hours,minutes,seconds ;
public:
Time (){
cout<<"enter the hours ... minutes ... seconds "<<endl;
cin>>hours>>minutes>>seconds;
}
void display (){
cout<<"the time now is ...
"<<hours<<":"<< minutes<<":"<<seconds<<endl;
}
~Time(){}
};
class Numbers {
private:
int num1,num2,num3 ;
public:
Numbers(){
cout<<"enter 3 numbers "<<endl;
cin>>num1>>num2>>num3;
}
void display (){
cout<<"the sum is ...
"<<num1+num2+num3<<endl;
cout<<"the multiplication is ...
"<<num1*num2*num3<<endl;
}
~Numbers(){}
};
int main () { Name name; name.display();
Time time; time.display(); }
Numbers numbers;
numbers.display();
Download

محمود عزت محمود كلية الحاسبات g3