Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 118

OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

Revision of Basic Concepts

TASK 1
#include <iostream.h>

#include <conio.h>

void main (void)

cout<<"\t\t\t\t\t*********WELCOME TO THIRD TERM***********"<<endl;

getch ();

Output Screen

TASK 2
#include<iostream.h>

#include <conio.h>

void main (void)

clrscr ();

cout<<endl<<endl<<"\t\tTry\n"<<endl;

getch ();

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

Output Screen

TASK 3
#include <iostream.h>

#include <conio.h>

#include <iomanip.h>

void main (void)

clrscr ();

char
n[30],fn[30],loc[50],mf[15],sc[15],uni[30],em[30],dob[50],grade[10],fgrade[10],roll[20],gp[10],sub[30],in
ter[40],a[50],mm[50],fm[50],tc[50];

cout<<endl<<endl<<setw(40)<<"Cirriculum Vitae"<<endl<<endl<<endl;

cout<<setw(20)<<"Name\t\t\t:\t\t\t";

cin.getline(n,29);

cout<<setw(20)<<"Father Name\t\t\t:\t\t\t";

cin.getline(fn,29);

cout<<setw(20)<<"Age\t\t\t:\t\t\t";

cin.getline(a,49);

cout<<setw(20)<<"Date Of Birth\t\t\t:\t\t\t";

cin.getline(dob,49);

cout<<setw(20)<<"Gender\t\t\t:\t\t\t";

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

cin.getline(mf,14);

cout<<setw(20)<<"Location\t\t\t:\t\t\t";

cin.getline(loc,49);

cout<<setw(20)<<"Sect/Cast\t\t\t:\t\t\t";

cin.getline(sc,14);

cout<<setw(20)<<"Technology\t\t\t:\t\t\t";

cin.getline(tc,49);

cout<<setw(20)<<"University\t\t\t:\t\t\t";

cin.getline(uni,29);

cout<<setw(20)<<"Email ID\t\t\t:\t\t\t";

cin.getline(em,29);

cout<<setw(20)<<"Matric Marks\t\t\t:\t\t\t";

cin.getline(mm,29);

cout<<setw(20)<<"Matric Grade\t\t\t:\t\t\t";

cin.getline(grade,9);

cout<<setw(20)<<"FSC Marks\t\t\t:\t\t\t";

cin.getline(fm,49);

cout<<setw(20)<<"FSC Grade\t\t\t:\t\t\t";

cin.getline(fgrade,9);

cout<<setw(20)<<"Roll No\t\t\t:\t\t\t";

cin.getline(roll,19);

cout<<setw(20)<<"Group\t\t\t:\t\t\t";

cin.getline(gp,9);

cout<<setw(20)<<"Subject\t\t\t:\t\t\t";

cin.getline(sub,29);

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

cout<<setw(20)<<"Interests\t\t\t:\t\t\t";

cin.getline(inter,39);

getch(); }

Output Screen

TASK 4
#include <iostream.h>

#include<conio.h>

void main (void)

Clrscr();

int v1,v2,v3;

cout<<endl<<endl<<"\t\t\t\t#Sum Programe#"<<endl<<endl;

cout<<"\t\tEnter two digits to be added"<<endl<<"\t\t\t\t\t\t";

cin>>v1;

cout<<"\t\t\t\t\t\t";

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

cin>>v2;

v3=v1+v2;

cout<<endl<<"\t\tSum of the two integers Entered=";

cout<<v3;

getch();}

Output Screen

TASK 5(a)
#include <iostream.h>

#include <conio.h>

void main (void)

clrscr ();

cout<<" The blackslah at the end of the line can be \

uesd to extend a string from one line to the\

next line.";

getch ();

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

Output Screen

TASK 5(b)
#\

include<iostream.h>

void mai\

n(

vo\id)

{cou\

t<\

<"See if\

this works?\n"\

Output Screen

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

LAB: 01

TASK 1
#include <iostream.h>

int main (void)

{ int _seg=1;

cout<<"_seg="<<_seg;

return 0;

Output Screen

Task 2(a)
#include <iostream.h>

#include <conio.h>

void main ()

{ const int i=0,j;

cout<<"i="<<i<<"j="<<j<<endl;

i=10; j=20;

cout<<"i="<<i<<"j="<<j<<endl;

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

getch ();}

Output Screen

TASK 2(b)
#include <iostream.h>

#include <conio.h>

void main ()

{ int i=0,j;

cout<<"i="<<i<<"j="<<j<<endl;

i=10; j=20;

cout<<"i="<<i<<"j="<<j<<endl;

getch ();}

Output Screen

TASK 3
#include <iostream.h>

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

#include <conio.h>

void main ()

{ clrscr ();

cout<<"\a";

cout<<"Welcome to";

cout<<"\b";

cout<<"C++";

cout<<"\n";

cout<<"Welcome";

cout<<"\r";

cout<<"to";

cout<<"\t";

cout<<"C++";

getch ();

Output Screen

Task 4
#include<iostream.h>

#include <conio.h>

void main ()

{clrscr();

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

cout<<"\n\n\n\t\t\t\xC9\xCD\xCD\xCD\xCD\xCD\xCD\xBB\n";

cout<<"\t\t\t\xBA\AHMED \xBA\n";

cout<<"\t\t\t\xC8\xCD\xCD\xCD\xCD\xCD\xCD\xBC";

getch ();

Output Screen

TASK 5
#include <iostream.h>

#include <conio.h>

void main ()

{ clrscr ();

int i=10;

cout<<i<<endl<<hex<<i<<endl<<oct<<i;

getch ();

Output Screen

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

TASK 6
#include <iostream.h>

#include <conio.h>

void main ()

{ clrscr ();

int x=10; cout<<x<<endl;

cout<<++x<<endl; cout<<x<<endl;

cout<<x++<<endl; cout<<x<<endl; cout<<++x<<++x<<++x<<++x;

getch (); }

Output Screen

LAB: 02

TASK 1
#include <iostream.h>

#include <conio.h>

void main ()

{ int intUpperBound=32767, intLowerBound= -32768;

clrscr ();

cout<<"\tintUpperBound ="<<intUpperBound<<endl;

cout<<"\tintLowerBound ="<<intLowerBound<<endl;

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

cout<<"\tintUpperBound +1 ="<<intUpperBound+1<<endl;

cout<<"\tintLowerBound -1 ="<<intLowerBound-1<<endl;

getch ();}

Output Screen

TASK 2
#include <iostream.h>

#include <conio.h>

void main ()

{ clrscr ();

cout<<"size of int in bytes ="<<sizeof(int)<<endl;

cout<<"size of float in bytes ="<<sizeof(float)<<endl;

cout<<"size of long in bytes ="<<sizeof(long)<<endl;

cout<<"size of double in bytes ="<<sizeof(double)<<endl;

getch ();}

Output Screen

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

TASK 3
#include <iostream.h>

#include <conio.h>

#include <iomanip.h>

void main ()

{ int x=111, y=222; float z=34.5678; clrscr ();

cout<<x<<y<<z<<endl;

cout<<setw(10)<<x<<setw(10)<<y<<setw(10)<<z<<endl;

cout<<setfill('*')<<setprecision(2)<<setw(10)<<x<<setw(10)<<y<<setw(10)<<z<<endl;

cout<<12345<<setw(15)<<26.2652876;

getch ();}

Output Screen

TASK 4
#include <iostream.h>

#include <conio.h>

void main (void)

{ clrscr ();

int i=10,j=2;

cout<<"\n\tA="<<(i*j++)+(i*j)<<endl; j=2;

cout<<"\tB="<<(i*j)+(i*++j)<<endl; j=2;

cout<<"\tC="<<(i*j++)+(i*j--)<<endl; j=2;

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

cout<<"\tD="<<(i*j--)+(i*++j)<<endl; j=2;

cout<<"\tE="<<(i*++j)+(i*++j)<<endl; j=2;

cout<<"\tF="<<(i*--j)+(i*--j)<<endl; j=2;

cout<<"\tG="<<(i*++j)+(i*--j)<<endl; j=2;

cout<<"\tH="<<(i*--j)+(i*++j)<<endl;

getch ();

Output Screen

TASK 5
#include <iostream.h>

#include <conio.h>

void main (void)

{ clrscr ();

int a=0,b=1;

if(++a)cout<<"\tTrue"; cout<<"\tFalse";

if(a==b) cout<<"\tToday";

else cout<<"Tomorrow";

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

getch (); }

Output Screen

LAB: 03

TASK 1
#include <iostream.h>

#include <conio.h>

class integer

{int i;

public:

void get_i()

{cout<<"\n\tEnter the Value of i= ";

cin>>i;}

void print_i()

{cout<<"\n\ti="<<i<<endl;}};

void main ()

{ clrscr ();

integer myint;

myint.get_i();

myint.print_i();

getch ();}

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

Output Screen

TASK 2
#include <iostream.h>

#include <conio.h>

class print

{public:

void display()

{cout<<"\n\tThis is my first class"<<endl;}

};

void main ()

{ clrscr ();

print b1;

b1.display ();

getch ();}

Output Screen

TASK 3
#include <iostream.h>

#include <conio.h>

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

class rectangle

{ int length,width;

public:

void getdata ()

{ cout<<"\n\tEnter Lenght=";

cin>>length;

cout<<"\n\tEnter width=";

cin>>width;}

void perimeter()

{ float perimeter;

perimeter=2*(length+width);

cout<<"\n\tPerimeter="<<perimeter<<endl;}

void area ()

{ float area;

area=length+width;

cout<<"\n\tArea="<<area<<endl;}};

void main ()

{ clrscr ();

rectangle rect;

rect.getdata();

rect.perimeter();

rect.area();

getch ();}

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

Output Screen

TASK 4
#include <iostream.h>

#include <conio.h>

class arithmetic

{ int a,b;

public:

void getdata()

{ cout<<"\n\tEnter 1st Integer=";

cin>>a;

cout<<"\n\tEnter 2nd Integer=";

cin>>b;}

void sum ()

{ int sum;

sum=a+b;

cout<<"\n\tSum="<<sum;}

void difference()

{ int difference;

difference=a-b;

cout<<"\n\tDifference="<<difference;}

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

void product ()

{ int product;

product=a*b;

cout<<"Product="<<product<<endl;}};

void main ()

{ clrscr();

arithmetic ari;

ari.getdata();

ari.sum();

ari.difference();

ari.product();

getch ();}

Output Screen

TASK 5 (A)
#include<iostream.h>

#include <conio.h>

class rectangle

{ int length, width;

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

public:

void getdata()

{ cout<<"\n\tEnter Length =";

cin>>length;

cout<<"\n\tEnter Width=";

cin>>width;}

void perimeter()

{ float perimeter;

perimeter=2*(length+width);

cout<<"\n\tPerimter="<<perimeter<<endl;}

void area ()

{ float area;

area=length+width;

cout<<"\n\tArea="<<area;}

void size ()

{ cout<<"\n\tsizeof(rectangle)="<<sizeof(rectangle);}};

void main ()

{ clrscr ();

rectangle rect;

rect.getdata ();

rect.perimeter();

rect.area();

rect.size();

getch ();}

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

Output Screen

TASK 5 (B)
#include <iostream.h>

#include <conio.h>

class integer

{ int i;

public:

void get_i ()

{ cout<<"\n\tEnter the value ofi=";

cin>>i;}

void print_i()

{ cout<<"\n\ti=i"<<i;}

void size()

{ cout<<"\n\tsizeof(integer)="<<sizeof(integer);}};

void main ()

{ clrscr ();

integer myint;

myint.get_i();

myint.print_i();

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

myint.size();

getch ();}

Output Screen

TASK 6
#include <iostream.h>

#include <conio.h>

class integer

{ int i;

public:

void get_i()

{ cout<<"\n\tEnter the value of i=";

cin>>i;}

void cond()

{ if(i>0)

cout<<"\n\tPositive";

else

cout<<"\n\tNegative";}};

void main ()

{ clrscr ();

integer myint;

myint.get_i();

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

myint.cond();

getch();}

Output Screen

TASK 7
#include <iostream.h>

#include <conio.h>

void main ()

{ clrscr ();

int a=023,b=0xab;

cout<<"\n\t"<<a<<"\t"<<b<<endl;

cout<<"\n\t"<<hex<<a<<"\t"<<hex<<b<<endl;

cout<<"\n\t"<<oct<<a<<"\t"<<oct<<b<<endl;

getch ();}

Output Screen

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

LAB: 04

TASK 1
#include <iostream.h>

#include <conio.h>

typedef int bool;

const bool true=1,false=0;

void main ()

{ clrscr();

bool var=true;

if(var)cout<<"\n\tTrue"<<endl;

else cout<<"\tFalse"<<endl;

var=false;

if(var)cout<<"\tTrue"<<endl;

else cout<<"\tFalse"<<endl;

getch ();}

Output Screen

TASK 2
#include <iostream.h>

#include <conio.h>

class Triangle

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

{ int x,y,z;

public:

void input()

{cout<<"\n\tEnter first side:";

cin>>x;

cout<<"\n\tEnter 2nd side:";

cin>>y;

cout<<"\n\tEnter 3rd side:";

cin>>z;}

void result()

{if(x+y>z&&y+z>x&&x+z>y)

cout<<"\n\tValid Triangle";

else

cout<<"\n\tInvalid Triangle";}

void perimeter()

{int p;

p=x+y+z;

if (x+y>z && y+z>x && x+z>y)

cout<<"\n\tPerimeter is"<<p;

else

cout<<"\n\tCan't Find Perimeter";}};

void main ()

{ clrscr ();

Triangle Tri;

Tri.input();

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

Tri.result();

Tri.perimeter();

getch ();}

Output Screen

TASK 3
#include <iostream.h>

#include <conio.h>

#include <iomanip.h>

class variable

{ int x;

float y;

double z;

public:

void input()

{cout<<"\n\tEnter first:" ;

cin>>x;

cout<<"\n\tEnter 2nd:";

cin>>y;

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

cout<<"\n\tEnter 3rd:";

cin>>z;}

void printf()

{cout<<"\n\t"<<setfill('-')<<setw(11)<<x<<setw(13)<<y<<setw(16)<<z;

};

void main ()

{ clrscr();

variable var;

var.input();

var.printf();

getch();}

Output Screen

TASK 4
#include <iostream.h>

#include <conio.h>

void main ()

{ clrscr ();

int i,j=2,k=4;

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

i=(j>3)&&(++k==6);

cout<<"\n\ti="<<i<<"\tj="<<j<<"\tk="<<k<<endl;

i=(j<3)&&(++k=6);

cout<<"\n\ti="<<i<<"\tj="<<j<<"\tk="<<k;

getch ();}

Output Screen

TASK 5
#include <iostream.h>

#include <conio.h>

class result

{ int marks;

public:

void input ()

{cout<<"\n\tEnter marks=";

cin>>marks;}

void grade ()

{if (marks<50)

cout<<"\n\tFail";

else if (marks>49&&marks<=59)

cout<<"\n\tPass with C grade";

else if (marks>59&&marks<=69)

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

cout<<"Pass with B grade";

else if(marks>69&&marks<=79)

cout<<"\n\tPass with A grade";

else if(marks>79&&marks<=100)

cout<<"\n\tPass with A1 grade";

else if (marks>100||marks<0)

cout<<"\n\tInvalid marks";

else

cout<<"\n\tProgram ends";}};

void main ()

{ clrscr ();

result res;

res.input();

res.grade();

getch();}

Output Screen

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

TASK 6
OPERATORS

ARITHMETIC OPERATORS:addition(+),subtraction(-),multiplication(*),division(/),remainder(%)

INCREMENT OPERATORS:preincrement(++a),postincrement(a++)

DECREMENT OPERATORS:predecrement(--a),postdecrement(a--)

ASSIGNMENT OPERATORS:=(a=b),a+=b(a=a+b),a-=b(a=a-
b),a*=b(a=a*b),a/=b(a=a/b),a%=b(a=a%b)
RELATIONAL OPERATORS:==(equal to),<(less than),>(greater than),!
=(not equal to),<=(less than or equal to),>=(greater than or equal to)

LOGICAL OPERATORS:&&(logical AND),||(logical OR),!(logical NOT)


CONDITIONAL OPERATORS:c=(c>0)?10:-10.if c>0 then 10 is printed
otherwise -10.
BITWISE OPERATORS:&(bitwise AND),|(bitwise OR),^(bitwise exclusive
OR),~(bitwise complement),<<(shift left),>>(shift right)

TASK 7
cin.good() - determines if the cin input was valid 

Example:
#include <iostream.h>

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

#include <conio.h>

void main (void)

{ clrscr ()

int year;

cout << "Enter a year to display the first month of that year: ";

cin >> year;

while(year < 1 || !cin.good())

{cout << endl << "Invalid year!" << endl

<< "Enter a year to display the first month of that year: ";

cin >> year;}

getch ();}

Output Screen

cin.fail() - detects whether the value entered fits the value defined in the variable. If cin.fail() is true, it
means that the entered value does not fit the variable, or the variable will not be affected, or the
instream is still broken.

Example:
#include <iostream.h>

#include <conio.h>

int main()

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

{ clrscr ();

int i=8, j = 0;

while (1) {

i++;

cout<<"Enter integer: ";

cin >> j;

if (cin.fail()) return 0;

cout << "Integer " << i << ": " << j << endl; }

getch ();}

Output Screen

LAB: 05

TASK 1
#include <iostream.h>

#include <conio.h>

int main (void)

{clrscr ();

char ch;

while (cin.get(ch),!cin.eof())

cout<<ch;

return 0;}

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

Output Screen

TASK 3
#include <iostream.h>

#include <conio.h>

typedef int bool;

const bool true=1, false= 0;

void main ()

{ clrscr ();

long num=0,count=0,sum=0;

bool check= true;

while (check)

++num;

if(num%2==1)

{ count++;

sum=sum+num;

cout<<sum<<endl;

check=(count<10); }

} cout<<"sum="<<sum;

getch ();

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

Output Screen

TASK 4
#include <iostream.h>

#include <conio.h>

void main(void)

{ clrscr();

int a,b;

char op;

cout<<"\n\n\n\t\t\tCalculator\n\n\n";

cout<<"\tEnter first num";

cin>>a;

cout<<"\n\tEnter operator";

cin>>op;

cout<<"\n\tEnter the 2rd num";

cin>>b;

switch (op)

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

case '+':

cout<<"\n\tSum"<<(a+b);

break;

case '-':

cout<<"\n\tsub"<<(a-b);

break;

case '/':

cout<<"\n\tDivi"<<(a/b);

break;

case '%':

cout<<"\n\tRem"<<(a%b);

default:

cout<<"\n\terror";}

getch ();}

Output Screen

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

TASK 5(a)
#include <iostream.h>

#include <conio.h>

void main ()

{ clrscr ();

int n,sum=0,count=0;

float avg;

cout<<"\t\tEnter number> 0 : ";cin>>n;

while(!cin.eof())

{ if(cin.fail()) {cin.clear();

cout<<"\a \t\tError"<<char(cin.get())<<"?";}

else if(n<=0)cout<<"\a\t\tnumber: "<<n<<"<=0?";

else {count++; sum=sum+n;}

cout<<"\n\t\tEnter number > 0 : "; cin>>n;

avg=float(sum)/float(count);

cout<<"\nAverage= "<<avg;

getch ();

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

Output Screen

TASK 5 (b)
#include <iostream.h>

#include <conio.h>

void main ()

{ clrscr ();

int n,sum=0,count=0;

float avg;

while(cout<<"\t\tEnter number> 0 : ", cin>>n, !cin.eof())

{ if(cin.fail()) {cin.clear();

cout<<"\a\n \t\tError"<<char(cin.get())<<"?";}

else if(n<=0)cout<<"\a\t\tnumber: "<<n<<"<=0?";

else {count++; sum=sum+n;}

cout<<"\n\t\tEnter number > 0 : "; cin>>n;

avg=float(sum)/float(count);

getch ();

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

Output Screen

LAB: 06

Task 1

#include <iostream.h>

#include <conio.h>

class rectangle

{ int length,width;

public:

void getdata ()

{ cout<<"\n\tEnter Length=";

cin>>length;

cout<<"\n\tEnter width=";

cin>>width;}

void printlength()

{ cout<<"\n\tThe Length of rectangle is="<<length;}

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

void printwidth()

{ cout<<"\n\tThe width of rectangle is="<<width;}

void perimeter()

{ float perimeter;

perimeter=2*(length+width);

cout<<"\n\tPerimeter="<<perimeter;}

void area()

{ float area;

area=length+width;

cout<<"\n\tArea="<<area<<endl;}};

void main ()

{ clrscr ();

char ch;

rectangle rect;

rect.getdata();

cout<<"\n\tEnter character";

cin>>ch;

switch (ch)

case'l':

rect.printlength();

break;

case'L':

rect.printlength();

break;

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

case'w':

rect.printwidth();

break;

case'W':

rect.printwidth();

break;

case'p':

rect.perimeter();

break;

case'P':

rect.perimeter();

break;

case'a':

rect.area();

break;

case'A':

rect.area();

break;

default:

cout<<"\n\tError"; }

getch ();

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

Output Screen

Task 2 (i)
#include <iostream.h>

#include <conio.h>

void main (void)

{ clrscr ();

int a;

cout<<endl<<endl<<"\t\t\t\tTable of 3"<<endl<<endl;

for(a=1; a<=10;a++)

cout<<"\t3 X "<<a<<" = "<<3*a<<endl;

getch ();}

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

Output Screen

TASK 2(ii)
#include <iostream.h>

#include <conio.h>

void main (void)

{ clrscr ();

int a;

cout<<endl<<endl<<"\t\t\t\t Counting From 1 to 10"<<endl<<endl;

for(a=1; a<=10; a++)

{ cout<<"\t\t"<<a<<endl;

getch (); }

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

Output Screen

TASK 2(iii)
#include <iostream.h>

#include <conio.h>

void main (void)

{ clrscr ();

int a;

cout<<endl<<endl<<"\t\t\tOdd Numbers From 20 to 30"<<endl<<endl;

for(a=21; a<=30; a=a+2)

cout<<"\t\t"<<a<<endl;

getch ();}

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

Output Screen

TASK 2(iv)
#include <iostream.h>

#include <conio.h>

void main (void)

{ clrscr ();

int a;

cout<<endl<<endl<<"\t\t\tNumbers From 1 to 20 in steps of three"<<endl<<endl;

for(a=1; a<=20; a=a+3)

{ cout<<"\t\t"<<a<<endl;

getch ();}

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

Output Screen

TASK 3
#include <iostream.h>

#include <conio.h>

void main (void)

{ clrscr ();

for(int j=1; j<=3; j++)

{ for(int k=1; k<=j; k++)

{cout<<"*"; if(k==j) cout<<k;}

getch ();}

Output Screen

TASK 4
#include <iostream.h>

#include <conio.h>

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

void main (void)

{ clrscr ();

int a,fact;

cout<<endl<<endl<<"\t\t\tCalculating Factorial"<<endl<<endl;

cout<<"\t\tEnter the digit";

cin>>a;

for(fact=1; a>=1; a--)

{ fact=fact*a;}

cout<<endl<<"\t\tFactorial is ="<<fact;

getch ();}

Output Screen

TASK 5
#include <iostream.h>

#include <conio.h>

void main ()

{ clrscr ();

char ch;

cout<<"\n\tEnter any string of any length:";

cin>>ch;

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

int digit=0,line=0,space=0,caps=0,small=0;

while(cin.get(ch),(ch!='\x00'))

{if(ch<='9' &&ch>='0')

digit++;

if(ch<='z'&&ch>='a')

small++;

if(ch<='Z'&&ch>='A')

caps++;

if(ch==' ')

space++;

if(ch=='\x0a')

line++;}

cout<<"\xff";

cout<<"small case letter="<<small<<endl;

cout<<"Capital letter="<<caps<<endl;

cout<<"digit="<<digit<<endl;

cout<<"space="<<space<<endl;

cout<<"line="<<line<<endl;

getch ();}

Output Screen

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

TASK 6
#include <iostream.h>

#include <conio.h>

void main (void)

{ int i,c,sum;

clrscr ();

cout<<"\n\n";

for(i=1;i<=13;i=i+4)

{ sum=0;

for (c=i; c<=i+3;c++)

{ sum=sum+c;

cout<<"\t"<<c;

cout<<"\t "<<sum<<endl;

getch ();

Output Screen

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

TASK 8
#include <iostream.h>

#include <conio.h>

int v=10;

void main (void)

{ clrscr ();

cout<<"\n\n\t Global v = "<<v<<endl;

v=15; int v=20;

cout<<"\tLocal v = "<<v<<endl;

cout<<"\tModified v = "<<::v<<endl;

{ int v=30; ::v=25;

cout<<"\tLocal v = "<<v<<endl;

cout<<"\tModified global v = "<<::v<<endl;}

getch ();

Output Screen

TASK 9
#include <iostream.h>

#include <conio.h>

void main ()

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

{ clrscr ();

int a,b,c;

a=-14%5;

b=-14%-5;

c=14%-5;

cout<<"\n\t-ve%+ve:"<<a;

cout<<"\n\t-ve%-ve:"<<b;

cout<<"\n\t+ve%-ve:"<<c;

getch ();}

Output Screen

#include <iostream.h>

#include <conio.h>

void main ()

{ clrscr ();

int n=0;

while(cout<<n++%5,n<6)

getch ();}

Output Screen

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

LAB: 07

TASK 1
#include <iostream.h>

#include <conio.h>

int sum (int,int);

void product (int A,int B)

{cout<<"\n\tProduct of#s= "<<A*B;}

void main ()

{int x,y; cout<<"\n\tEnter first integer: ";

cin>>x;

cout<<"\n\tEnter Second integer: ";

cin>>y;

cout<<"\n\tSum of #s="<<sum(x,y)<<endl;

product(x,y);}

int sum (int a, int b){return a+b;}

Output Screen

TASK 2
#include <iostream.h>

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

#include <conio.h>

void squaresum (int);

void main (void)

{ int n;

cout<<"\n\tEnter any Postive Number";

cin>>n;

squaresum(n);

cout<<"\n\tOK";}

void squaresum (int p)

{ int sum;

if (p>0)

{sum=0;

for (p;p>0;p--)

{ sum=sum+(p*p);}

cout<<"\n\tSum of square is: "<<sum;}

else

cout<<"\n\tError";}

Output Screen

TASK 3
#include<iostream.h>

#include<conio.h>

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

void Endl(int);

void main()

int a; char c;

cout<<"\n\tDo you want to specify the argument? ";

cin>>c;

if (c=='y')

{ cout<<"\n\tEnter the value of a:\t";

cin>>a;

Endl(a); }

else

cout<<"\n";

getch();}

void Endl(int a)

{ for (int d=0; d<=a; d++)

cout<<"\n"; }

Output Screen

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

TASK 4
#include <iostream.h>

#include <conio.h>

float average (int newdata)

{ static float total=0.0f; static int count = 0;

count++; total+=newdata;

return total/count;}

void main ()

{ float ave; int data=1;

while (data !=0)

{cout<<"\n\tEnter a number -->";cin>>data;

cout<<"\n\tNew average is -->"<<average(data)<<endl;}}

Output Screen

TASK 5
#include <iostream.h>

#include <conio.h>

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

#include <math.h>

void QE ( float, float,float);

void main ()

float d,e,f;

cout<<"\n\tEnter value of A: ";

cin>>d;

cout<<"\n\tEnter value of B: ";

cin>>e;

cout<<"\n\tEnter value of C: ";

cin>>f;

QE (d,e,f);

cout<<"OK";

void QE (float a,float b, float c)

float disc,real,imag,r1,r2;

disc=b*b-4.0*a*c;

if(disc<0)

{ real=-b/(2.0*a);

imag= sqrt (-disc)/(2.0*a);

cout<<"\n\tRoots are imaginary";

cout<<"\n\tRoot1="<<real<<"+j("<<imag<<")";

cout<<"\n\tRoot2="<<real<<"-j("<<imag<<")";

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

if (disc==0)

r1=r2= -b/(2.0*a); cout<<"\n\tRoots are real&equal";

cout<<"\n\tRoot1="<<r1;

cout<<"\n\tRoot2="<<r2;

if(disc>0)

{ cout<<"\n\tRoots are real &different";

r1= -b/(2.0*a) + sqrt(disc)/(2.0*a);

r2= -b/(2.0*a) - sqrt(disc)/(2.0*a);

cout<<"\n\tRoot1="<<r1;

cout<<"\n\tRoot2="<<r2;

Output Screen

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

TASK 7
fabs ()
#include <iostream.h>

#include <math.h>

int main ()

cout<<"\n\tThe absolute value of 3.1416 is:"<<fabs(3.1416);

cout<<"\n\tThe absolute value of -10.6 is:"<< fabs(-10.6);

return 0;

Output Screen

abs ()
#include <iostream.h>

#include <math.h>

void main()

int aNum;

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

cout<<"\n\tEnter a positive or negative integer";

cin>>aNum;

cout<<"\n\t"<<abs(aNum);

Output Screen

LAB: 08

Task 1
#include <iostream.h>

#include <conio.h>

class C

{ int a,b; const int c; public:

C(): a(10),c(30) {b=20; cout<<"Constructor No 1"<<endl;}

C(int d,int e,int f):b(e),c(f) {a=d; cout<<"Constructor No 2"<<endl;}

~C() {cout<<"Destructor"<<endl;}

void print () {cout<<"a= "<<a<<"\nb= "<<b<<"\nc "<<c<<endl;}

};

void main()

{ C c1= C();

C c2= C(4,5,6);

C c3;

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

C c4(70,80,90);

c1.print();

c2.print();

c3.print();

c4.print();

Output Screen

Task 2
#include <iostream.h>

#include <conio.h>

class rectangle

{ int length,width;

public:

void getdata ()

{ cout<<"\n\tEnter Lenght=";

cin>>length;

cout<<"\n\tEnter width=";

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

cin>>width;}

void perimeter()

{ float perimeter;

perimeter=2*(length+width);

cout<<"\n\tPerimeter="<<perimeter<<endl;}

void area ()

{ float area;

area=length+width;

cout<<"\n\tArea="<<area<<endl;}

rectangle(int A,int B) {length= A; width= B; cout<<"\n\tThis is Constructor"<<endl;}

~rectangle() {cout<<"\n\tThis is destructor\n\tGoodbye!!"<<endl;}};

void main ()

rectangle rect(9,12);

rect.perimeter();

rect.getdata();

rect.area();

getch ();}

Output Screen

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

Task 3(i,ii)
#include <iostream.h>

#include <conio.h>

void main (void)

int c;

int array [10];

array[0]=10;

array[1]=20;

array[2]=30;

array[3]=40;

array[4]=50;

array[5]=60;

array[6]=70;

array[7]=89;

array[8]=90;

array[9]=100;

for(c=0;c<=9;c++)

{cout<<"\n\tThe element in array["<<c<<"] is= "<<array[c];}

Output Screen

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

Task 3(iii,iv)
#include <iostream.h>

#include <conio.h>

void main (void)

int c;

int array [10]={10,20,30,40,50,60,70,80,90,100};

cout<<"\n\tThe element out of bound is ="<<array[12]<<endl;

for(c=0;c<=9;c++)

{cout<<"\n\tThe address of array["<<c<<"] is= "<<&array[c];}

cout<<"\n\n\tcout<<array= "<<array;

cout<<"\n\tcout<<&array= "<<&array;

Output Screen

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

TASK 4
#include <iostream.h>

#include <conio.h>

void smallelement (int[]);

void main (void)

int array[6]={5,7,2,7,8,10};

smallelement(array);

cout<<"\n\tSize of array in Main="<<sizeof(array);

void smallelement(int arr[])

{cout<<"\n\tSize of array in Function="<<sizeof(arr);

int min,i;

min=arr[0];

for (i=1; i<=5; i++)

if(min>arr[i])

min=arr[i];

cout<<"\n\tMinimum value is= "<<min;}

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

Output Screen

TASK 5
#include <iostream.h>

#include <conio.h>

void main (void)

{int c,i,j;

int arr[2][2][2] = { { {4, 5}, {4, 5} },

{ {4, 5}, {4, 5}} };

cout<<"\n\tThe element in array[0][0][0] is= "<<arr[0][0][0];

cout<<"\n\tThe element in array[0][0][1] is= "<<arr[0][0][0];

cout<<"\n\tThe element in array[0][1][0] is= "<<arr[0][0][0];

cout<<"\n\tThe element in array[0][1][1] is= "<<arr[0][0][0];

cout<<"\n\tThe element in array[1][0][0] is= "<<arr[0][0][0];

cout<<"\n\tThe element in array[1][0][1] is= "<<arr[0][0][0];

cout<<"\n\tThe element in array[1][1][0] is= "<<arr[0][0][0];

cout<<"\n\tThe element in array[1][1][1] is= "<<arr[1][1][1];

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

Output Screen

TASK 6
#include<iostream.h>

#include<conio.h>

class ee

{int a[5];

public:

ee()

{for (int i=0;i<=4;i++)

{cout<<"\n\tEnter the element in array["<<i<<"]= ";

cin>>a[i];}

void print()

{for(int b=0;b<=4;b++)

{cout<<"\n\tThe element in array ["<<b<<"]= "<<a[b];}

};

void main(void)

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

ee a,b;

a.print();

cout<<"\n\tNow the other object\n";

b.print();

Output Screen

TASK 7
#include<iostream.h>

#include<conio.h>

#include<ctype.h>

main()

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

cout<<"Enter any string of any length ? \n";

char ch;

int digits=0,small=0,line=0,space=0,caps=0;

while(cin.get(ch),!cin.eof())

if (isdigit(ch))

digits++;

if (isupper(ch))

caps++;

if (isspace(ch) && !isprint(ch))

line++;

if (islower(ch))

small++;

if (isspace(ch))

space++;

cout<<"small case letters ="<<small<<endl

<<"capital letters ="<<caps<<endl

<<"digits ="<<digits<<endl

<<"spaces ="<<space-line<<endl

<<"line ="<<line<<endl;

getch();

return 0;

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

Output Screen

TASK 8
#include<iostream.h>

#include<conio.h>

#include <ctype.h>

int main ()

char ch;

cout<<"\n\tEnter any character:";

cin>>ch;

if (ch>='A'&& ch<='Z')

{cout<<"\n\tThe character is already Capital";}

else if (ch>='a' && ch<='z')

{ ch = toupper ( ch );

cout<<"\nCharacter in uppercase is="<<ch;}

else if (ch>=48 && ch<=57)

{}

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

else if ((ch>0 && ch<=47)||(ch>=58 && ch<=64)||

(ch>=91 && ch<=96)||(ch>=123 && ch<=127))

{}

getch();

return 0;

Output Screen

LAB: 09

TASK 1
#include <iostream.h>

class complex

{ float real,imag; public:

complex () {real=0.0f; imag= 0.0f;}

complex (float a, float b) {real=a; imag=b;}

void edit()

{cout<<"\n\tEnter real part: ";cin >>real;

cout<<"\n\tEnter imaginary part: "; cin>>imag;}

void display()

{(imag>=0)? cout<<"\n\t"<<real<<"+j"<<imag<<endl:cout<<real<<"-"<<-imag<<endl;}

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

void plus(complex a)

{ complex sum(real+a.real,imag+a.imag);

cout<<"\n\tSum-->\t";sum.display();}

void minus(complex b)

{complex sub(real-b.real,imag-b.imag);

cout<<"\n\tSubtraction-->\t";sub.display();}

void multiply(complex c)

{complex multiply(real*c.real-imag*c.imag,real*c.imag+imag*c.real);

cout<<"\n\tMultiply-->\t";multiply.display();}};

void main ()

{ complex c1, c2(3,5),c3(8,9);

c1.edit(); c1.display();

c2.plus(c3);

c3.minus(c1);

c1.multiply(c2);

#include <iostream.h>

class complex

{ float real,imag; public:

complex () {real=0.0f; imag= 0.0f;}

complex (float a, float b) {real=a; imag=b;}

void edit()

{cout<<"\n\tEnter real part: ";cin >>real;

cout<<"\n\tEnter imaginary part: "; cin>>imag;}

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

void display()

{(imag>=0)? cout<<"\n\t"<<real<<"+j"<<imag<<endl:cout<<real<<"-"<<-imag<<endl;}

complex plus(complex a,complex b)

{ return complex (a.real+b.real,a.imag+b.imag);}};

void main ()

{ complex c1, c2(3,5),c3(8,9);

c1.plus(c2,c3).display();

Output Screen

TASK 2
#include <iostream.h>

class complex

{ float real,imag; public:

complex () {real=0.0f; imag= 0.0f;}

complex (float a, float b) {real=a; imag=b;}

void edit()

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

{cout<<"\n\tEnter real part: ";cin >>real;

cout<<"\n\tEnter imaginary part: "; cin>>imag;}

void display()

{(imag>=0)? cout<<"\n\t"<<real<<"+j"<<imag<<endl:cout<<real<<"-"<<-imag<<endl;}

complex plus(complex a,complex b)

{ return complex (a.real+b.real,a.imag+b.imag);}};

void main ()

{ complex c1, c2(3,5),c3(8,9);

c1.plus(c2,c3).display();

Output Screen

TASK 3
#include <iostream.h>

#include <conio.h>

class time

{int hr,min; public:

time();

time (int,int);

void showtime()

{cout<<endl<<hr<<":"<<min;}};

time::time(){hr=0;min=0;}

time::time(int x,int y){hr=x;min=y;}

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

void main (void)

{time t;

t.showtime();

time t1(11,10);

t1.showtime();

Output Screen

TASK 4
#include<iostream.h>

#include<conio.h>

void main()

{int u,t,i,mna[4]={23,0,51,23};

for (u=3;u>=1;u--)

for (i=0;i<u;i++)

if (mna[i]<mna[i+1])

{ t=mna[i];

mna[i]=mna[i+1];

mna[i+1]=t;}

cout<<"sorted values"<<endl;

for (i=0;i<=3;i++)cout<<mna[i]<<endl;getch();}

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

Output Screen

TASK 5
#include <iostream.h>

class complex

{ float real,imag; public:

complex () {real=0.0f; imag= 0.0f;}

complex (float a, float b) {real=a; imag=b;}

void edit()

{cout<<"\n\tEnter real part: ";cin >>real;

cout<<"\n\tEnter imaginary part: "; cin>>imag;}

void display()

{(imag>=0)? cout<<"\n\t"<<real<<"+j"<<imag<<endl:cout<<real<<"-"<<-imag<<endl;}

void plus(complex a)

{ complex sum(real+a.real,imag+a.imag);

cout<<"\n\tSum-->\t";sum.display();}

void minus(complex b)

{complex sub(real-b.real,imag-b.imag);

cout<<"\n\tSubtraction-->\t";sub.display();}

void multiply(complex c)

{complex multiply(real*c.real-imag*c.imag,real*c.imag+imag*c.real);

cout<<"\n\tMultiply-->\t";multiply.display();}};

void main ()

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

{ complex a[5]={complex(),complex(4,-5),complex(10,20)};

a[0].edit();a[0].display();

a[1].plus(a[2]);

a[2].minus(a[0]);

a[0].multiply(a[1]);

Output Screen

TASK 6

#include<iostream.h>

#include<conio.h>

class Matrix

private:

int matrix[2][2];

public:

Matrix();

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

Matrix(int);

void input();

void display();

void add(Matrix a);

void subtract(Matrix a);

};

int main ( )

clrscr();

Matrix M,M1(1),M2(2);

M1.display();

M1.input();

M.display();

M1.display();

M2.display();

M1.add(M2);

M1.subtract(M2);

getch();

return 0;

Matrix::Matrix()

for (int loop2=0;loop2<2;loop2++)

for (int loop1=0;loop1<2;loop1++)

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

matrix[loop2][loop1]=0;

Matrix::Matrix(int)

input();

void Matrix::input()

cout<<"\n\t Enter values \n";

for (int loop5=0;loop5<2;loop5++)

for (int loop6=0;loop6<2;loop6++)

cout<<"enter next \t";

cin>>matrix[loop5][loop6];

void Matrix::display()

cout<<"\n\n\t Contents \n";

for (int loop7=0;loop7<2;loop7++)

for (int loop8=0;loop8<2;loop8++)

cout<<matrix[loop7][loop8]<<"\t";

cout<<"\n";

void Matrix::add(Matrix a)

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

for (int loop9=0;loop9<2;loop9++)

for (int loop10=0;loop10<2;loop10++)

a.matrix[loop9][loop10]=matrix[loop9][loop10]+a.matrix[loop9][loop10];

a.display();

void Matrix::subtract(Matrix a)

for (int loop11=0;loop11<2;loop11++)

for (int loop12=0;loop12<2;loop12++)

a.matrix[loop11][loop12]=matrix[loop11][loop12]-a.matrix[loop11][loop12];

a.display();

Output Screen

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

LAB: 10

TASK 1
#include <iostream.h>

void main ()

{ char A[]= {'W','e','l','l','C','o','m','e','\0'};

char B[15]="EED UET TAXILA";

char C[9]={71,111,0x6F,100,'B',0x79,A[7],041,0};

cout<<A<<"\t"<<sizeof(A)<<"\n"<<B<<"\t"<<sizeof(B)<<"\n"<<C<<"\t"<<sizeof(C)<<endl;

cout<<++C[0]<<A[1]<<B[12]<<char(108)<<C[2];}

Output Screen

TASK 2
#include<iostream.h>

#include<conio.h>

#include<dos.h>

void main(void)

char x[]="uet taxila";

int i,j;

gotoxy(30,1);

cout<<x;

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

for(i=0;x[i]!='\0';i++)

{for(j=1;j<=24;j++) {gotoxy(i+30,j); delay(40);gotoxy(i+30,j);cout<<" ";}

gotoxy(i+30,j);cout<<x[i];}

getch();

Output Screen

TASK 3
#include<iostream.h>

#include<conio.h>

int main ( )

char a[100];

cout<<"\t\t enter for cin: ";

cin>>a;

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

cout<<"output for cin="<<a<<endl;

cout<<"\n\t\t enter for cin.get() \n";

cin.get(a,25,'0'); //if space is used then enter terminates the program

cout<<"output for cin.get()="<<a<<endl;

return 0;}

Output Screen

TASK 4
#include<iostream.h>
#include<conio.h>
#include<string.h>
const int SIZE=100;
class string
{
char str[SIZE];
int length;
public:
string()
{
strcpy(str,"empty");
length=5;
}
string(char array[])
{

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

length=strlen(array);
if (length>SIZE)
cout<<"\n\n\t\t ERROR! \n\n";
else
strncpy(str,array,length);
str[length+1]='\0';
}
void input()
{
cout<<"\n enter values and use ctrl+z to terminate \n";
cin.getline(str,100,cin.eof());
length=strlen(str);
}
void output()
{
cout<<"output=\n"<<str<<endl;
cout<<"length="<<length<<endl;
}
void concatenate(char array1[])
{
if (strlen(str)+strlen(array1)>SIZE)
cout<<"\n\n\t\t ERROR! \n\n";
else
strcat(str,array1);
}
void compare(char array2[])
{
cout<<endl<<"result of strncmp=\n"<<strncmp(str,array2,5)<<endl;
cout<<endl<<"result of strcmp=\n"<<strcmp(str,array2)<<endl;
}

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

};
int main ( )
{
clrscr();
char arr[SIZE]="j"; //by changing the size 'SIZE' of the array
//we can generate the error
for (int loop=0;loop<SIZE;loop++)
arr[loop+1]='\0';
string s,s1(arr);
s.output();
s.input();
s.output();
s.compare(arr);
s.concatenate(arr);
s.output();
getch();
return 0;}

Output Screen

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

TASK 5
#include <iostream.h>
#include <conio.h>
#include <string.h>
void main (void)
{
int b,c,d,e,f;
char a[5];
cout<<"\n\tEnter string: ";
cin>>a;
c=strlen(a);
d=c;
b=0;
f=0;
do
{
if(a[b]==a[c-1])
e=0;
else
e=1;
b++;
c--;
}while(b<=d,c>=1);
if(e==0)
cout<<"\n\tthe Entered word is palindrome";
else
cout<<"\n\tthe Entered word in not palindrome";
}

Output Screen

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

TASK 6
#include <iostream.h>
#include <conio.h>
void main ()
{
int a=5; int*pointer=&a;
cout<<"\n\tThe contents of a: "<<a;
cout<<"\n\tThe address of a: "<<&a;
cout<<"\n\tThe contents of a through pointer: "<<*pointer;
cout<<"\n\tThe address of a through pointer: "<<pointer;
cout<<"\n\ttThe adress of pointer: "<<&pointer;}

Output Screen

LAB: 11

TASK 1
#include <iostream.h>

#include <conio.h>

void main ()

int i=10,j=20,*p=&i,*q=&j;

cout<<"\n\t&*&i : "<<&*&i;

cout<<"\n\t*&*&j : "<<*&*&j;

cout<<"\n\t**&p : "<<**&p;

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

Output Screen

TASK 2
#include <iostream.h>

#include <conio.h>

void main()

int a[10]={1,2,3,4,5,6,7,8,9,10};

int *p;

p=a;

cout<<"*(p+2)="<<*(p+2)<<endl;

cout<<"*p+3="<<*p+3<<endl;

cout<<"*(p+3)+5="<<*(p+3)+5<<endl;

cout<<"*(a+4)="<<*(a+4)<<endl;

cout<<"p[5]="<<p[5]<<endl;

cout<<"a[2]+*p="<<a[2]+*p<<endl;

getch();}

Output Screen

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

TASK 3
#include <iostream.h>

#include <conio.h>

void main()

{int arr[]={2,30,14,35};

int *ptr=arr;

cout<<"++*ptr ="<<++*ptr<<endl;

cout<<"*ptr++ ="<<*ptr++<<endl;

cout<<"(*ptr)++ ="<<(*ptr)++<<endl;

cout<<"*++ptr ="<<*++ptr<<endl;

cout<<"++*ptr++ ="<<++*ptr++<<endl;

getch();

Output Screen

TASK 4
TASK 5
#include<iostream.h>

#include<conio.h>

void swap2(int &,int &);

void swap1(int,int);

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

int main ( )

int a,b;

cout<<"enter two no.\t";

cin>>a>>b;

swap1(a,b);

cout<<"a="<<a<<"\t b="<<b<<endl;

swap2(a,b);

cout<<"a="<<a<<"\t b="<<b<<endl;

return 0;

void swap1(int x,int y)

x=x+y;

y=x-y;

x=x-y;

void swap2(int &x,int &y)

x+=y;

y=x-y;

x=x-y;

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

Output Screen

TASK 6
#include <iostream.h>

#include <conio.h>

void func1(int &x,int &y)

{ x=100,y=200;

void main()

{int b,c;

b=20;c=40;

cout<<"b ="<<b<<endl;

cout<<"c ="<<c<<endl;

func1(b,c);

cout<<"b ="<<b<<endl;

cout<<"c ="<<c<<endl;

getch();}

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

Output Screen

TASK 7
#include<iostream.h>

#include<conio.h>

void func(const int &);

int main ( )

const int a[5]={5,6,7,8,9};

int b[5]={10,11,12,13,14};

func(b[0]);

func (a[0]);

return 0;

void func(const int &x)

cout<<x;}

Output Screen

#include<iostream.h>

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

#include<conio.h>

void func(const int *);

int main ( )

const int a[5]={5,6,7,8,9};

int b[5]={10,11,12,13,14};

const int *p=a;

int *q=b;

func(b);

func (a);

func(q);

func(p);

return 0;

void func(const int *x)

cout<<*++x<<endl;}

Output Screen

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

TASK 8(a)
#include <iostream.h>

#include <conio.h>

class reference

{int a; const int b;public:

reference():b(20) {a=10;}

void func1(){cout<<"non-const function"<<endl;cout<<"a ="<<++a<<"\nb="<<++b;}

void func2()const{cout<<"constant function"<<endl;cout<<" ="<<++a<<"\nb="<<++b<<endl;}

};

void main()

{reference ref;

ref.func1();

ref.func2();

getch();}

Output Screen

TASK 8(b)
TASK 9(a)
#include<iostream.h>

#include<conio.h>

int *fun(int z)

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

cout<<z<<endl;

z=42;

return &z;

void main()

cout<<*fun(5)<<endl;

int *P=fun(10);

cout<<++*P;

Output Screen

TASK 9(b)
#include<iostream.h>

#include<conio.h>

int & fun(int &z)

cout<<z<<endl;

z=42;

return z;

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

void main()

int a=5;

cout<<fun(a)<<endl;

cout<<a;

Output Screen

TASK 10
#include<iostream.h>

#include<conio.h>

void main()

int a=1,*q=&a,**p=&q;

cout<<++a<<"\t"<<++**p<<"\t"<<++*q<<"\t"<<a<<endl;

cout<<**p<<endl;

cout<<--*q<<endl;

cout<<--a<<endl;

cout<<--**p<<endl;

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

Output Screen

LAB: 12

TASK 1
#include<iostream.h>

#include<conio.h>

int main ( )

int size,total=0,*array;

cout<<"enter the total number of values you want to enter: \t";

cin>>size;

array=new int[size];

for (int loop=0;loop<size;loop++)

cout<<"enter value: \t";

cin>>array[loop];

total+=array[loop];

cout<<"\n average is :\t"<<(float)total/size<<endl;

delete array;

return 0;

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

Output Screen

TASK 2
#include<iostream.h>

#include<conio.h>

class dummy

int a,b;

public:

void getdata();

void display();

dummy();

~dummy();

};

int main()

dummy *dumdum=new dummy;

dumdum->getdata();

(*dumdum).display();

dummy *dumdum2=new dummy[10];

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

for (int loop=0;loop<10;loop++)

dumdum2->getdata();

(*dumdum2).display();

return 0;

void dummy::getdata()

cout<<"\nenter #:";

cin>>a;

cout<<"enter #:";

cin>>b;

void dummy::display()

cout<<"\na="<<a<<"\tb="<<b;

dummy::dummy()

a=0;

b=0;

dummy::~dummy()

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

{}

Output Screen

TASK 3
#include<iostream.h>

#include<conio.h>

#include<stdlib.h>

#include<string.h>

const int MAXWORD=50,SIZE=100;

void sort_words(char*[],int);

void swap(char**,char**);

int main ( )

char *wrd[SIZE],word[MAXWORD];

int n,i;

cout<<"\n Enter a string and terminate it with [ctrl+z]"<<endl;

for (i=0;cin>>word,!cin.eof();i++)

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

if (i>SIZE)

cout<<"\nAt most"<<SIZE<<"elements can be sorted ";

exit(1);

wrd[i]=new char [strlen(word)+1];

strcpy(wrd[i],word);

n=i;

sort_words(wrd,n);

for (i=0;i<n;i++)

cout<<wrd[i]<<" ";

getch();

return 0;

void sort_words(char*w[],int n)

int i,j;

for (i=0;i<n;i++)

for (j=i+1;j<n;j++)

if (strcmp(w[i],w[j])>0)

swap(&w[i],&w[j]);

void swap(char**p,char**q)

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

char*tmp;

tmp=*p;

*p=*q;

*q=tmp;

Output Screen

TASK 4

#include<iostream.h>

#include<conio.h>

#include<string.h>

class String

char *s;

int l;

public:

String()

l=79;

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

s=new char[79+1];

String(int x)

s=new char[x+1];

l=x;

String(char *st)

l=strlen(st);

s=new char[l+1];

strcpy(s,st);

void Assign(char *str)

strcpy(s,str);

l=strlen(str);

void print()

cout<<s<<endl;

int len()

return l;

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

void concat(String &a,String &b)

delete s;

s=new char[a.l+b.l+1];

strcpy(s,a.s);

strcat(s,b.s);

l=a.l+b.l;

~String()

delete s;

};

int main()

char *q="ahmed",*p="bilal";

String S1;

cout<<"\n\t S1\n";

S1.print();

cout<<"S1 length="<<S1.len()<<endl;

cout<<"\n***********************************************************\n";

String S2(20);

cout<<"\n\t S2\n";

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

S2.print();

cout<<"S2 length="<<S2.len()<<endl;

cout<<"\n***********************************************************\n";

String S3(q);

cout<<"\n\t S3\n";

S3.print();

cout<<"S3 length="<<S3.len()<<endl;

cout<<"\n***********************************************************\n";

S3.Assign(p);

cout<<"\n\t MODIFIED By Assign S3\n";

S3.print();

cout<<"S3 length="<<S3.len()<<endl;

cout<<"\n***********************************************************\n";

cout<<"\n\t Modified by Concat S1\n";

S1.concat(S2,S3);

S1.print();

cout<<S1.len();

getch();

return 0;

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

Output Screen

TASK 5
#include<iostream.h>

#include<conio.h>

class A{

protected:int i,j;

public: int k;

A():i(1),j(1){}

A(int a,int b):i(a){j=b;}

inline void show(){

cout<<"ints are"<<i<<" and "<<j<<endl;

cout<<"Public int is "<<k<<endl;}};

class B:public A{int m;

public:

B():m(0){}

B(int n):m(n){}

void sum(){

cout<<"sum="<<i+j<<endl;}

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

inline void showm(){

cout<<"derived int is "<<m<<endl;}};

main(){

B b(10);

A a(45,65);

a.show();

b.show();

b.showm();

b.k=100;

b.show();

//b.i=10; //error

b.sum();

//a.showm(); //error

getche();

return 0;}

Output Screen

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

LAB: 13

TASK 1
#include<iostream.h>

#include<conio.h>

#include<new.h>

#include<stdlib.h>

class matrix{

int **p,s1,s2;

public: int ub1,ub2;

matrix(int d1,int d2){

if(d1<0||d2<0) {

cerr<<"Illegal matrix size"<<endl;exit(1);}

s1=d1;s2=d2;

p=new int*[s1];

for(int i=0;i<s1;++i) p[i]=new int [s2];

ub1=s1-1;ub2=s2-1;}

int& element(int i,int j){

if(i<0||i>ub1||j<0||j>ub2)

{cerr<<"Illegal matrix index"<<endl;exit(1);}

return p[i][j];}

void input(){

cout<<"Enter elements";

for(int k=0;k<s1;k++)

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

for(int g=0;g<s2;g++)

cin>>p[k][g];

cout<<endl;}

void printValues(){

cout<<"elements of matrix:\n";

for(int k=0;k<s1;k++)

{for(int g=0;g<s2;g++)

cout<<p[k][g]<<" ";

cout<<endl;}

void printAddress(){

cout<<"Adresses of elements of matrix:\n";

for(int k=0;k<s1;k++)

{for(int g=0;g<s2;g++)

cout<<&p[k][g]<<" ";

cout<<endl;}

void printScalarValues(){

cout<<"Scalar value of elements of matrix:\n";

cout<<sizeof(p)<<endl;

cout<<sizeof(*p);

cout<<endl;

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

~matrix(){

for(int i=0;i<=ub1;++i)delete p[i];

delete p;}

};

main(){

matrix a(3,3);

a.input();

a.printValues();

a.printAddress();

a.printScalarValues();

getche();

return 0;}

Output Screen

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

TASK 2
#include<iostream.h>

#include<conio.h>

#include<new.h>

struct link

int data;

link* next;};

class Linklist

link* first;public:

Linklist(){first=NULL;}

void additem(int d){

link* newlink=new link;

newlink->data=d;

newlink->next=first;

first=newlink;

void display(){

link* current=first;

while(current!=NULL){cout<<current->data<<endl;

current=current->next;}

};

int main(){

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

Linklist a;

a.additem(25);

a.additem(35);

a.additem(45);

a.additem(55);

a.display();

getche();

Output Screen

TASK 3
#include<iostream.h>

#include<conio.h>

class A{

int x;

protected:int y;

public:

A(int m=0,int n=0):x(m),y(n){}

void show(){

cout<<"\nprivate int of A:"<<x<<"\npublic int of A:"<<y<<endl;}};

class B:public A{

int z;public:

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

B(int i=0,int j=0,int k=0):A(i,j),z(k){}

void show(){cout<<"\nprotected int of A:"<<y<<"\nprivate int of B:"<<z<<endl;}};

int main(){

A a=A(1,2);

B b(3,4,5);

a.show();

b.show();

b.A::show();

getche();

return 0;}

Output Screen

TASK 4
#include<iostream.h>

#include<conio.h>

class B;

class A{int a;public:

A(int x=0):a(x){}

friend int sum(A,B);};

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

class B{int b;

public:

B(int y=0):b(y){} friend int sum(A,B);};

int sum(A i,B j)

{ return i.a+j.b;}

int main(){

A a(5);

B b(6);

cout<<"Sum of private ints of classes A and B="<<sum(a,b)<<endl;

getche();

return 0;

Output Screen

TASK 5
#include<iostream.h>

#include<conio.h>

class web{

int x,y;

public:

web():x(0),y(0){}

web(int a,int b){x=a;y=b;}

void operator++(int){

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

++x;++y;}

void operator++(){

++x;++y;}

web operator+(web a){

return web(x+a.x,y+a.y);}

web operator-(web a){

return web(x-a.x,y-a.y);}

web operator*(web a){

return web(x*a.x,y*a.y);}

web operator/(web a){

return web(x/a.x,y/a.y);}

void show(){

cout<<"x="<<x<<"\ny="<<y<<endl;}

};

int main(){ //clrscr();

web ob1,ob2(2,4),ob3(2,6);

ob3++;

++ob3;

ob1=ob2+ob3;

ob1.show();

ob3=ob1/ob2;

ob3.show();

web ob4(10,20);

ob2=(ob1*ob3)-ob4;

ob2.show();

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

getche();

return 0;}

Output Screen

LAB: 14

TASK 1
#include <iostream.h>

#include <conio.h>

#include <string.h>

void main( int arg, char* argv[] )

{ argv[0] = "today";

argv[1] = "is ";

argv[2] = "a";

argv[3] = "very";

argv[4] = "nice";

argv[5] = "day";

arg=6;

for(int i = 0 ; i <arg ; i++) cout<<"\n\t"<<*argv++<<endl;

getch();

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

Output Screen

TASK 2(a)
#include <iostream.h>

#include <conio.h>

const int EXIT_SUCCESS = 0;

class B

{ char* ptrB; public:

B(){ptrB = new char[5]; cout << "\n\tB allocates 5 bytes "<<endl;}

~B() { delete [] ptrB; cout<< "\n\tB de-allocates 5 bytes "<<endl; }

};

class D: public B

{ char* ptrD; public:

D( ){ptrD = new char[10]; cout<<"\n\tD allocates 10 bytes"<<endl;}

~D(){ delete[] ptrD; cout<< "\n\tD de-allocates 10 bytes"<<endl;}

};

void f()

{ B* p=new B;

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

delete p;

int main()

{ f(); //or use Dd;

getche(); return EXIT_SUCCESS;}

Output Screen 1

Output Screen 2

TASK 2(b)
#include <iostream.h>

class B1 {protected: int x;};

class B2 {protected: int x;};

class D: public B1, public B2

{protected: int x;

public:

void test()

{x=999; B1::x=111; B2::x=222;

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

cout<<"\n\td.x="<<x<<"\n\tB1::x="<<B1::x<<"\n\tB2::x="<<B2::x<<endl;} };

void main (void)

{D d;

d.test();

Output Screen

TASK 3
#include <iostream.h>

#include <string.h>

class base1

{ protected: char message[80]; public:

base1(char* m) { strcpy(message,m);}

char* show1() {return message;} };

class base2: public base1

{ protected: char message[80]; public:

base2(char* m):base1("Default Value") {strcpy(message,m);}

base2(char* m,char* n):base1(n) {strcpy(message,m);}

char* show2(){return message;} };

class base3:public base2

{ char message[80]; public:

base3(char* p,char* q,char* r):base2(q) {strcpy(message,p); strcpy(base1::message,r);}

char* show3() {return message;} };

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62


OOP: Turbo C++ Lab: 0-14 Date: 20-12-2013

void main()

{base1 b1("How are you?");

base2 b2 ("I am fine");

base2 b3("what is your name?","My name is XYZ");

base3 b("Where do you live?","I live in Tazila","Very good place");

cout<<"b1::base1= "<<b1.show1()<<endl;

cout<<"b2::base2= "<<b2.show2()<<endl;

cout<<"b2::base1= "<<b2.show1()<<endl;

cout<<"b3::base2= "<<b3.show2()<<endl;

cout<<"b::base3= "<<b.show3()<<endl;

cout<<"b::base2= "<<b.show2()<<endl;

cout<<"b::base1="<<b.show1()<<endl;

Output Screen

Name: Ahmed Bilal Group: B1 Roll No: 12-EE-62

You might also like