#include <iostream> #include<cstring> using namespace std; class Demo { private: long mno; char name[10]; public: void setMyInfo(long mno, char *name){ this->mno =mno; strcpy(this->name,name); } void displayMyInfo(){ cout<<"Name: "<<name<<endl; c…
Read more#include <iostream> using namespace std; class A { private: int a; protected: int b; public: A(int m,int n) { a=m; b=n; } // friend class declaration friend class B; }; class B { public: void display(A& t) { cout << "Sqaure of varible a = " << t.a*t.a <…
Read more5) Write a C++ program that achieve Runtime polymorphism using Virtual function.
#include <iostream> #include<cstring> using namespace std; class Media { protected: char name[40]; float price; public: Media(char *nm,float b) { strcpy(name,nm); price=b; } virtual void display() {} }; class Book:public Media { int pages; public: B…
Read more4) Write a C++ program that finds reverse no. of given no using Object Oriented .
#include <iostream> using namespace std; class ReverseNo { int n; public: void get(int m) { n=m; } void reverse() { int d,revno=0; cout<<"\n given no is: "<< n; while(n>0) { d=n%10; revno=revno*10+d; n=n/10; } cout<<"\n reverse no is : "<< revno; } }; int main() {…
Read more#include <iostream> #include <cstring> using namespace std; class Person { char name[20]; int age; public: Person(char *s, float b) { strcpy(name,s); age=b; } Person & greater(Person &y) { if(y.age>age) return y; else …
Read more2) Write a C++ program that get and display students information using pointers to objects.
#include <iostream> #include<cstring> using namespace std; class Student { int Rollno; char name[25]; public: void getdata(int rn , char *nm) { Rollno=rn; strcpy(name,nm); } void display() { cout<< "\n Roll No: "<< Rollno ; …
Read more1)Write a C++ program that finds and display sum of all array numbers using Pointer.
#include <iostream> using namespace std; int main() { // Write C++ code here cout << "Pointer and Array program"; int S[]={10,20,-30,40,50}; int *P; int i,sum=0; cout<<"\nArray numbers are: "; for(i=0;i<5;i++) { cout<<S[i] << " "; } cout<<&q…
Read more6) Write a C++ program that implements operators << , >> and * (scalar vector ) using operator overloading.
#include <iostream> using namespace std; const int N=3; class Vector { int V[N]; public: Vector() { for(int i=0;i<N;i++) V[i]=0; } Vector(int *y) { for(int i=0;i<N;i++) V[i]=y[i]; } friend Vector operator*(int a, Vector b ); friend Ve…
Read more