Skip to content

College Activities #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions college/2 constructor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* WAP to print area of the three rooms usin differenttypes of constrctors
default -- parameterized constructor*/

#include<iostream>
using namespace std;

class Area
{
int length, breadth;
public:
Area()
{
cout<<"Enter length and breadth of room 1"<<endl;
cin>>length>>breadth;
cout<<"Area of room 1 is "<<length*breadth<<endl;
}

Area(int l, int b)
{
cout<<"Area of room 2: "<<l*b<<endl;
}

Area(double l, double b)
{
cout<<"Area of room 3: "<<l*b;
}

};

int main(void)
{
Area a;
Area ar(12,12);
Area are(1.2,2.5);
}
Binary file added college/2 constructor.exe
Binary file not shown.
Binary file added college/Exception Handling/c1e2
Binary file not shown.
Binary file added college/Exception Handling/c2
Binary file not shown.
17 changes: 17 additions & 0 deletions college/Exception Handling/c2e3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*WAP a program to input the age of the user. If it is above 18 print,
* "You are eligible to apply! do the following:
* a. Less than 0, "Invalid Age"
* b. Less than 18, "Want some years!"
* c. Greater than 30, "Not eligible"
* d. Greater than 200, "No such age!"
*/

#include<iostream>
using namespace std;

int main()
{


return 0;
}
29 changes: 29 additions & 0 deletions college/Exception Handling/case1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* case 1 -- One catch and one throw
* -- three keywords -> try throw catch
*/


#include<iostream>
using namespace std;

int main()
{
int a = 2, b = 0;
int c;

try
{
if(b==0)
throw 1;
else
c=a/b;
cout<<c<<endl;
}
catch(int x)
{
cout<<"Divided by 0 case";
}

return 0;
}
42 changes: 42 additions & 0 deletions college/Exception Handling/case2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* multiple throws and multiple catches
*
* /*
* WAP to input only +ve numbers.
* If user inputs -ve number show -- "Negative Numbers Not Allowed" as exception
* If user inputs 0 number show -- "Zero Not Allowed" as exception
*/



#include<iostream>
using namespace std;

int main()
{
int PN;
cout<<"Input any positive number"<<endl;
cin>>PN;
try
{
if(PN<0)
throw 1;
else
cout<<"You've entered: "<<PN;
}
catch(int x)
{
cout<<endl<<"Negative Numbers Not Allowed"<<endl<<endl;
}

try
{
if(PN==0)
throw 1.1f;
}
catch(float y)
{
cout<<endl<<"Zero Not Allowed"<<endl<<endl;
}

return 0;
}
28 changes: 28 additions & 0 deletions college/Exception Handling/caseg2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* WAP to input only +ve numbers. If user inputs -ve number show
* "Negative Numbers Not Allowed" as exception
*/



#include<iostream>
using namespace std;

int main()
{
int PN;
cout<<"Input any positive number"<<endl;
cin>>PN;
try
{
if(PN<0)
throw 0;
else
cout<<"You've entered: "<<PN;
}
catch(int x)
{
cout<<endl<<"Negative Numbers Not Allowed"<<endl<<endl;
}
return 0;
}
23 changes: 23 additions & 0 deletions college/Exception Handling/eg.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include<iostream>
using namespace std;

int main()
{
int a = 2, b = 0;
int c;

try
{
if(b==0)
throw 1;
else
c=a/b;
cout<<c<<endl;
}
catch(int x)
{
cout<<"Divided by 0 case";
}

return 0;
}
Binary file added college/Exception Handling/eg1
Binary file not shown.
25 changes: 25 additions & 0 deletions college/Lab 8 - Polymorphism/function overloading.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include<iostream>
using namespace std;

class fxnover
{
public:
void sum(int a,int b)
{
int sum = a+b;
cout<<"Sum: "<<sum<<endl;
}
void sum(double a, double b)
{
double sum = a+b;
cout<<"Sum: "<<sum<<endl;
}
};

int main()
{
fxnover fo;
fo.sum(1,2);
fo.sum(1.2,2.1);
return 0;
}
Binary file added college/Lab 8 - Polymorphism/fxo
Binary file not shown.
56 changes: 56 additions & 0 deletions college/Lab 8 - Polymorphism/operator overloading.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Note: can't overload these operators :: . .* ?:
* operator overloading is fuction of Polymorphism i.e OOP -- hence operator overloading isn't available in C
*/


#include<iostream>
using namespace std;

class Complex
{
int real,imag;

public:
Complex()
{
real = 0;
imag = 0;
}

Complex(int r, int i)
{
this->real = r; //this
this->imag = i;
}
void show()
{
cout<<real<<"+"<<imag<<"i"<<endl;
}

Complex operator +(Complex o) //copy constructor , operator is a keyword
{
Complex c;
c.real = this->real + o.real;
c.imag = this->imag + o.imag;
return c;
}
};

int main()
{
Complex c1(2,3);
cout<<endl<<"First Input"<<endl;
c1.show();

Complex c2(4,3);
cout<<endl<<"Second Input"<<endl;
c2.show();

cout<<endl<<"Sum"<<endl;
Complex c3;
c3 = c1 + c2;
c3.show();

return 0;
}
Binary file added college/Lab 8 - Polymorphism/opv
Binary file not shown.
Binary file added college/Lab 8 - Polymorphism/virtual
Binary file not shown.
38 changes: 38 additions & 0 deletions college/all construtor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*WAP to print sum and difference of two float numbers using all three types of constructors*/

#include<iostream>
using namespace std;

class calc
{
float a,b;
public:
calc()
{
float x=28.34, y=22.21;
cout<<"Sum: "<<x+y<<endl<<"Difference: "<<x-y<<endl<<endl;
}
calc(float x, float y)
{
a=x;b=y;
cout<<"Sum: "<<a+b<<endl<<"Difference: "<<a-b<<endl<<endl;
}
calc(calc &ulate)
{
a=ulate.a;
b=ulate.b;
cout<<"Sum: "<<a+b<<endl<<"Difference: "<<a-b;
}
};

int main()
{
calc ua;
calc mn(12.2,1.22);
calc op(ua);
calc opq(mn);

return 0;
}


Binary file added college/all construtor.exe
Binary file not shown.
67 changes: 67 additions & 0 deletions college/c.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include <iostream>
#include <string>
#include <windows.h>
// #include<windows.h>
// Sleep(milliseconds);
using namespace std;

class k
{
int num, n = 1;
string name[100];
static int counter;

public:
// IT IS THE INPUT SECTION
void input()
{
// cout << "Press 1 to exit from the program" << endl;
cout << "Enter the name of the item " << endl;
for (int i = 0; i < n; i++)
{
Sleep(100);
cin >> name[i];
n++;
counter++;
cin >> num;
if (num == 0)
{
break;
}
else
continue;
}
}

// IT IS THE OUTPUT SECTION
void output()
{
cout << endl
<< "The name of the stored items is" << endl;
for (int i = 0; i < counter; i++)
{
cout << name[i] << endl;
}
}
static void dc()
{
cout << "Total no of stored items is : " << counter << endl;
}
};
int k::counter;
int main()
{
k c;
c.input();
c.output();
k::dc();
return 0;
}

/*

Yaha maile main kura chai user le input function ma ta jatti pani items haru halna milyo ni ta
Ani yesi user lai for eg:5 item halesi input function bata bahira niklina mann xa re haina tara
user le harek patak ko string input sang sangai num vanne varaible ko value ni magxa , so yesto huda user
le harek patak ma number ko value haliraknu parxa, which is not simple and easy for each repeattion of loop
*/
Binary file added college/c.exe
Binary file not shown.
Loading