Create A Class Circle Having Attributes Constant Float Pie and Float Radius
Create A Class Circle Having Attributes Constant Float Pie and Float Radius
Section 05
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.
...
};
#include <iostream>
using namespace std;
class Member
{
private:
// declaration of the static data members
static int A;
static int B;
static int 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
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);
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