├── LamdaExpression262.cpp ├── FunctionToDisplayHello134.cpp ├── InfiniteLoop72.cpp ├── Auto259.cpp ├── DemoFirstProgram23.cpp ├── ScopingRule151.cpp ├── StaticVariables153.cpp ├── DefaultArguments140.cpp ├── DynamicAllocation110.cpp ├── RecursiveFunction154.cpp ├── ReturnByRefrence148.cpp ├── WritingInAFile245.cpp ├── DemoPointers107.cpp ├── FinalKeyword260.cpp ├── StudentExercise143.cpp ├── AddingAllElementsOfArray90.cpp ├── DemoCompoundAssignment34.cpp ├── DrawingPattern298.cpp ├── FindUserNameFromEmail132.cpp ├── PracticeProblemMultiplicationTable73.cpp ├── FunctionWithArgument134.cpp ├── StringLengthUsingLoop128.cpp ├── FactorsOfANumber76.cpp ├── CompoundConditionYoung52.cpp ├── FactorialOfANumber75.cpp ├── LocalAndGlobalVariables150.cpp ├── PassByAddress143.cpp ├── ReverseANumber82.cpp ├── SomOfNaturalNumbersUsingLoop74.cpp ├── CompoundConditionEligible52.cpp ├── DrawingPattern197.cpp ├── FindingMaxOf2Nos46.cpp ├── GcdOf2Nos85.cpp ├── PreprocessorDirectives236.cpp ├── StringLengthUsingIterator128.cpp ├── SumOfNaturalNumbersUsingWhileLoop74.cpp ├── DrawingPattern399.cpp ├── FIndingMaxElementFromAnArray91.cpp ├── PracticeProblemChangeCasesOfLetters129.cpp ├── FunctionTemplate138.cpp ├── PracticeProblemChangeCasesToUpperCase129.cpp ├── SumOfFactors77.cpp ├── ShortCircuit60.cpp ├── StructVsClass176.cpp ├── PassByReference145.cpp ├── ExceptionHandlingConstruct223.cpp ├── ReturnByAddress147.cpp ├── ProgramToFindGCD85.cpp ├── PassByValue142.cpp ├── Validation48.cpp ├── InclassInitializerAndDelegationOfConstructor265.cpp ├── Namespaces238.cpp ├── ArmstrongNumber81.cpp ├── DemoConditionalStatement47.cpp ├── FunctionToFindMaxOf3Nos134.cpp ├── PrimeNumber78.cpp ├── InnerClasses220.cpp ├── PerfectNumber77.cpp ├── ReadingFromAFile247.cpp ├── FindingMaxOf3Nos54.cpp ├── Ellipses267.cpp ├── FunctionOverloading136.cpp ├── FunctionOverriding204.cpp ├── CheckingPalindrome131.cpp ├── STLClassesUsingVector256.cpp ├── StudentExercise8155.cpp ├── ThrowAndCatchBetweenFunctions225.cpp ├── Demo1VirtualFunction206.cpp ├── ArrayLinearSearch92.cpp ├── DefaultConstructors170.cpp ├── StaticDataMembers216.cpp ├── Demo2VirtualFunction207.cpp ├── DemoFriendFunctionAndClass214.cpp ├── DemoIncrementAndDecrementOperators36.cpp ├── ThisPointer175.cpp ├── DemoDestructor240.cpp ├── Overflow38.cpp ├── ArrayBinarySearch93.cpp ├── Demo1BaseClassPtrDerivedClassObject200.cpp ├── Inheritance187.cpp ├── StaticFunctionOfAClass216.cpp ├── StudentExercise6104.cpp ├── VirtualDestructor242.cpp ├── DemoDynamicDeclarations62.cpp ├── DemoLoops71.cpp ├── AllAboutThrow227.cpp ├── PracticeProblemMatrixOperations103.cpp ├── NatureOfQuadraticRoots55.cpp ├── OperatorOverloadingUsingAdd179.cpp ├── AbstractClass211.cpp ├── Demo2BaseClassPtrDerivedClassObject201.cpp ├── PointerToAnObject163.cpp ├── ClassInC++161.cpp ├── PointerArithmitic112.cpp ├── SwitchUsingMenu66.cpp ├── DemoCompoundCondition52.cpp ├── StudentExercise244.cpp ├── AllAboutCatch229.cpp ├── BitwiseOperators40.cpp ├── STLMapClasses257.cpp ├── StudentExercise4LeapYear68.cpp ├── StudentExercise586.cpp ├── Demo3BaseClassPtrDerivedClassObject202.cpp ├── SmartUniquePointer264.cpp ├── DemoPolymorphism209.cpp ├── SmartSharedPointer264.cpp ├── PracticeStudentExercise367.cpp ├── CountVowelsAndWordsInAString130.cpp ├── ConstructorsInInheritance190.cpp ├── DayNameUsingElseIfLadder58.cpp ├── DayNameUsingSwitchCase65.cpp ├── InsertionOperatorOverloadingUsingStreamOperator183.cpp ├── OperatorOverloadingUsing+Operator179.cpp ├── OperatorOverloadingUsingFriendFunction181.cpp ├── StaticMemberExamples218.cpp ├── AccessorsAndMutators166.cpp ├── DemoAccessorsAndMutators166.cpp ├── DemoWaysOfInheritance196.cpp ├── DemoTemplateClassesOfTypeInt232.cpp ├── StudentExercise13230.cpp ├── DemoTemplateClassesOfTypeFloat232.cpp ├── AccessSpecifiers193.cpp ├── StudentExercise12212.cpp ├── StudentExercise9177.cpp ├── StudentExercise11198.cpp ├── StudentExercise10184.cpp ├── Serialization248.cpp ├── StudentExercise7105.cpp ├── StudentExercise14251.cpp ├── StudentExercise15258.cpp └── InheritanceExample188.cpp /LamdaExpression262.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | [](int x,int y) 7 | { 8 | cout<<"Sum is "< 2 | using namespace std; 3 | 4 | void display() 5 | { 6 | cout<<"Hello"; 7 | } 8 | 9 | int main() 10 | { 11 | display(); 12 | 13 | return 0; 14 | 15 | } 16 | 17 | -------------------------------------------------------------------------------- /InfiniteLoop72.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int i=0; 7 | 8 | for(;;) 9 | { 10 | cout<<" Hello"; 11 | i++; 12 | } 13 | return 0; 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Auto259.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | float fun() 5 | { 6 | return 2.34f; 7 | } 8 | 9 | int main() 10 | { 11 | double d=12.3f; 12 | int i=9; 13 | auto x=2*d+i; 14 | 15 | cout< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | string str; 7 | cout<<"Enetr your Name"; 8 | cin>>str; 9 | 10 | cout<<"Welcome "< 2 | using namespace std; 3 | 4 | int x=10; 5 | int main() 6 | { 7 | int x=20; 8 | { 9 | int x=30; 10 | cout< 2 | using namespace std; 3 | 4 | void fun() 5 | { 6 | static int s=10; 7 | s++; 8 | 9 | cout< 2 | using namespace std; 3 | 4 | int sum(int a,int b,int c=0) 5 | { 6 | return a+b+c; 7 | } 8 | 9 | int main() 10 | { 11 | cout< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int size; 7 | cout<<"Enter Number of Elements"; 8 | cin>>size; 9 | int A[size]; 10 | 11 | cout< 2 | using namespace std; 3 | 4 | void fun(int n) 5 | { 6 | if(n>0) 7 | { 8 | cout< 2 | using namespace std; 3 | 4 | int & fun(int &x) 5 | { 6 | return x; 7 | } 8 | 9 | int main() 10 | { 11 | int a=10; 12 | fun(a)=25; 13 | 14 | cout< 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | ofstream ofs("My.Text",ios::trunc); 8 | ofs<<"john"< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int a=10; 7 | int *p=&a; 8 | 9 | cout< 2 | using namespace std; 3 | 4 | class Parent 5 | { 6 | virtual void show() final 7 | { 8 | 9 | } 10 | 11 | }; 12 | 13 | class Child:Parent 14 | { 15 | void show() 16 | { 17 | 18 | } 19 | 20 | }; 21 | 22 | 23 | -------------------------------------------------------------------------------- /StudentExercise143.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | float radius; 7 | float area; 8 | 9 | cout<<"Enrer Radius of a Circle"; 10 | cin>>radius; 11 | area=3.1425*radius*radius; 12 | 13 | cout<<"Area of a Circle is "< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int a[7]={4,8,6,9,5,2,7}; 7 | int n=7,sum=0; 8 | 9 | for(int i=0;i<7;i++) 10 | { 11 | sum=sum+a[i]; 12 | } 13 | 14 | cout<<"sum is"< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int sum=10,x=5; 7 | sum+=x; 8 | cout< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | for(int i=0;i<4;i++) 7 | { 8 | for(int j=0;j<4;j++) 9 | { 10 | if(i>=j) 11 | cout<<"*"; 12 | } 13 | 14 | cout< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | string email="john123@gmail.com"; 7 | int i=(int)email.find('@'); 8 | string uname=email.substr(0,i); 9 | 10 | cout<<"User Name is "< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int n,i; 7 | cout<<"Enter a Number"; 8 | cin>>n; 9 | 10 | for(i=1;i<=10;i++) 11 | { 12 | cout< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int i,n; 7 | cout<<"Enter the Number"; 8 | cin>>n; 9 | 10 | for(i=1;i<=n;i++) 11 | { 12 | if(n%i==0) 13 | { 14 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int age; 6 | cout<<"Enter Age"; 7 | cin>>age; 8 | 9 | if(age>=12&&age<=50) 10 | { 11 | cout<<"Young"; 12 | } 13 | else 14 | { 15 | cout<<"Not Young"; 16 | } 17 | 18 | return 0; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /FactorialOfANumber75.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int n,i=1,fact=1; 7 | cout<<"Enter the Number"; 8 | cin>>n; 9 | 10 | for(i=1;i<=n;i++) 11 | { 12 | fact=fact*i; 13 | } 14 | cout<<"Factorial of"< 2 | using namespace std; 3 | 4 | int g=5; 5 | void fun() 6 | { 7 | int a=10; 8 | a++; 9 | g++; 10 | 11 | cout< 2 | using namespace std; 3 | 4 | void swap(int *a,int *b) 5 | { 6 | int temp; 7 | temp=*a; 8 | *a=*b; 9 | *b=temp; 10 | } 11 | 12 | int main() 13 | { 14 | int x=10,y=20; 15 | swap(&x,&y); 16 | cout< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int n,r,rev=0; 7 | cout<<"Enter the Number"; 8 | cin>>n; 9 | 10 | while(n>0) 11 | { 12 | r=n%10; 13 | n=n/10; 14 | rev=rev*10+r; 15 | } 16 | cout<<"Reverse Number is"< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int n,i,sum=0; 7 | cout<<"Enter the Number"; 8 | cin>>n; 9 | 10 | for(i=1;i<=n;i++) 11 | { 12 | sum=sum+i; 13 | } 14 | cout<<"Sum of Natural no is"< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int age; 7 | cout<<"Enter Age"; 8 | cin>>age; 9 | 10 | if(age<=12||age>=50) 11 | { 12 | cout<<"Eligible"; 13 | } 14 | else 15 | { 16 | cout<<"Not Eligible"; 17 | } 18 | 19 | return 0; 20 | 21 | } 22 | -------------------------------------------------------------------------------- /DrawingPattern197.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int count=1; 7 | 8 | for(int i=0;i<4;i++) 9 | { 10 | for(int j=0;j<4;j++) 11 | { 12 | cout< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int x,y; 7 | cout<<"Enter 2 nos"; 8 | cin>>x>>y; 9 | 10 | if(x>y) 11 | { 12 | cout<<"Maximum is"< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int m,n; 7 | cout<<"Enter two Numbers"; 8 | cin>>m>>n; 9 | 10 | while(m!=n) 11 | { 12 | if(m>n) 13 | m=m-n; 14 | else if(n>m) 15 | n=n-m; 16 | } 17 | cout<<"GCD of 2nos "< 2 | using namespace std; 3 | 4 | #define max(x,y) (x>y?x:y) 5 | #define msg(x) #x 6 | #define pI 3.1425 7 | 8 | #ifndef pI 9 | #define pI 3 10 | #endif 11 | 12 | int main() 13 | { 14 | cout< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | string str="welcome"; 7 | string::iterator it; 8 | int count=0; 9 | 10 | for(it=str.begin();it!=str.end();it++) 11 | { 12 | count++; 13 | } 14 | cout<<"length is"< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int n,i=1,sum=0; 7 | cout<<"Enter the Number"; 8 | cin>>n; 9 | 10 | while(i<=n) 11 | { 12 | sum=sum+i; 13 | i++; 14 | } 15 | cout<<"Sum of Natural no is"< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | for(int i=0;i<4;i++) 7 | { 8 | for(int j=0;j<4;j++) 9 | { 10 | if(i+j>4-1) 11 | cout<<"*"; 12 | else 13 | cout<<" "; 14 | } 15 | 16 | cout< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int A[7]={4,8,6,9,5,2,7}; 7 | int n=7,max; 8 | max=A[0]; 9 | 10 | for(int i=0;i<7;i++) 11 | { 12 | if(A[i]>max) 13 | { 14 | max=A[i]; 15 | } 16 | } 17 | cout<<"Maxmium no is"< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | string str="WeLcOMe"; 7 | 8 | for(int i=0;str[i]!='\0';i++) 9 | { 10 | if(str[i]>=65 && str[i]<=90) 11 | { 12 | str[i]=str[i]+32; 13 | } 14 | } 15 | cout< 2 | using namespace std; 3 | 4 | template 5 | T maxim(T a,T b) 6 | { 7 | return a>b?a:b; 8 | } 9 | 10 | int main() 11 | { 12 | cout< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | string str="wELcoMe7"; 7 | 8 | for(int i=0;str[i]!='\0';i++) 9 | { 10 | if(str[i]>=97 && str[i]<=122) 11 | { 12 | str[i]=str[i]-32; 13 | } 14 | } 15 | cout< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int i,n,sum=0; 7 | cout<<"Enter the Number"; 8 | cin>>n; 9 | 10 | for(i=1;i<=n;i++) 11 | { 12 | if(n%i==0) 13 | { 14 | sum=sum+i; 15 | } 16 | } 17 | cout<<"Sum of Factors"< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int a=10,b=5,i=5; 7 | 8 | if(a>b && ++i<=b) 9 | { 10 | 11 | } 12 | cout< 2 | using namespace std; 3 | 4 | class Demo 5 | { 6 | public: 7 | int x; 8 | int y; 9 | 10 | void display() 11 | { 12 | cout< 2 | using namespace std; 3 | 4 | void swap(int &a,int &b) 5 | { 6 | cout<<&a<<" "<<&b< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int x=10,y=0,z; 7 | 8 | try 9 | { 10 | if(y==0) 11 | throw 1; 12 | z=x/y; 13 | cout< 2 | using namespace std; 3 | 4 | int * fun() 5 | { 6 | int *p=new int[5]; 7 | for(int i=0;i<5;i++) 8 | { 9 | p[i]=5*i; 10 | } 11 | 12 | cout< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int m,n; 7 | cout<<"Enter 2 Numbers "<>m>>n; 9 | 10 | while(m!=n) 11 | { 12 | if(m>n) 13 | m=m-n; 14 | else 15 | n=n-m; 16 | } 17 | 18 | cout<<"GCD is "< 2 | using namespace std; 3 | 4 | void swap(int a,int b) 5 | { 6 | cout< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int a,b,c; 7 | cout<<"Enter Two Numbers: "<>a>>b; 9 | 10 | if(b==0) 11 | { 12 | cout<<"Division By Zero"< 2 | # include 3 | using namespace std; 4 | 5 | class Test 6 | { 7 | int x=10; 8 | int y=13; 9 | public: 10 | Test(int a,int b) 11 | { 12 | x=a; 13 | y=b; 14 | } 15 | Test():Test(1,1) 16 | { 17 | 18 | } 19 | 20 | }; 21 | 22 | int main() 23 | { 24 | 25 | } 26 | 27 | -------------------------------------------------------------------------------- /Namespaces238.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | namespace First 5 | { 6 | void fun() 7 | { 8 | cout<<"First"< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int n,r,sum=0,m; 7 | cout<<"Enter the Number"; 8 | cin>>n; 9 | m=n; 10 | 11 | while(n>0) 12 | { 13 | r=n%10; 14 | n=n/10; 15 | sum=sum+r*r*r; 16 | } 17 | 18 | if(sum==m) 19 | cout<<"Armstrong Number"; 20 | else 21 | cout<<"Not a Armstrong Number"; 22 | 23 | return 0; 24 | 25 | } 26 | -------------------------------------------------------------------------------- /DemoConditionalStatement47.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int roll; 7 | cout<<"Enter your Roll Number."<>roll; 9 | 10 | if(roll<1) 11 | { 12 | cout<<"Invalid Roll Number."< 2 | using namespace std; 3 | 4 | int maxim(int a,int b,int c) 5 | { 6 | if(a>b && a>c) 7 | return a; 8 | else if(b>c) 9 | return b; 10 | else 11 | return c; 12 | } 13 | 14 | int main() 15 | { 16 | int a,b,c,d; 17 | cout<<"Enter 3nos"; 18 | cin>>a>>b>>c; 19 | d=maxim(a,b,c); 20 | 21 | cout<<"Maximum no is"< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int i,n,count=0; 7 | cout<<"Enter the Number"; 8 | cin>>n; 9 | 10 | for(i=1;i<=n;i++) 11 | { 12 | if(n%i==0) 13 | { 14 | count++; 15 | } 16 | } 17 | 18 | if(count==2) 19 | cout<<"Prime Number"; 20 | else 21 | cout<<"Not a Prime Number"; 22 | 23 | return 0; 24 | 25 | } 26 | -------------------------------------------------------------------------------- /InnerClasses220.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | class Outer 5 | { 6 | class Inner 7 | { 8 | public: 9 | void display() 10 | { 11 | cout<<"Display of Inner"< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int i,n,sum=0; 7 | cout<<"Enter the Number"; 8 | cin>>n; 9 | 10 | for(i=1;i<=n;i++) 11 | { 12 | if(n%i==0) 13 | { 14 | sum=sum+i; 15 | } 16 | } 17 | 18 | if(2*n==sum) 19 | cout<<"Perfect Number"; 20 | else 21 | cout<<"Not a Perfect Number"; 22 | 23 | return 0; 24 | 25 | } 26 | -------------------------------------------------------------------------------- /ReadingFromAFile247.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | ifstream ifs; 8 | ifs.open("My.txt"); 9 | 10 | cout<<"file is opened"<>name>>roll>>branch; 15 | ifs.close(); 16 | 17 | cout<<"name"< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int a,b,c; 7 | cout<<"Enter 3 no.s"<>a>>b>>c; 9 | 10 | if(a>b && a>c) 11 | { 12 | cout<c) 15 | { 16 | cout< 2 | #include 3 | using namespace std; 4 | 5 | int sum(int n,...) 6 | { 7 | va_list list; 8 | va_start(list,n); 9 | int x; 10 | int s=0; 11 | 12 | for(int i=0;i 2 | using namespace std; 3 | 4 | int sum(int a,int b) 5 | { 6 | return a+b; 7 | } 8 | 9 | float sum(float a,float b) 10 | { 11 | return a+b; 12 | } 13 | 14 | int sum(int a,int b,int c) 15 | { 16 | return a+b+c; 17 | } 18 | 19 | int main() 20 | { 21 | cout< 2 | using namespace std; 3 | 4 | class Base 5 | { 6 | public: 7 | void display() 8 | { 9 | cout<<"Display of Base"< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | string str="MADAM"; 7 | string rev=""; 8 | int len=(int)str.length(); 9 | rev.resize(len); 10 | 11 | for(int i=0,j=len-1;i 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | vector v={2,4,6,8,10}; 8 | v.push_back(20); 9 | v.push_back(30); 10 | vector::iterator itr; 11 | cout<<"Using Iterator"< 2 | using namespace std; 3 | 4 | int Search(int A[],int n,int key) 5 | { 6 | for(int i=0;i>k; 18 | int index=Search(A,7,k); 19 | 20 | cout<<"Element found at index :"< 2 | using namespace std; 3 | 4 | int division(int a,int b) 5 | { 6 | if(b==0) 7 | throw 1; 8 | return a/b; 9 | } 10 | 11 | int main() 12 | { 13 | int x=10,y=2,z; 14 | try 15 | { 16 | if(y==0) 17 | throw 1; 18 | z=x/y; 19 | cout< 2 | using namespace std; 3 | 4 | class Base 5 | { 6 | public: 7 | virtual void fun() 8 | { 9 | cout<<"fun of Base"<fun(); 30 | 31 | } 32 | 33 | -------------------------------------------------------------------------------- /ArrayLinearSearch92.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int A[10],n=10; 7 | int key; 8 | cout<<"Enter Numbers"; 9 | 10 | for(int i=0;i>A[i]; 13 | } 14 | cout<<"Enter Key"; 15 | cin>>key; 16 | 17 | for(int i=0;i 2 | using namespace std; 3 | 4 | class Rectangle 5 | { 6 | private: 7 | int length; 8 | int breadth; 9 | 10 | public: 11 | Rectangle() 12 | { 13 | 14 | length=1; 15 | breadth=1; 16 | } 17 | 18 | int area() 19 | { 20 | return length*breadth; 21 | } 22 | 23 | }; 24 | 25 | int main() 26 | { 27 | Rectangle r1; 28 | cout< 2 | using namespace std; 3 | 4 | class Test 5 | { 6 | public: 7 | int a; 8 | static int count; 9 | Test() 10 | { 11 | a=10; 12 | count++; 13 | } 14 | 15 | }; 16 | 17 | int Test::count=0; 18 | 19 | int main() 20 | { 21 | Test t1,t2; 22 | cout< 2 | using namespace std; 3 | 4 | class BasicCar 5 | { 6 | public: 7 | virtual void start() 8 | { 9 | cout<<"BasicCar Started"<start(); 28 | 29 | } 30 | 31 | -------------------------------------------------------------------------------- /DemoFriendFunctionAndClass214.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | class Your; 5 | class My 6 | { 7 | private: 8 | int a; 9 | protected: 10 | int b; 11 | public: 12 | int c; 13 | friend Your; 14 | }; 15 | 16 | class Your 17 | { 18 | public: 19 | My m; 20 | void fun() 21 | { 22 | m.a=10; 23 | m.b=10; 24 | m.c=10; 25 | } 26 | 27 | }; 28 | 29 | int main() 30 | { 31 | 32 | } 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /DemoIncrementAndDecrementOperators36.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int i=5,j; 7 | j=i++; 8 | cout< 2 | using namespace std; 3 | 4 | class Rectangle 5 | { 6 | private: 7 | int length; 8 | int breadth; 9 | 10 | public: 11 | Rectangle(int length,int breadth) 12 | { 13 | this->length=length; 14 | this->breadth=breadth; 15 | } 16 | 17 | int area() 18 | { 19 | return length*breadth; 20 | } 21 | 22 | }; 23 | 24 | int main() 25 | { 26 | Rectangle r1(10,5); 27 | cout< 2 | using namespace std; 3 | 4 | class Demo 5 | { 6 | int *p; 7 | public: 8 | Demo() 9 | { 10 | p=new int[10]; 11 | cout<<"Constructor of Demo"< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | char a=128; 7 | cout<<(int)a< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int A[10]={6,8,13,17,20,22,25,28,30,35}; 7 | int l=0,h=9,key,mid; 8 | cout<<"Enter the Key"; 9 | cin>>key; 10 | 11 | while(l<=h) 12 | { 13 | mid=(l+h)/2; 14 | if(key==A[mid]) 15 | { 16 | cout<<"Found at"< 2 | using namespace std; 3 | 4 | class Base 5 | { 6 | public: 7 | void fun1() 8 | { 9 | cout<<"fun1 of Base"<fun1(); 29 | ptr->fun2(); 30 | 31 | return 0; 32 | 33 | } 34 | -------------------------------------------------------------------------------- /Inheritance187.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | class Base 5 | { 6 | public: 7 | int a; 8 | void display() 9 | { 10 | cout<<"Display of Base "< 2 | using namespace std; 3 | 4 | class Test 5 | { 6 | public: 7 | int a; 8 | static int count; 9 | Test() 10 | { 11 | a=10; 12 | count++; 13 | } 14 | 15 | static int getCount() 16 | { 17 | return count; 18 | } 19 | 20 | }; 21 | 22 | int Test::count=0; 23 | int main() 24 | { 25 | Test t1,t2; 26 | cout< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int n, i; 7 | float num[100], sum=0.0, average; 8 | 9 | cout << "Enter the Numbers of Element: "; 10 | cin >> n; 11 | 12 | for(i = 0; i < n; ++i) 13 | { 14 | cout << i + 1 << ". Enter number: "; 15 | cin >> num[i]; 16 | sum += num[i]; 17 | } 18 | 19 | average = sum / n; 20 | cout << "Average = " << average; 21 | 22 | return 0; 23 | 24 | } 25 | 26 | -------------------------------------------------------------------------------- /VirtualDestructor242.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | class Base 5 | { 6 | public: 7 | virtual ~Base() 8 | { 9 | cout<<"Destructor of Base"< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int a=10,b=5; 7 | 8 | if(true) 9 | { 10 | int c=a+b; 11 | cout< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int a=0; 7 | 8 | while(a<10) 9 | { 10 | cout< 2 | using namespace std; 3 | 4 | class MyException: exception 5 | { 6 | 7 | }; 8 | 9 | int division(int a,int b)throw(MyException) 10 | { 11 | if(b==0) 12 | throw MyException(); 13 | return a/b; 14 | } 15 | 16 | int main() 17 | { 18 | int x=10,y=2,z; 19 | try 20 | { 21 | z=division(x,y); 22 | cout< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int A[2][3]={3,3,3,3,3,3}; 7 | int B[2][3]={1,1,1,1,1,1}; 8 | int C[2][3]; 9 | 10 | for(int i=0;i<2;i++) 11 | { 12 | for(int j=0;j<3;j++) 13 | { 14 | C[i][j]=A[i][j]+B[i][j]; 15 | } 16 | } 17 | 18 | for(int i=0;i<2;i++) 19 | { 20 | for(int j=0;j<3;j++) 21 | { 22 | cout< 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | float a,b,c,d,r1,r2; 8 | cout<<"Enter a,b,c"; 9 | cin>>a>>b>>c; 10 | d=b*b-4*a*c; 11 | 12 | if(d==0) 13 | { 14 | cout<<"Roots are Real and Equal"<0) 18 | { 19 | cout<<"Roots are Real and Unequal"< 2 | using namespace std; 3 | 4 | class Complex 5 | { 6 | public: 7 | int real; 8 | int img; 9 | 10 | Complex add(Complex c) 11 | { 12 | Complex temp; 13 | temp.real=real+c.real; 14 | temp.img=img+c.img; 15 | return temp; 16 | } 17 | 18 | }; 19 | 20 | int main() 21 | { 22 | Complex c1,c2,c3; 23 | c1.real=5; 24 | c1.img=3; 25 | c2.real=10; 26 | c2.img=5; 27 | c3=c1.add(c2); 28 | 29 | cout< 2 | using namespace std; 3 | 4 | class Base 5 | { 6 | public: 7 | virtual void fun1()=0; 8 | virtual void fun2()=0; 9 | }; 10 | 11 | class Derived :public Base 12 | { 13 | public: 14 | void fun1() 15 | { 16 | cout<<"fun1 of Derived"< 2 | using namespace std; 3 | 4 | class Rectangle 5 | { 6 | public: 7 | void area() 8 | { 9 | cout<<"Area of Rectangle"<area(); 29 | p->volume(); // this function cannot be call 30 | 31 | return 0; 32 | 33 | } 34 | 35 | -------------------------------------------------------------------------------- /PointerToAnObject163.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | class Rectangle 5 | { 6 | public: 7 | int length; 8 | int breadth; 9 | 10 | int area() 11 | { 12 | return length*breadth; 13 | } 14 | 15 | int perimeter() 16 | { 17 | return 2*(length+breadth); 18 | } 19 | 20 | }; 21 | 22 | int main() 23 | { 24 | Rectangle r1; 25 | Rectangle *ptr; 26 | ptr=&r1; 27 | ptr->length=10; 28 | ptr->breadth=5; 29 | 30 | cout<area()<perimeter()< 2 | using namespace std; 3 | 4 | class Rectangle 5 | { 6 | public: 7 | int length; 8 | int breadth; 9 | 10 | int area() 11 | { 12 | return length*breadth; 13 | } 14 | 15 | int perimeter() 16 | { 17 | return 2*(length+breadth); 18 | } 19 | }; 20 | 21 | int main() 22 | { 23 | Rectangle r1; 24 | r1.length=10; 25 | r1.breadth=5; 26 | 27 | cout<<"Area is "< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int A[5]={2,4,6,8,10}; 7 | int *p=A,*q=&A[4]; 8 | cout<<*p< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | cout<<"Menu\n"; 7 | cout<<"1. add\n"<<"2. sub\n"<<"3. multi\n"<<"4. div\n"; 8 | int option; 9 | cout<<"Enter Your Choice"; 10 | cin>>option; 11 | int a,b,c; 12 | cout<<"Enter 2 Numbers"; 13 | cin>>a>>b; 14 | 15 | switch(option) 16 | { 17 | case 1:c=a+b; 18 | break; 19 | case 2:c=a-b; 20 | break; 21 | case 3:c=a*b; 22 | break; 23 | case 4:c=a/b; 24 | break; 25 | } 26 | cout<<"result is"< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int age; 7 | cout<<"Enter your age: "<>age; 9 | 10 | if(age>=12 && age<=50) 11 | { 12 | cout<<"Young"<50) 20 | { 21 | cout<<"Eligible for the offer"< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | float basic; 7 | float percentAllow; 8 | float percentDeduct; 9 | float netSalary; 10 | 11 | cout<<"Enter Basic Salary:"; 12 | cin>>basic; 13 | cout<<"Enter percent of Allowences:"; 14 | cin>>percentAllow; 15 | cout<<"Enter percent of Deductions:"; 16 | cin>>percentDeduct; 17 | 18 | netSalary=basic+basic*percentAllow/100- 19 | basic*percentDeduct/100; 20 | 21 | cout<<"Net Salary is:"< 2 | using namespace std; 3 | 4 | class MyException1: exception 5 | { 6 | 7 | }; 8 | 9 | class MyException2:public MyException1 10 | { 11 | 12 | }; 13 | 14 | int main() 15 | { 16 | try 17 | { 18 | throw MyException1(); 19 | } 20 | 21 | catch(MyException2 e) 22 | { 23 | cout<<"Int Catch"< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int a=11,b=7,c; 7 | c=a&b; 8 | cout<>1; 24 | cout<<(int)m< 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | map m; 8 | m.insert(pair(1,"john")); 9 | m.insert(pair(2,"ravi")); 10 | m.insert(pair(3,"khan")); 11 | map::iterator itr; 12 | 13 | for(itr=m.begin();itr!=m.end();itr++) 14 | { 15 | cout<first<<" "<second<::iterator itr1; 18 | itr1=m.find(2); 19 | 20 | cout<<"Value Found is"<first<<" "<second< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int year; 7 | 8 | cout << "Enter a year: "; 9 | cin >> year; 10 | 11 | if (year % 4 == 0) 12 | { 13 | if (year % 100 == 0) 14 | { 15 | if (year % 400 == 0) 16 | cout << year << " is a leap year."; 17 | else 18 | cout << year << " is not a leap year."; 19 | } 20 | else 21 | cout << year << " is a leap year."; 22 | } 23 | else 24 | cout << year << " is not a leap year."; 25 | 26 | return 0; 27 | 28 | } 29 | -------------------------------------------------------------------------------- /StudentExercise586.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int n, num, digit, rev = 0; 7 | 8 | cout << "Enter a Positive Number: "; 9 | cin >> num; 10 | n = num; 11 | 12 | do 13 | { 14 | digit = num % 10; 15 | rev = (rev * 10) + digit; 16 | num = num / 10; 17 | } while (num != 0); 18 | 19 | cout << " The Reverse of the Number is: " << rev << endl; 20 | 21 | if (n == rev) 22 | cout << " The Number is a Palindrome"; 23 | else 24 | cout << " The Number is Not a Palindrome"; 25 | 26 | return 0; 27 | 28 | } 29 | -------------------------------------------------------------------------------- /Demo3BaseClassPtrDerivedClassObject202.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | class BasicCar 5 | { 6 | public: 7 | void start() 8 | { 9 | cout<<"Car Started"<start(); 33 | ptr->playmusic(); // this function cannot be called. 34 | 35 | } 36 | 37 | -------------------------------------------------------------------------------- /SmartUniquePointer264.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | class Rectangle 6 | { 7 | int length; 8 | int breadth; 9 | public: 10 | Rectangle(int l,int b) 11 | { 12 | length=l; 13 | breadth=b; 14 | } 15 | 16 | int area() 17 | { 18 | return length*breadth; 19 | } 20 | 21 | }; 22 | 23 | int main() 24 | { 25 | unique_ptr ptr(new Rectangle(10,5)); 26 | cout<area()< ptr2; 28 | ptr2=move(ptr); 29 | 30 | cout<area(); 31 | //cout<area(); // this ptr cannot be called. 32 | 33 | } 34 | 35 | -------------------------------------------------------------------------------- /DemoPolymorphism209.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | class Car 5 | { 6 | public: 7 | virtual void start() 8 | { 9 | cout<<"Car Started"<start(); 38 | ptr=new Swift(); 39 | ptr->start(); 40 | 41 | } 42 | 43 | -------------------------------------------------------------------------------- /SmartSharedPointer264.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | class Rectangle 6 | { 7 | int length; 8 | int breadth; 9 | public: 10 | Rectangle(int l,int b) 11 | { 12 | length=l; 13 | breadth=b; 14 | } 15 | 16 | int area() 17 | { 18 | return length*breadth; 19 | } 20 | 21 | }; 22 | 23 | int main() 24 | { 25 | shared_ptr ptr(new Rectangle(10,5)); 26 | cout<area()< ptr2; 28 | ptr2=ptr; 29 | 30 | cout<<"ptr2 "<area()<area()< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | float billAmount; 7 | float discount=0.0; 8 | 9 | cout<<"Enter Bill Amount:"; 10 | cin>>billAmount; 11 | 12 | if(billAmount>=500) 13 | 14 | discount=billAmount*20/100; 15 | 16 | else if(billAmount>=100 && billAmount<500) 17 | 18 | discount=billAmount*10/100; 19 | billAmount=billAmount-discount; 20 | 21 | cout<<"Bill Amount is:"< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | string str="How Many Words"; 7 | int vowels=0,consonant=0,space=0; 8 | 9 | for(int i=0;str[i]!='\0';i++) 10 | { 11 | if(str[i]=='A' || str[i]=='E' || str[i]=='I' || str[i]=='O' || str[i]=='U' || str[i]=='a' || str[i]=='e' || str[i]=='i' || str[i]=='o' || str[i]=='u') 12 | 13 | vowels++; 14 | else if(str[i]==' ') 15 | 16 | space++; 17 | 18 | else 19 | consonant++; 20 | } 21 | 22 | cout<<"vowels "< 2 | using namespace std; 3 | 4 | class Base 5 | { 6 | public: 7 | Base() 8 | { 9 | cout<<"Non-Param Base"< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int day; 7 | cout<<"Enter the Day Number"; 8 | cin>>day; 9 | 10 | if(day==1) 11 | cout<<"Monday"< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int day; 7 | cout<<"Enter Day Number"; 8 | cin>>day; 9 | 10 | switch(day) 11 | { 12 | case 1: cout<<"Monday"< 2 | using namespace std; 3 | 4 | class Complex 5 | { 6 | private: 7 | int real; 8 | int img; 9 | 10 | public: 11 | Complex(int r=0,int i=0) 12 | { 13 | real=r; 14 | img=i; 15 | } 16 | void display() 17 | { 18 | cout< 2 | using namespace std; 3 | 4 | class Complex 5 | { 6 | private: 7 | int real; 8 | int img; 9 | 10 | public: 11 | Complex(int r=0,int i=0) 12 | { 13 | real=r; 14 | img=i; 15 | } 16 | 17 | void display() 18 | { 19 | cout< 2 | using namespace std; 3 | 4 | class Complex 5 | { 6 | private: 7 | int real; 8 | int img; 9 | 10 | public: 11 | Complex(int r=0,int i=0) 12 | { 13 | real=r; 14 | img=i; 15 | } 16 | 17 | void display() 18 | { 19 | cout< 2 | using namespace std; 3 | 4 | class Student 5 | { 6 | public: 7 | int roll; 8 | string name; 9 | 10 | static int addNo; 11 | 12 | Student(string n) 13 | { 14 | addNo++; 15 | roll=addNo; 16 | name=n; 17 | } 18 | 19 | void display() 20 | { 21 | cout<<"Name "< 2 | using namespace std; 3 | 4 | class Rectangle 5 | { 6 | private: 7 | int length; 8 | int breadth; 9 | 10 | public: 11 | void setLength(int l) 12 | { 13 | length=l; 14 | } 15 | 16 | void setBreadth(int b) 17 | { 18 | breadth=b; 19 | } 20 | 21 | int getLength() 22 | { 23 | return length; 24 | } 25 | 26 | int getBreadth() 27 | { 28 | return breadth; 29 | } 30 | 31 | int area() 32 | { 33 | return length*breadth; 34 | } 35 | 36 | int perimeter() 37 | { 38 | return 2*(length+breadth); 39 | } 40 | }; 41 | 42 | int main() 43 | { 44 | Rectangle r1; 45 | r1.setLength(10); 46 | r1.setBreadth(5); 47 | 48 | cout< 2 | using namespace std; 3 | 4 | class Rectangle 5 | { 6 | private: 7 | int length; 8 | int breadth; 9 | 10 | public: 11 | void setLength(int l) 12 | { 13 | length=l; 14 | } 15 | 16 | void setBreadth(int b) 17 | { 18 | breadth=b; 19 | } 20 | 21 | int getLength() 22 | { 23 | return length; 24 | } 25 | 26 | int getBreadth() 27 | { 28 | return breadth; 29 | } 30 | 31 | int area() 32 | { 33 | return length*breadth; 34 | } 35 | 36 | int perimeter() 37 | { 38 | return 2*(length+breadth); 39 | } 40 | 41 | }; 42 | 43 | int main() 44 | { 45 | Rectangle r1; 46 | r1.setLength(10); 47 | r1.setBreadth(5); 48 | 49 | cout< 2 | using namespace std; 3 | 4 | class Parent 5 | { 6 | private: int a; 7 | protected: int b; 8 | public: int c; 9 | 10 | void funParent() 11 | { 12 | a=10; 13 | b=5; 14 | c=15; 15 | } 16 | 17 | }; 18 | 19 | class Child: private Parent 20 | { 21 | private: 22 | protected: 23 | public: 24 | 25 | void funChild() 26 | { 27 | //a=10; 28 | b=5; 29 | c=15; 30 | } 31 | 32 | }; 33 | 34 | class GrandChild : public Child 35 | { 36 | public: 37 | void funGrandChild() 38 | { 39 | //a=10; 40 | //b=5; 41 | //c=20; 42 | } 43 | 44 | }; 45 | 46 | int main() 47 | { 48 | // Child c; 49 | //c.a=10; 50 | //c.b=5; 51 | //c.c=20; 52 | 53 | } 54 | 55 | -------------------------------------------------------------------------------- /DemoTemplateClassesOfTypeInt232.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | template 5 | class Stack 6 | { 7 | private: 8 | T *stk; 9 | int top; 10 | int size; 11 | public: 12 | Stack(int z) 13 | { 14 | size=z; 15 | top=-1; 16 | stk=new int[size]; 17 | } 18 | void push(T x); 19 | T pop(); 20 | }; 21 | 22 | template 23 | void Stack::push(T x) 24 | { 25 | if(top==size-1) 26 | cout<<"Stack is Full"; 27 | else 28 | { 29 | top++; 30 | stk[top]=x; 31 | } 32 | } 33 | 34 | template 35 | T Stack::pop() 36 | { 37 | T x=0; 38 | 39 | if(top==-1) 40 | cout<<"Stack is Empty"< s(10); 52 | s.push(10); 53 | s.push(23); 54 | s.push(33); 55 | 56 | } 57 | 58 | -------------------------------------------------------------------------------- /StudentExercise13230.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | class StackOverFlow:exception{}; 5 | class StackUnderFlow:exception{}; 6 | 7 | class Stack 8 | { 9 | private: 10 | int *stk; 11 | int top=-1; 12 | int size; 13 | public: 14 | Stack(int sz) 15 | { 16 | size=sz; 17 | stk=new int[size]; 18 | } 19 | 20 | void push(int x) 21 | { 22 | if(top==size-1) 23 | throw StackOverFlow(); 24 | top++; 25 | stk[top]=x; 26 | } 27 | 28 | int pop() 29 | { 30 | if(top==-1) 31 | throw StackUnderFlow(); 32 | return stk[top--]; 33 | } 34 | 35 | }; 36 | 37 | int main() 38 | { 39 | Stack s(5); 40 | 41 | s.push(2); 42 | s.push(3); 43 | s.push(4); 44 | s.push(10); 45 | s.push(9); 46 | s.push(8); 47 | 48 | } 49 | 50 | -------------------------------------------------------------------------------- /DemoTemplateClassesOfTypeFloat232.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | template 5 | class Stack 6 | { 7 | private: 8 | T *stk; 9 | int top; 10 | int size; 11 | public: 12 | Stack(int sz) 13 | { 14 | size=sz; 15 | top=-1; 16 | stk=new T[size]; 17 | } 18 | void push(T x); 19 | T pop(); 20 | 21 | }; 22 | 23 | template 24 | void Stack::push(T x) 25 | { 26 | if(top==size-1) 27 | cout<<"Stack is Full"; 28 | else 29 | { 30 | top++; 31 | stk[top]=x; 32 | } 33 | } 34 | 35 | template 36 | T Stack::pop() 37 | { 38 | T x=0; 39 | 40 | if(top==-1) 41 | cout<<"Stack is Empty"< s(10); 53 | s.push(10); 54 | s.push(23); 55 | s.push(33); 56 | 57 | } 58 | 59 | -------------------------------------------------------------------------------- /AccessSpecifiers193.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | class Rectangle 5 | { 6 | private: 7 | int length; 8 | int breadth; 9 | 10 | public: 11 | void setLength(int l) 12 | { 13 | if(l>0) 14 | length=l; 15 | else 16 | length=0; 17 | } 18 | 19 | void setBreadth( int b) 20 | { 21 | if(b>0) 22 | breadth=b; 23 | else 24 | breadth=0; 25 | } 26 | 27 | int getLength() 28 | { 29 | return length; 30 | } 31 | 32 | int getBreadth() 33 | { 34 | return breadth; 35 | } 36 | 37 | int area() 38 | { 39 | return length*breadth; 40 | } 41 | 42 | int perimeter() 43 | { 44 | return 2*(length+breadth); 45 | } 46 | }; 47 | 48 | int main() 49 | { 50 | Rectangle r1; 51 | r1.setLength(10); 52 | r1.setBreadth(5); 53 | 54 | cout< 2 | using namespace std; 3 | 4 | class Shape 5 | { 6 | public: 7 | virtual float area()=0; 8 | virtual float perimeter()=0; 9 | 10 | }; 11 | 12 | class Rectangle:public Shape 13 | { 14 | private: 15 | float length; 16 | float breadth; 17 | public: 18 | Rectangle(int l=1,int b=1){length=1;breadth=b;} 19 | 20 | float area(){ return length*breadth;} 21 | float perimeter(){return 2*(length+breadth);} 22 | 23 | }; 24 | 25 | class Circle:public Shape 26 | { 27 | private: 28 | float radius; 29 | public: 30 | Circle(float r){radius=r;} 31 | float area(){return 3.1425*radius*radius;} 32 | float perimeter(){return 2*3.1425*radius;} 33 | 34 | }; 35 | 36 | int main() 37 | { 38 | Shape *s=new Rectangle(10,5); 39 | 40 | cout<<"Area of Rectangle "<area()<perimeter()<area()<perimeter()< 2 | using namespace std; 3 | 4 | class Student 5 | { 6 | private: 7 | int roll; 8 | string name; 9 | int mathMarks; 10 | int phyMarks; 11 | int chemMarks; 12 | 13 | public: 14 | Student(int r,string n,int m,int p,int c) 15 | { 16 | roll=r; 17 | name=n; 18 | mathMarks=m; 19 | phyMarks=p; 20 | chemMarks=c; 21 | } 22 | 23 | int total() 24 | { 25 | return mathMarks+phyMarks+chemMarks; 26 | } 27 | 28 | char grade() 29 | { 30 | float average=total()/3; 31 | 32 | if(average > 60) 33 | return 'A'; 34 | else if(average>=40 && average<=60) 35 | return 'B'; 36 | else 37 | return 'C'; 38 | } 39 | 40 | }; 41 | 42 | int main() 43 | { 44 | int roll; 45 | string name; 46 | int m,p,c; 47 | cout<<"Enter Roll Number of a Student: "; 48 | cin>>roll; 49 | cout<<"Enter Name of a Student:"; 50 | cin>>name; 51 | cout<<"Enter Marks in 3 Subjects"; 52 | cin>>m>>p>>c; 53 | Student s(roll,name,m,p,c); 54 | 55 | cout<<"Total Marks:"< 2 | using namespace std; 3 | 4 | class Employee 5 | { 6 | private: 7 | int eid; 8 | string name; 9 | 10 | public: 11 | Employee(int e,string n) 12 | { 13 | eid=e; 14 | name=n; 15 | } 16 | 17 | int getEmployeeID(){return eid;} 18 | 19 | string getName(){return name;} 20 | 21 | }; 22 | 23 | class FulltimeEmployee:public Employee 24 | { 25 | private: 26 | int salary; 27 | 28 | public: 29 | FulltimeEmployee(int e,string n,int sal):Employee(e,n) 30 | { 31 | salary=sal; 32 | } 33 | 34 | int getSalary(){return salary;} 35 | 36 | }; 37 | 38 | class ParttimeEmployee: public Employee 39 | { 40 | private: 41 | int wage; 42 | 43 | public: 44 | ParttimeEmployee(int e,string n,int w):Employee(e,n) 45 | { 46 | wage=w; 47 | } 48 | 49 | int getWage(){return wage;} 50 | 51 | }; 52 | 53 | int main() 54 | { 55 | ParttimeEmployee p1(1,"John",300); 56 | FulltimeEmployee p2(2,"Raj",5000); 57 | 58 | cout<<"Salary of "< 2 | using namespace std; 3 | 4 | class Rational 5 | { 6 | private: 7 | int p; 8 | int q; 9 | 10 | public: 11 | Rational() 12 | { 13 | p=1; 14 | q=1; 15 | } 16 | 17 | Rational(int p,int q) 18 | { 19 | this->p=p; 20 | this->q=q; 21 | } 22 | 23 | Rational(Rational &r) 24 | { 25 | this->p=r.p; 26 | this->q=r.q; 27 | } 28 | 29 | int getP(){return p;} 30 | 31 | int getQ(){return q;} 32 | 33 | void setP(int p) 34 | { 35 | this->p=p; 36 | } 37 | 38 | void setQ(int q) 39 | { 40 | this->q=q; 41 | } 42 | 43 | Rational operator+(Rational r) 44 | { 45 | Rational t; 46 | t.p=this->p*r.q+this->q*r.p; 47 | t.q=this->q*r.q; 48 | return t; 49 | } 50 | friend ostream & operator<<(ostream &os,Rational &r); 51 | 52 | }; 53 | 54 | ostream & operator<<(ostream &os,Rational &r) 55 | { 56 | os< 2 | #include 3 | using namespace std; 4 | 5 | class Student 6 | { 7 | private: 8 | string name; 9 | int roll; 10 | string branch; 11 | 12 | public: 13 | Student(){} 14 | 15 | Student(string n,int r,string b) 16 | { 17 | name=n; 18 | roll=r; 19 | branch=b; 20 | } 21 | 22 | friend ofstream & operator<<(ofstream &ofs,Student s); 23 | friend ifstream & operator>>(ifstream &ifs,Student &s); 24 | friend ostream & operator<<(ostream &os,Student &s); 25 | 26 | }; 27 | 28 | ofstream & operator<<(ofstream &ofs,Student s) 29 | { 30 | ofs<>(ifstream &ifs,Student &s) 37 | { 38 | ifs>>s.name; 39 | ifs>>s.roll; 40 | ifs>>s.branch; 41 | return ifs; 42 | } 43 | 44 | ostream & operator<<(ostream &os,Student &s) 45 | { 46 | os<<"Name "<>s1; 61 | 62 | cout< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int A[10][10], B[10][10], Mult[10][10], r1, c1, r2, c2, i, j, k; 7 | 8 | cout << "Enter Rows and Columns for First Matrix: "; 9 | cin >> r1 >> c1; 10 | cout << "Enter Rows and Columns for Second Matrix: "; 11 | cin >> r2 >> c2; 12 | 13 | if (c1!=r2) 14 | { 15 | cout<<"Cant be Multiplied"; 16 | return 0; 17 | } 18 | 19 | // Storing Elements of First Matrix. 20 | cout << endl << "Enter Elements of Matrix 1:" << endl; 21 | 22 | for(i = 0; i < r1; ++i) 23 | for(j = 0; j < c1; ++j) 24 | { 25 | cout << "Enter Element A" << i + 1 << j + 1 << " : "; 26 | cin >> A[i][j]; 27 | } 28 | 29 | // Storing Elements of Second Matrix. 30 | cout << endl << "Enter Elements of Matrix 2:" << endl; 31 | 32 | for(i = 0; i < r2; ++i) 33 | for(j = 0; j < c2; ++j) 34 | { 35 | cout << "Enter Element B" << i + 1 << j + 1 << " : "; 36 | cin >> B[i][j]; 37 | } 38 | 39 | // Multiplying Matrix A and B and Storing in Array Mult. 40 | for(i = 0; i < r1; ++i) 41 | for(j = 0; j < c2; ++j) 42 | { 43 | Mult[i][j]=0; 44 | 45 | for(k = 0; k < c1; ++k) 46 | { 47 | Mult[i][j] += A[i][k] * B[k][j]; 48 | } 49 | } 50 | 51 | // Displaying the Multiplication of Two Matrix. 52 | cout << endl << "Output Matrix: " << endl; 53 | 54 | for(i = 0; i < r1; ++i) 55 | for(j = 0; j < c2; ++j) 56 | { 57 | cout << " " << Mult[i][j]; 58 | 59 | if(j == c2-1) 60 | cout << endl; 61 | } 62 | 63 | return 0; 64 | } 65 | 66 | 67 | -------------------------------------------------------------------------------- /StudentExercise14251.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | class Item 6 | { 7 | private: 8 | string name; 9 | float price; 10 | int qty; 11 | 12 | public: 13 | Item(){} 14 | Item(string n,float p,int q); 15 | 16 | friend ifstream & operator>>(ifstream &fis,Item &i); 17 | friend ofstream & operator<<(ofstream &fos,Item &i); 18 | friend ostream & operator<<(ostream &os,Item &i); 19 | 20 | }; 21 | 22 | int main() 23 | { 24 | int n; 25 | string name; 26 | float price; 27 | int qty; 28 | 29 | cout<<"Enter number of Item:"; 30 | cin>>n; 31 | Item *list[n]; 32 | cout<<"Enter All Item "<>name; 38 | cin>>price; 39 | cin>>qty; 40 | list[i]=new Item(name,price,qty); 41 | 42 | } 43 | 44 | ofstream fos("Items.txt"); 45 | 46 | for(int i=0;i>item; 56 | cout<<"Item "<>(ifstream &fis,Item &i) 75 | { 76 | fis>>i.name>>i.price>>i.qty; 77 | return fis; 78 | } 79 | 80 | ostream & operator<<(ostream &os,Item &i) 81 | { 82 | os< 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | class Item 7 | { 8 | private: 9 | string name; 10 | float price; 11 | int qty; 12 | 13 | public: 14 | Item(){} 15 | Item(string n,float p,int q); 16 | 17 | friend ifstream & operator>>(ifstream &fis,Item &i); 18 | friend ofstream & operator<<(ofstream &fos,Item &i); 19 | friend ostream & operator<<(ostream &os,Item &i); 20 | 21 | }; 22 | 23 | int main() 24 | { 25 | int n; 26 | string name; 27 | float price; 28 | int qty; 29 | cout<<"Enter number of Item:"; 30 | cin>>n; 31 | 32 | vector list; 33 | cout<<"Enter All Item "<>name; 39 | cin>>price; 40 | cin>>qty; 41 | list.push_back(new Item(name,price,qty)); 42 | 43 | } 44 | 45 | ofstream fos("Items.txt"); 46 | vector::iterator itr; 47 | 48 | for(itr=list.begin();itr!=list.end();itr++) 49 | { 50 | fos<<**itr; 51 | } 52 | 53 | Item item; 54 | ifstream fis("Items.txt"); 55 | 56 | for(int i=0;i<3;i++) 57 | { 58 | fis>>item; 59 | cout<<"Item "<>(ifstream &fis,Item &i) 78 | { 79 | fis>>i.name>>i.price>>i.qty; 80 | return fis; 81 | } 82 | 83 | ostream & operator<<(ostream &os,Item &i) 84 | { 85 | os< 2 | using namespace std; 3 | 4 | class Rectangle 5 | { 6 | private: 7 | int length; 8 | int breadth; 9 | 10 | public: 11 | Rectangle(); 12 | Rectangle(int l,int b); 13 | Rectangle(Rectangle &r); 14 | int getLength(){return length;} 15 | int getBreadth(){return breadth;} 16 | 17 | void setLength(int l); 18 | void setBreadth(int b); 19 | int area(); 20 | int perimeter(); 21 | bool isSquare(); 22 | ~Rectangle(); 23 | 24 | }; 25 | 26 | class Cuboid:public Rectangle 27 | { 28 | private: 29 | int height; 30 | 31 | public: 32 | Cuboid(int h) 33 | { 34 | height=h; 35 | } 36 | 37 | int getHeight(){return height;} 38 | 39 | void setHeight(int h){height=h;} 40 | 41 | int volume(){return getLength()*getBreadth()*height;} 42 | 43 | }; 44 | 45 | int main() 46 | { 47 | Cuboid c(5); 48 | c.setLength(10); 49 | c.setBreadth(7); 50 | 51 | cout<<"Volume is "<