0% found this document useful (0 votes)
27 views11 pages

Oop Assignment

The document contains 6 programs written in C++ that demonstrate the use of classes and objects. The programs cover topics like defining classes for time, points, accounts, balls, authors and books. The time class defines methods to set, get and print time values. The point class defines methods to set coordinates, get magnitude and print points. The account class defines methods to credit amounts. The ball class defines methods to move balls and print their position and speed. The author class defines methods to set, get and print author details. The book class defines methods to set book details by linking it to an author object.

Uploaded by

khizulicious
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views11 pages

Oop Assignment

The document contains 6 programs written in C++ that demonstrate the use of classes and objects. The programs cover topics like defining classes for time, points, accounts, balls, authors and books. The time class defines methods to set, get and print time values. The point class defines methods to set coordinates, get magnitude and print points. The account class defines methods to credit amounts. The ball class defines methods to move balls and print their position and speed. The author class defines methods to set, get and print author details. The book class defines methods to set book details by linking it to an author object.

Uploaded by

khizulicious
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Submitted By Sadia Naz

Submitted To Dr.Usman
Roll no 22149
Department CS &IT
Subjact Objact oriented
programe
PROGRAME 01
#include<iostream>
Using namespace std;
Class time
{
Private:
Int hour;
Int minutes;
Int second;
Public:
Time():
Hour(0):
Minutes(0):
Second(0):
}
{
Time(int h,int m,int s):
Hour(h),minute(m),second(s)
Int gethour()const{return hour;}
Int getminute()const{return minute;
Int getsecond()const{return second;}
Voidsethour(int h){hour=(h>=0&& h<24)? h: 0;}
Void setminute(int m{minute=(m>=0&&m<60)?s:0;}
Void settime (int h,int m,int s)
{
Sethour(h);
Setminute(m);
Setsecond(s);
}
Void print()const
{
Std::cout<<”std::setfill(o)<<std::setw(2)<<minute<<”:”setw(2)
<<second<<std::endl;
}
Void nextsecond()
{
Second++
If(second==60)
{
Second=0;
Minute++;
If(minute==60)
{
Minute=0;
Hour =(hour+1)%24;
}
}
}
};
Int main();
Time t(23,24,26);
t.print();
t.nextsecond();
t.print();
return 0;
}

PROGRAME # 02
#include<iostream>
Using namepace std;
Class point
{
Public:
Point(int x=0,int y=0)
Int getx()const{return x;}
Void setx(int newx){y=new;}
Void setxy(int newx,int newy{
X=newx;
Y=newy;
}
Double getmagnitude()const{
Return std::sqrt(x*x+y*y);
}
Double getargument()const{
If(x==0)
{
Return(y>0)?M-PI/2:-M-PI/2;
}
Void print()const{
Std::cout<<”(“<<x<<”,”<<y<<”)”<<std::endl;
}
};
Int main()
{
Point p1;
Point 2;
P1.setxy(3,4);
P1.print();
Std::cout<<”magnitude:”<<p1.getmagnitude()<<std::endl;
Return 0;

PROGRME #03

#include<iostream>
Using namespace std;
Class account
{
Private:
(Int account number;
Double initial balance );
Account number (accnum),balance(initial balance)
{
Void credit(double amount)
{
Balance+amount;
}
Int main()
{
Account my account(123456,3445,2233)
My account.credit(112.30);
My account.print();
Return 0;
}

PROGRAM #04

#include<iostream>
Using namespace std;
Class ball
{
Private:
Double x,y;
Double xspeed,yspeed;
Public:
Ball(double x=0.0,double y=o.o,double xspeed=0.0,double
yspeed=0.0)
Doublegetx()const{return x;)
Double gety()const{return y;)
}
Void print()const{
Std::cout<<”ball(:<<std::fixed<<std::setprecision(2)<<y<<”)with
speed(“<<std::fixed)
Int main()
Ball (o.o,0.0,2.5,1.5);
Ball.print();
Ball.move();
Ball.print();
Return 0;
}

PROGRAME #05

#include<iostream>
Using namespace std;
Class author
{
Private:
Std::string name;
Std::string email;
Char gender;
Public:
Std::string getname()const{
Return name;
}
Std::string getemail()const
{
Return email;
}
Char getgender()const{
Return gender ;
}
Void print()const{
Std::cout<<name<<”(“std::endl;
}
};
Int main()
{
Author author (“peter jone”,);
Autor.print();
Author.setemail(“peter [email protected]”);
Author.print();
Return 0;
}

PROGRAME # 06
#include<iostream>
Using namespace std;
Class author;
Class book;
{
Private:
Std::string name;
Author*author;
Double price;
Int qtylnstock;
Public:
Book(const std::string &name,author*author,double price,int
qtylnstock=0)
Std::string getname()const{return name;}
Author*author()const{return author;}
Int getqtylnstock()const{retun qtylnstock)
Void.print()const{
Std::cout<<name<<”by”<<author-
>getname()<<”(“<<author_>getemail()<<std::endl;\}
Public:
Author(const std::string&name,const std::string&email,char
gender)
Std::string getname()const{return name;}
Std::string getemail()const{return email;}
Char getgender()const{return gender;}
};

You might also like