SlideShare a Scribd company logo
1 of 10
Program 3: Write a program to overload+ and * operators to add and multiplytwo complex
numbers.
#include<iostream.h>
#include<conio.h>
class comp
{
floatr,i;
public:
comp(){}
comp(floatd,floate)
{
r=d; i=e;
}
comp operator+(comp b)
{
comp temp;
temp.r=r+b.r;
temp.i=i+b.i;
returntemp;
}
comp operator*(comp b)
{
comp temp;
temp.r=r*b.r-i*b.i;
temp.i=i*b.r+b.i*r;
returntemp;
}
void show()
{
cout<<endl<<r<<" + "<<i<<"i";}
};
void main()
{
clrscr();
comp c1(5,2),c2(7,3),c3,c4;
c3=c1+c2;
c4=c1*c2;
c1.show();
c2.show();
c3.show();
c4.show();
getch();
}
Program 2: Write a program to show the use of friendfunctionin order to access the private data
of a class.
#include<iostream.h>
#include<conio.h>
#include<string.h>
class abc
{
char name[20];
intm;
public:
abc()
{
strcpy(name,"Akshay");
m=85;
}
friendvoid replace(abc&a1);
void show()
{
cout<<endl<<name<<""<<m;}
};
void replace(abc&a)
{
strcpy(a.name,"none");
a.m=0;
}
void main()
{
clrscr();
abc a;
a.show();
replace(a);
a.show();
getch();
}
Program 1: Write a program to implementbasicstructure of classesand memberfunction by
readingand printinga studentname and marks and also write a functionto assigngrade to the
student.
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
class studnt
{
floatmarks;char nam[50],grade[2];
public:
void getdata()
{
cout<<"Enter the name and marksof the studentn";
gets(nam);
cout<<endl;
cin>>marks;cout<<endl;
}
void calc()
{
if(marks>=85)
strcpy(grade,"A+");
else if(marks>=75)
strcpy(grade,"A");
else if(marks>=65)
strcpy(grade,"B");
else if(marks>=50)
strcpy(grade,"C");
else if(marks>=40)
strcpy(grade,"D");
else strcpy(grade,"F");
}
void show()
{
cout<<endl<<"Student:"<<nam<<"has grade "<<grade<<endl;
}
};
void main()
{
clrscr();
int n=1,i;
cout<<"nHowmany studentsdatayouwantto createn";cin>>n;
studnt*s;
s= newstudnt[n];
for(i=0;i<n;i++)
{
s[i].getdata();
s[i].calc();
}
for(i=0;i<n;i++)
s[i].show();
getch();
}
Program 4: Write a program to show the use of “this” pointer.
#include<iostream.h>
#include<conio.h>
class student
{
char name[100];
floatpercent;
public:
voidgetdata()
{
cout<<"Enterdata"<<endl;
cout<<"Name:";
cin>>name;
cout<<"Percent:";
cin>>percent;
cout<<endl;
}
student& max(student&s1,student&s2)
{
if(percent>s1.percent&&percent>s2.percent)
return*this;
else if(s1.percent>percent&&s1.percent>s2.percent)
returns1;
else if(s2.percent>percent&&s2.percent>s1.percent)
returns2;
}
voiddisplay()
{
cout<<"Name:"<<name<<endl;
cout<<"Percent:"<<percent;
}
};
void main()
{
students,s1,s2,s3;
s1.getdata();
s2.getdata();
s3.getdata();
s=s3.max(s1,s2);
cout<<"Studentwithhighestpercentage"<<endl;
s.display();
getch();
}
Program 5: Write a program to implementmultiple andmultilevel inheritence.
A) Multilevel inheritance
#include <iostream>
#include<conio.h>
usingnamespace std;
class A
{
public:
voiddisplay()
{
cout<<"Base class content.";
}
};
class B : publicA
{ };
class C : public B
{ };
int main()
{
C obj;
obj.display();
return0;
getch();
}
af
B) Multiple inheritence
#include <iostream>
usingnamespace std;
class Mammal
{
public:
Mammal()
{
cout << "Mammalscan give directbirth."<< endl;
}
};
class WingedAnimal
{
public:
WingedAnimal()
{
cout << "Wingedanimal canflap."<< endl;
}};
class Bat: publicMammal, publicWingedAnimal
{
};
int main()
{
Bat b1;
return0;
}
Program 6: Write a program to implementhybridand heirarchical inheritence.
A) Hybrid inheritance
#include<iostream.h>
#include<conio.h>
class arithmetic
{
protected:
intnum1, num2;
public:
void getdata()
{
cout<<"For Addition:";
cout<<"nEnterthe firstnumber:";
cin>>num1;
cout<<"nEnterthe secondnumber:";
cin>>num2;
}
};
class plus:publicarithmetic
{
protected:
intsum;
public:
void add()
{
sum=num1+num2;
}
};
class minus
{
protected:
intn1,n2,diff;
public:
void sub()
{
cout<<"nForSubtraction:";
cout<<"nEnterthe firstnumber:";
cin>>n1;
cout<<"nEnterthe secondnumber:";
cin>>n2;
diff=n1-n2;
}
};
class result:publicplus,publicminus
{
public:
void display()
{
cout<<"nSumof "<<num1<<" and "<<num2<<"= "<<sum;
cout<<"nDifference of "<<n1<<" and "<<n2<<"= "<<diff;
}};
void main()
{
clrscr();
resultz;
z.getdata();
z.add();
z.sub();
z.display();
getch();
}
A) Heirarchical inheritance
#include <iostream.h>
#include<conio.h>
class Number
{
private:
intnum;
public:
voidgetNumber()
{
cout << "Enteran integernumber:";
cin >> num;
}
intreturnNumber()
{
returnnum;
}
};
class Square:publicNumber
{
public:
int getSquare()
{
intnum,sqr;
num=returnNumber();
sqr=num*num;
returnsqr;
}
};
class Cube:publicNumber
{
public:
int getCube()
{
intnum,cube;
num=returnNumber();
cube=num*num*num;
returncube;
}
};
void main()
{
clrscr();
Square objS;
Cube objC;
intsqr,cube;
objS.getNumber();
sqr=objS.getSquare();
cout<< "Square of "<< objS.returnNumber() <<" is: " << sqr << endl;
objC.getNumber();
cube=objC.getCube();
cout<< "Cube of "<< objS.returnNumber() <<" is:" << cube << endl;
getch();
}

More Related Content

What's hot

Computer Architecture and Organization lab with matlab
Computer Architecture and Organization lab with matlabComputer Architecture and Organization lab with matlab
Computer Architecture and Organization lab with matlabShankar Gangaju
 
C program to add two numbers
C program to add two numbers C program to add two numbers
C program to add two numbers mohdshanu
 
Infix to Prefix (Conversion, Evaluation, Code)
Infix to Prefix (Conversion, Evaluation, Code)Infix to Prefix (Conversion, Evaluation, Code)
Infix to Prefix (Conversion, Evaluation, Code)Ahmed Khateeb
 
C++ Programming - 3rd Study
C++ Programming - 3rd StudyC++ Programming - 3rd Study
C++ Programming - 3rd StudyChris Ohk
 
Ffffffffffff
FfffffffffffFfffffffffff
Ffffffffffffmohdshanu
 
اسلاید دوم جلسه پنجم کلاس پایتون برای هکرهای قانونی
اسلاید دوم جلسه پنجم کلاس پایتون برای هکرهای قانونیاسلاید دوم جلسه پنجم کلاس پایتون برای هکرهای قانونی
اسلاید دوم جلسه پنجم کلاس پایتون برای هکرهای قانونیMohammad Reza Kamalifard
 
How c program execute in c program
How c program execute in c program How c program execute in c program
How c program execute in c program Rumman Ansari
 
Write a program to show the example of hybrid inheritance.
Write a program to show the example of hybrid inheritance.Write a program to show the example of hybrid inheritance.
Write a program to show the example of hybrid inheritance.Mumbai B.Sc.IT Study
 
C-- Sample Programs and Screenshots
C-- Sample Programs and ScreenshotsC-- Sample Programs and Screenshots
C-- Sample Programs and ScreenshotsBen Egadah
 
C multiple choice questions and answers pdf
C multiple choice questions and answers pdfC multiple choice questions and answers pdf
C multiple choice questions and answers pdfchoconyeuquy
 
C mcq practice test 4
C mcq practice test 4C mcq practice test 4
C mcq practice test 4Aman Kamboj
 

What's hot (20)

Computer Architecture and Organization lab with matlab
Computer Architecture and Organization lab with matlabComputer Architecture and Organization lab with matlab
Computer Architecture and Organization lab with matlab
 
C program to add two numbers
C program to add two numbers C program to add two numbers
C program to add two numbers
 
Pslb lab manual
Pslb lab manualPslb lab manual
Pslb lab manual
 
C test
C testC test
C test
 
Infix to Prefix (Conversion, Evaluation, Code)
Infix to Prefix (Conversion, Evaluation, Code)Infix to Prefix (Conversion, Evaluation, Code)
Infix to Prefix (Conversion, Evaluation, Code)
 
1 c introduction
1 c introduction1 c introduction
1 c introduction
 
week-12x
week-12xweek-12x
week-12x
 
C++ Programming - 3rd Study
C++ Programming - 3rd StudyC++ Programming - 3rd Study
C++ Programming - 3rd Study
 
Ffffffffffff
FfffffffffffFfffffffffff
Ffffffffffff
 
Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
 
اسلاید دوم جلسه پنجم کلاس پایتون برای هکرهای قانونی
اسلاید دوم جلسه پنجم کلاس پایتون برای هکرهای قانونیاسلاید دوم جلسه پنجم کلاس پایتون برای هکرهای قانونی
اسلاید دوم جلسه پنجم کلاس پایتون برای هکرهای قانونی
 
Prefix Postfix
Prefix PostfixPrefix Postfix
Prefix Postfix
 
How c program execute in c program
How c program execute in c program How c program execute in c program
How c program execute in c program
 
Practical no 4
Practical no 4Practical no 4
Practical no 4
 
Write a program to show the example of hybrid inheritance.
Write a program to show the example of hybrid inheritance.Write a program to show the example of hybrid inheritance.
Write a program to show the example of hybrid inheritance.
 
Lab loop
Lab loopLab loop
Lab loop
 
C-- Sample Programs and Screenshots
C-- Sample Programs and ScreenshotsC-- Sample Programs and Screenshots
C-- Sample Programs and Screenshots
 
C multiple choice questions and answers pdf
C multiple choice questions and answers pdfC multiple choice questions and answers pdf
C multiple choice questions and answers pdf
 
C mcq practice test 4
C mcq practice test 4C mcq practice test 4
C mcq practice test 4
 
Labsheet_3
Labsheet_3Labsheet_3
Labsheet_3
 

Similar to A.P.S.E PRACTICAL FILE, NIT KURUKSHETRA

Introduction to cpp
Introduction to cppIntroduction to cpp
Introduction to cppNilesh Dalvi
 
Computer Science Sample Paper 2015
Computer Science Sample Paper 2015Computer Science Sample Paper 2015
Computer Science Sample Paper 2015Poonam Chopra
 
c++ practical Digvajiya collage Rajnandgaon
c++ practical  Digvajiya collage Rajnandgaonc++ practical  Digvajiya collage Rajnandgaon
c++ practical Digvajiya collage Rajnandgaonyash production
 
Operator overloading2
Operator overloading2Operator overloading2
Operator overloading2zindadili
 
C++ 11 Features
C++ 11 FeaturesC++ 11 Features
C++ 11 FeaturesJan Rüegg
 
Pads lab manual final
Pads lab manual finalPads lab manual final
Pads lab manual finalAhalyaR
 
'C' language notes (a.p)
'C' language notes (a.p)'C' language notes (a.p)
'C' language notes (a.p)Ashishchinu
 
Cs2312 OOPS LAB MANUAL
Cs2312 OOPS LAB MANUALCs2312 OOPS LAB MANUAL
Cs2312 OOPS LAB MANUALPrabhu D
 
2014 computer science_question_paper
2014 computer science_question_paper2014 computer science_question_paper
2014 computer science_question_papervandna123
 
cuptopointer-180804092048-190306091149 (2).pdf
cuptopointer-180804092048-190306091149 (2).pdfcuptopointer-180804092048-190306091149 (2).pdf
cuptopointer-180804092048-190306091149 (2).pdfYashwanthCse
 
Programming in C Presentation upto FILE
Programming in C Presentation upto FILEProgramming in C Presentation upto FILE
Programming in C Presentation upto FILEDipta Saha
 

Similar to A.P.S.E PRACTICAL FILE, NIT KURUKSHETRA (20)

C++ TUTORIAL 8
C++ TUTORIAL 8C++ TUTORIAL 8
C++ TUTORIAL 8
 
Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
 
Bijender (1)
Bijender (1)Bijender (1)
Bijender (1)
 
Introduction to cpp
Introduction to cppIntroduction to cpp
Introduction to cpp
 
Computer Science Sample Paper 2015
Computer Science Sample Paper 2015Computer Science Sample Paper 2015
Computer Science Sample Paper 2015
 
c++ practical Digvajiya collage Rajnandgaon
c++ practical  Digvajiya collage Rajnandgaonc++ practical  Digvajiya collage Rajnandgaon
c++ practical Digvajiya collage Rajnandgaon
 
Lecture 3 c++
Lecture 3 c++Lecture 3 c++
Lecture 3 c++
 
Operator overloading2
Operator overloading2Operator overloading2
Operator overloading2
 
Lab 1
Lab 1Lab 1
Lab 1
 
C++ 11 Features
C++ 11 FeaturesC++ 11 Features
C++ 11 Features
 
Pads lab manual final
Pads lab manual finalPads lab manual final
Pads lab manual final
 
'C' language notes (a.p)
'C' language notes (a.p)'C' language notes (a.p)
'C' language notes (a.p)
 
Labsheet1stud
Labsheet1studLabsheet1stud
Labsheet1stud
 
Cs2312 OOPS LAB MANUAL
Cs2312 OOPS LAB MANUALCs2312 OOPS LAB MANUAL
Cs2312 OOPS LAB MANUAL
 
2014 computer science_question_paper
2014 computer science_question_paper2014 computer science_question_paper
2014 computer science_question_paper
 
Final DAA_prints.pdf
Final DAA_prints.pdfFinal DAA_prints.pdf
Final DAA_prints.pdf
 
7720
77207720
7720
 
operators.ppt
operators.pptoperators.ppt
operators.ppt
 
cuptopointer-180804092048-190306091149 (2).pdf
cuptopointer-180804092048-190306091149 (2).pdfcuptopointer-180804092048-190306091149 (2).pdf
cuptopointer-180804092048-190306091149 (2).pdf
 
Programming in C Presentation upto FILE
Programming in C Presentation upto FILEProgramming in C Presentation upto FILE
Programming in C Presentation upto FILE
 

Recently uploaded

Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and usesDevarapalliHaritha
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .Satyam Kumar
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxvipinkmenon1
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 

Recently uploaded (20)

Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and uses
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptx
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 

A.P.S.E PRACTICAL FILE, NIT KURUKSHETRA

  • 1. Program 3: Write a program to overload+ and * operators to add and multiplytwo complex numbers. #include<iostream.h> #include<conio.h> class comp { floatr,i; public: comp(){} comp(floatd,floate) { r=d; i=e; } comp operator+(comp b) { comp temp; temp.r=r+b.r; temp.i=i+b.i; returntemp; } comp operator*(comp b) { comp temp; temp.r=r*b.r-i*b.i; temp.i=i*b.r+b.i*r; returntemp; } void show() { cout<<endl<<r<<" + "<<i<<"i";} }; void main() { clrscr(); comp c1(5,2),c2(7,3),c3,c4; c3=c1+c2; c4=c1*c2; c1.show(); c2.show(); c3.show(); c4.show(); getch(); }
  • 2. Program 2: Write a program to show the use of friendfunctionin order to access the private data of a class. #include<iostream.h> #include<conio.h> #include<string.h> class abc { char name[20]; intm; public: abc() { strcpy(name,"Akshay"); m=85; } friendvoid replace(abc&a1); void show() { cout<<endl<<name<<""<<m;} }; void replace(abc&a) { strcpy(a.name,"none"); a.m=0; } void main() { clrscr(); abc a; a.show(); replace(a); a.show(); getch(); }
  • 3. Program 1: Write a program to implementbasicstructure of classesand memberfunction by readingand printinga studentname and marks and also write a functionto assigngrade to the student. #include<iostream.h> #include<conio.h> #include<stdio.h> #include<string.h> class studnt { floatmarks;char nam[50],grade[2]; public: void getdata() { cout<<"Enter the name and marksof the studentn"; gets(nam); cout<<endl; cin>>marks;cout<<endl; } void calc() { if(marks>=85) strcpy(grade,"A+"); else if(marks>=75) strcpy(grade,"A"); else if(marks>=65) strcpy(grade,"B"); else if(marks>=50) strcpy(grade,"C"); else if(marks>=40) strcpy(grade,"D"); else strcpy(grade,"F"); } void show() { cout<<endl<<"Student:"<<nam<<"has grade "<<grade<<endl; } }; void main() { clrscr(); int n=1,i; cout<<"nHowmany studentsdatayouwantto createn";cin>>n; studnt*s; s= newstudnt[n]; for(i=0;i<n;i++) { s[i].getdata(); s[i].calc(); } for(i=0;i<n;i++) s[i].show(); getch(); }
  • 4.
  • 5. Program 4: Write a program to show the use of “this” pointer. #include<iostream.h> #include<conio.h> class student { char name[100]; floatpercent; public: voidgetdata() { cout<<"Enterdata"<<endl; cout<<"Name:"; cin>>name; cout<<"Percent:"; cin>>percent; cout<<endl; } student& max(student&s1,student&s2) { if(percent>s1.percent&&percent>s2.percent) return*this; else if(s1.percent>percent&&s1.percent>s2.percent) returns1; else if(s2.percent>percent&&s2.percent>s1.percent) returns2; } voiddisplay() { cout<<"Name:"<<name<<endl; cout<<"Percent:"<<percent; } }; void main() { students,s1,s2,s3; s1.getdata(); s2.getdata(); s3.getdata(); s=s3.max(s1,s2); cout<<"Studentwithhighestpercentage"<<endl; s.display(); getch(); }
  • 6. Program 5: Write a program to implementmultiple andmultilevel inheritence. A) Multilevel inheritance #include <iostream> #include<conio.h> usingnamespace std; class A { public: voiddisplay() { cout<<"Base class content."; } }; class B : publicA { }; class C : public B { }; int main() { C obj; obj.display(); return0; getch(); } af
  • 7. B) Multiple inheritence #include <iostream> usingnamespace std; class Mammal { public: Mammal() { cout << "Mammalscan give directbirth."<< endl; } }; class WingedAnimal { public: WingedAnimal() { cout << "Wingedanimal canflap."<< endl; }}; class Bat: publicMammal, publicWingedAnimal { }; int main() { Bat b1; return0; }
  • 8. Program 6: Write a program to implementhybridand heirarchical inheritence. A) Hybrid inheritance #include<iostream.h> #include<conio.h> class arithmetic { protected: intnum1, num2; public: void getdata() { cout<<"For Addition:"; cout<<"nEnterthe firstnumber:"; cin>>num1; cout<<"nEnterthe secondnumber:"; cin>>num2; } }; class plus:publicarithmetic { protected: intsum; public: void add() { sum=num1+num2; } }; class minus { protected: intn1,n2,diff; public: void sub() { cout<<"nForSubtraction:"; cout<<"nEnterthe firstnumber:"; cin>>n1; cout<<"nEnterthe secondnumber:"; cin>>n2; diff=n1-n2; } }; class result:publicplus,publicminus { public: void display() { cout<<"nSumof "<<num1<<" and "<<num2<<"= "<<sum; cout<<"nDifference of "<<n1<<" and "<<n2<<"= "<<diff; }};
  • 9. void main() { clrscr(); resultz; z.getdata(); z.add(); z.sub(); z.display(); getch(); } A) Heirarchical inheritance #include <iostream.h> #include<conio.h> class Number { private: intnum; public: voidgetNumber() { cout << "Enteran integernumber:"; cin >> num; } intreturnNumber() { returnnum; } }; class Square:publicNumber { public: int getSquare() { intnum,sqr; num=returnNumber(); sqr=num*num; returnsqr; } }; class Cube:publicNumber
  • 10. { public: int getCube() { intnum,cube; num=returnNumber(); cube=num*num*num; returncube; } }; void main() { clrscr(); Square objS; Cube objC; intsqr,cube; objS.getNumber(); sqr=objS.getSquare(); cout<< "Square of "<< objS.returnNumber() <<" is: " << sqr << endl; objC.getNumber(); cube=objC.getCube(); cout<< "Cube of "<< objS.returnNumber() <<" is:" << cube << endl; getch(); }