0% found this document useful (0 votes)
18 views6 pages

Create A Class Circle Having Attributes Constant Float Pie and Float Radius

oop

Uploaded by

hirrah21
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)
18 views6 pages

Create A Class Circle Having Attributes Constant Float Pie and Float Radius

oop

Uploaded by

hirrah21
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/ 6

Object Oriented Programming

Section 05

Semester: Fall 2022


Faculty of Information Technology
UCP Lahore, Pakistan
Table of Contents
Semester: Fall 2022....................................................................................................................1
Lab 7:.........................................................................................................................................3
Sample code for constant member function...............................................................................3
Sample code for static data member..........................................................................................3
Lab Task...................................................................................................................................5
const data member and object................................................................................................5
Task1:........................................................................................................................................5
Task2.........................................................................................................................................5
Task 3........................................................................................................................................6
TASK 4:.....................................................................................................................................6
Lab 7:

Sample code for constant member function

class Date
{
private:

int month;
int day;
int year;

public:

Date();
Date(int, int, int);
void set_month(int);
int get_month() const; // This function does not change modify data
members of the object that calls it.
...
};

int Date::get_month() const


{
return month;
}

Sample code for static data member

#include <iostream>
using namespace std;
class Member
{

private:
// declaration of the static data members
static int A;
static int B;
static int C;

// declare public access specifier


public:
Member(){
A++;
B++;
C++;

}
// define the static member function
static void disp()
{
cout << " The value of the A is: " << A << endl;
cout << " The value of the B is: " << B << endl;
cout << " The value of the C is: " << C << endl;
}
};
// initialization of the static data members
int Member::A = 0;
int Member::B = 0;
int Member::C = 0;

int main()
{
// create object of the class Member
Member mb;
// access the static member function using the class object name
cout << " Print the static member through object name: " << endl;
mb.disp();
// access the static member function using the class name
cout << " Print the static member through the class name: " << endl;
Member::disp();

Member nb;
// access the static member function using the class object name
cout << " Print the static member through object name: " << endl;
nb.disp();
return 0;
}
Lab Task

const data member and object


Task1:
Create a class circle having attributes constant float pie and float radius. create its setter function
and getter functions must be constant. Create overloaded constructors, now create float type
function to calculate area of a circle, display function to display radius and pie values.in main
function create a constant object with parameterized constructor and try to change it value of radius
with the help of setter function.

Task2
Create a class point having x and y co-ordinates as its constant data member. Initialize data
members through appropriate constructors. Calculate the distance of a point from origin
by using Pythagoras Theorem.

Hint: The distance d of a point (x, y) from the origin according to the Pythagorean theorem
is d 2 = x2 + y2.
For taking square use #include <math.h> header file and formula

pow(variable, 2);

for taken square root use formula sqrt(variable)


Task 3
const parameter in function
write a c++ program create math class and add two number. takes const parameter in a
function for example
int Sum(const int n1, const int n2)

TASK 4:
Static attribute and function.

Punjab government wants to track laptop objects that are distributed to students

Write a C++ program that create a class Laptop have a static attribute count, which
counts the number of laptops given to the students. whenever an object created it
increase the counter by 1 and whenever an array of any number created it counts
that too. Create getCount() function static

You might also like