PRACTICAL – 7.1
Create a program to understand and use static members and static member functions
#include <iostream>using namespace std;class Stat{static int a;public:static void set(int x){a = x;}static int print(){return a;}};int Stat ::a;int main(){Stat s;s.set(4);cout << s.print();return 0;}
PRACTICAL – 7.2
Create a class employee with suitable members and functions. Create an array of objects and demonstrate the use of the class using the main function.
#include <iostream>#include <string>using namespace std;class Employee{string name;int sel;public:void set_name(){cout << "Enter Name : ";cin >> name;cout << "Enter Selary : ";cin >> sel;}void get_name(){cout << "Name : " << name << endl<< "Selary : " << sel << endl;}};int main(){Employee e[100];e[0].set_name();e[1].set_name();e[0].get_name();e[1].get_name();return 0;}
PRACTICAL – 7.3
Create a class time with members hours and minutes. Write a member function ‘add’ which takes 2 arguments of type class time and demonstrate the use with a main program.
#include <iostream>#include <string>using namespace std;class class_time{int hours, minute;string detail;public:void add(int time, string s){minute = time % 60;hours = (time - minute) / 60;detail = s;}void getdata(string s){cout << "Class of " << s << " for " << hours << " Hour " << minute << " minute " << endl;}};int main(){class_time math;int time;string s;cout << "Enter time of class : ";cin >> time;cout << "Enter class Name : ";cin >> s;math.add(time, s);math.getdata(s);return 0;}
0 Comments