string Data Type Demonstration
string Data Type Demonstration
string Data Type Demonstration
int main()
{
string n;
cout<<"Enter the value\n";
cin>>n;
cout<<n;
cout<<"\n skipped after the space in the name......";
getch();
return 1;
}
int main()
{
string mystr;
cout << "What's your name? ";
getline(cin, mystr);
int a[WIDTH][HEIGHT];
int n,m;
int main ()
{
for (n=0;n<HEIGHT;n++)
{
for (m=0;m<WIDTH;m++)
{
a[n][m]=(n+1)*(m+1);
cout<<a[n][m]<<'\t';
}
cout<<endl;
}
return 0;
}
// Another Example of MultiDimentional Array..
#include <iostream>
using namespace std;
int main() {
int numbers[2][3];
return 0;
}
//Insertion of an Element into an array
#include<iostream>
using namespace std;
main()
{
int n=6;
int a[n], i, p, e;
cout<<"Enter the "<<n<<" Elemnts of an Array\n";
for(i=0;i<n;i++)
{
cin>>a[i];
}
cout<<"\nSpecify the Position";
cin>>p;
cout<<"\nEnter the Value\n";
cin>>e;
for(i=n-1; i>=p;i--)
{
a[i+1]=a[i];
}
a[p]=e;
for(i=0;i<=n;i++)
{
cout<<a[i]<<" ";
}
}
//Deletion of an Element from an array
#include<iostream>
using namespace std;
int main()
{
int n=5,p,i;
int a[n];
cout<<"enter the 5 elements of an array\n";
for(i=0;i<n;i++)
{
cin>>a[i];
}
cout<<"\nEntered Elements are\n";
for(i=0;i<n;i++)
{
cout<<a[i]<<" ";
}
if(p<=0 || p>n)
{
cout<<"Invalid Position. It should not be negative or zero";
}
else if(p==n)
{
n--;
for(i=0;i<n;i++)
{
cout<<a[i]<<" ";
}
}
else
{
for(i=p-1;i<n;i++)
{
a[i]=a[i+1];
}
n--;
cout<<"\nAfter Deletion\n";
for(i=0;i<n;i++)
{
cout<<a[i]<<" ";
}
}
return 1;
}
//C++ program to demonstrate function declaration outside class
#include <iostream>
using namespace std;
class Welcome
{
public:
string Course_Name;
int id;
void printname();
void printid()
{
cout << "Course id is: " << id;
}
};
int main() {
obj1.printname();
cout << endl;
obj1.printid();
return 0;
}
//Single Inheritance
#include<iostream>
using namespace std;
class Employee {
public:
int salary;
};
class Developer : public Employee {
Employee e;
public:
void salary() {
cout<<"Enter employee salary: ";
cin>>e.salary;
cout<<"Employee salary: "<<e.salary;
}
};
int main() {
Developer obj;
obj.salary();
obj.name();
return 1;
}
/*C++ program to demonstrate example of simple inheritance.*/
#include <iostream>
using namespace std;
/*Base Class*/
class A
{
public:
void Afun(void);
};
// function definiion
void A::Afun()
{
cout << "I'm the Definition of Afun()..." << endl;
}
/*Derived Class*/
class B:public A
{
public:
void Bfun();
};
// function definition
void B::Bfun()
{
cout << "I'm the Definition of Bfun()..." << endl;
}
int main()
{
//create object of derived class - class B
B objB;
// Now, we can access the function of class A (Base class)
objB.Afun();
objB.Bfun();
return 0;
}
/*C++ program to demonstrate example of private simple inheritance.*/
class A
{
private:
int a;
protected:
int x; //can access by the derived class
public:
void setVal(int v)
{
x=v;
}
};
class B:private A
{
public:
void printVal()
{
setVal(10); //accessing public member function here
//protected data member direct access here
cout << "value of x: " << x << endl;
}
};
int main()
{
B objB; //derived class creation
objB.printVal();
return 0;
}
/* C++ program to demonstrate example of multilevel inheritance.*/
#include <iostream>
using namespace std;
void disp_a()
{
cout << "Value of a: " << a << endl;
}
};
//Here Class B is base class for class C and Derived class for class A
class B: public A
{
private:
int b;
public:
//assign value of a from here
void get_b(int val_a, int val_b)
{
//assign value of a by calling function of class A
get_a(val_a);
b=val_b;
}
void disp_b()
{
//display value of a
disp_a();
cout << "Value of b: " << b << endl;
}
};
//Here class C is derived class and B is Base class
class C: public B
{
private:
int c;
public:
//assign value of a from here
void get_c(int val_a, int val_b,int val_c)
{
/*** Multilevel Inheritance ***/
//assign value of a, bby calling function of class B and Class A
//here Class A is inherited on Class B, and Class B in inherited on Class B
get_b(val_a,val_b);
c=val_c;
}
void disp_c()
{
//display value of a and b using disp_b()
disp_b();
cout << "Value of c: " << c << endl;
}
};
int main()
{
//create object of final class, which is Class C
C objC;
objC.get_c(10,20,30);
objC.disp_c();
return 0;
}
/* C++ program to read and print employee information using multiple inheritance.*/
}
};
int main()
{
//create object of class employee
employee emp;
emp.getEmployeeInfo();
emp.printEmployeeInfo();
return 0;
}
/*C++ program to read and print employee information with department and pf information using
hierarchical inheritance.*/
#include <iostream>
#include <stdio.h>
using namespace std;
cin.getline(assignedWork,30);
cout << "Enter time in hours to complete work: ";
cin >> time2complete;
}
void printDeptInfo(void)
{
cout << "Employee's Information is: " << endl;
cout << "Basic Information...:" << endl;
cout << "Name: " << name << endl; //accessing protected data
cout << "Employee ID: " << empId << endl; //accessing protected data
cout << "Gender: " << gender << endl << endl;//accessing protected data
}
};
int main()
{
//read and print department information
deptInfo objD;
objD.getDeptInfo();
objD.printDeptInfo();
objL.getLoanInfo();
objL.printLoanInfo();
return 0;
}