




















































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





















































Q:Write a program to enter two number from user and find which one is greater than other using pointer. Program: #include using namespace std; int main() { int var_1; int var_2; int* ptr1, * ptr2; ptr1 = &var_1; ptr2 = &var_2; cout << "\nCOMPARE TWO NUMBER TO FIND WHICH ONE IS GREATER THAN OTHER\n"; cout << "ENTER FIRST NUMBER\n"; cin >> var_1; cout << "ENTER SECOND NUMBER\n"; cin >> var_2; if (var_1 > var_2) { cout << var_1 << " is greater than " << var_2 << endl; } else { cout << var_2 << " is greater than " << var_1 << endl; } return 0; }
Q.Write a program in c++ to find out the maximum number in array using pointer. Program: #include using namespace std; int main() { int array[5]; int* ptr; int max; ptr = &array[0]; max = array[0]; for (int i = 0;i < 5;i++) { cout << "Enter array element " << i + 1 << " "; cin >> *ptr; ptr++; } ptr = &array[0]; for (int i = 0;i < 5;i++) {
return lengthlength;//L=W } double Geometry::Square_P() { return length+length+length+length; } double Geometry::Rectangle_A() { return lengthwidth; } double Geometry::Rectangle_P() { return 2length+2width; } int main() { int opt; double L; double W; do { cout<<"\tSELECT OPTION\n"; cout<<"1.To calcualate Area and perimeter\n"; cout<<"2.To exit\n";
cout<<"Enter option\n"; cin>>opt; switch(opt) { case 1: { cout<<" Enter Length\n"; cin>>L; cout<<"Enter Width\n"; cin>>W; Geometry geometry(L,W); if(L==W) { cout<<"\tSQUARE: LENGTH=WIDTH\n"; cout<<"Length="<
Employee e; e.display(); } //CLASSNAME.H #include class Employee // Declare class { private: // data members std::string name; int id; std::string cnic; std::string status; int age; public: //member function void getdata(); // function for getting record of 10student void display(); //function to display menu void showdata(); // function to show data of 10student }; #endif //CLASSNAME.CPP FILE #include "Employee.h" #include
#include // standard library using namespace std; void Employee::getdata() { //getting data std::cout<<"Enter Employee Name:"; std::cin.ignore(); getline(std::cin,name); std::cout<<"Enter Employee Id:"; std::cin>>id; std::cout<<"Enter Employee Age:"; std::cin>>age; std::cout<<"Enter Employee CNIC:"; std::cin.ignore(); getline(std::cin,cnic); std::cout<<"Enter Status(married/unmaried) :"; //std::cin.ignore(); getline(std::cin,status); } void Employee::showdata() { //showing record std::cout<<"Employee Name:"< std::cout<<"\t\tEMPLOYEE DATA\n"; for(int i=0;i exit(0); } } while(ch!=3); }
TOPIC: Constructor destructor Execution Program: //main.cpp #include #include "constructor_distructor.h" using namespace std; int main() { cout<<"FOR FIRST INSTANCE \n"; constructor_distructor const1(1); cout<<"FOR SECOND INSTANCE \n"; constructor_distructor const2(2); cout<<"DISTRUCTOR IS AUTOMATICALLY CALLED\n"; return 0; } //classname.h #ifndef CONSTRUCTOR_DISTRUCTOR_H #define CONSTRUCTOR_DISTRUCTOR_H class constructor_distructor { int randomvalue;
_Area_circumference(int l,int w): length(l),width(w) {} Area_circumference(double r): radius(r){} double area() { return lengthwidth; } double circumference() { return 23.14*radius; } }; int main() { Area_circumference rec(5,6); Area_circumference cir(6.6); cout<<"Area of rectangle :"<
#include using namespace std; class base { private:
cout<<" Enter Public data member of base 1\n"; cin>>base1public; cout<<" Public data member of base 1:"<>base2private; cout<<"Private data member of base 2"<>base2protected; cout<<" protected data member of base 2:"<>base2public; cout<<" Public data member of base 2:"< using namespace std;
class shape{ public : void setWidth ( int w) { width = w; } void setHeight ( int h) { height = h ; } protected : int width ; int height ; } ;// Derived c l a s s class Rectangle : public shape { public : int getArea ( ) { return width*height; } } ; int main { Rectangle Rect ;
int main() { developer obj; obj.salaryemployee(); }
#include using namespace std; class Base1 { protected: float salary = 900; }; class Base2 { protected: float bonus = 100; }; class Derived: protected Base1, protected Base2 { public: int sum() { return salary + bonus; } }; int main() {
// Creating an object of the derived class and calling the sum() function. Derived x; cout<<"your salery="< using namespace std; class Base1 { protected: float salary = 900; }; class Base2 { protected: float bonus = 100; }; class Derived: protected Base1, protected Base2 { public: int sum() { return salary + bonus; } }; int main() { // Creating an object of the derived class and calling the sum() function. Derived x;