diff --git a/college/2 constructor.cpp b/college/2 constructor.cpp new file mode 100644 index 0000000..cf896ef --- /dev/null +++ b/college/2 constructor.cpp @@ -0,0 +1,35 @@ +/* WAP to print area of the three rooms usin differenttypes of constrctors +default -- parameterized constructor*/ + +#include +using namespace std; + +class Area +{ + int length, breadth; +public: + Area() + { + cout<<"Enter length and breadth of room 1"<>length>>breadth; + cout<<"Area of room 1 is "< +using namespace std; + +int main() +{ + + + return 0; +} diff --git a/college/Exception Handling/case1.cpp b/college/Exception Handling/case1.cpp new file mode 100644 index 0000000..82e6a96 --- /dev/null +++ b/college/Exception Handling/case1.cpp @@ -0,0 +1,29 @@ +/* + * case 1 -- One catch and one throw + * -- three keywords -> try throw catch +*/ + + +#include +using namespace std; + +int main() +{ + int a = 2, b = 0; + int c; + + try + { + if(b==0) + throw 1; + else + c=a/b; + cout< +using namespace std; + +int main() +{ + int PN; + cout<<"Input any positive number"<>PN; + try + { + if(PN<0) + throw 1; + else + cout<<"You've entered: "< +using namespace std; + +int main() +{ + int PN; + cout<<"Input any positive number"<>PN; + try + { + if(PN<0) + throw 0; + else + cout<<"You've entered: "< +using namespace std; + +int main() +{ + int a = 2, b = 0; + int c; + + try + { + if(b==0) + throw 1; + else + c=a/b; + cout< +using namespace std; + +class fxnover +{ +public: + void sum(int a,int b) + { + int sum = a+b; + cout<<"Sum: "< +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 + o.real; + c.imag = this->imag + o.imag; + return c; + } +}; + +int main() +{ + Complex c1(2,3); + cout< +using namespace std; + +class calc +{ + float a,b; +public: + calc() + { + float x=28.34, y=22.21; + cout<<"Sum: "< +#include +#include +// #include +// 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 +*/ \ No newline at end of file diff --git a/college/c.exe b/college/c.exe new file mode 100644 index 0000000..6cc6748 Binary files /dev/null and b/college/c.exe differ diff --git a/college/complex using complex.cpp b/college/complex using complex.cpp new file mode 100644 index 0000000..da93c5f --- /dev/null +++ b/college/complex using complex.cpp @@ -0,0 +1,37 @@ +class complex +{ + int real,imag; +public: + void set() + { + cout<<"enter real and imag part: "; + cin>>real>>imag; + } + + friend complex sum(complex,complex); + void display(); +}; + +void complex::display() +{ +cout<<"the sum of complex num is"< +using namespace std; + +class Example +{ + int n1,n2; +public: + Example() + { + n1=100; + n2=50; + } + Example(int num1, int num2) + { + n1=num1; + n2=num2; + } + Example(Example &obj) + { + n1=obj.n1; + n2=obj.n2; + } + + void display() + { + cout<<"n1 ="< + +using namespace std; + +class calc +{ + int x,y; +public: + calc(int n1, int n2) + { + x=n1; + y=n2; + } + + int sum() + { + int sum; + sum = x+y; + cout<<"sum: "<>num1>>num2; + + calc op(num1,num2); + op.sum(); + op.difference(); + op.product(); + op.remainder(); + + return 0; +} \ No newline at end of file diff --git a/college/constructor parameterized.exe b/college/constructor parameterized.exe new file mode 100644 index 0000000..1a78253 Binary files /dev/null and b/college/constructor parameterized.exe differ diff --git a/college/constructor.cpp b/college/constructor.cpp new file mode 100644 index 0000000..487cf55 --- /dev/null +++ b/college/constructor.cpp @@ -0,0 +1,21 @@ +#include +#include + +using namespace std; + +class counter +{ + int count; +public: + counter(int num) + { + count = num; + cout <<"count: "< +#include +using namespace std; + +class Staff +{ + protected: + char name[50]; + int id; + + public: + void ReadData() + { + id = 201; + name = "Sita"; + } + + void DisplayData() + { + cout<<"Name:"< +using namespace std; + +class Square +{ +private: +int num; + +public: + void getdata() + { + cout << "Enter the number"<>num; + } + void display() + { + cout << "Square of a given number= "<< num*num< +using namespace std; + +class Complex +{ +private: + int real,imag ; +public: + Complex() + { + real=0; + imag=0; + } + + void display( ) + { + cout<<"Real part="< 2+3i +class 2 -> 4-9i +WAP to add two complex numbers +*/ + +#include +using namespace std; + +class c1 +{ + float r1,i1; + + void display(float a, float b) + { + r1=a; + i1=b; + + } +}; \ No newline at end of file diff --git a/college/friend function 2.cpp b/college/friend function 2.cpp new file mode 100644 index 0000000..3582f48 --- /dev/null +++ b/college/friend function 2.cpp @@ -0,0 +1,53 @@ +/* +friend function +WAP to add numbers in twow classes and display the output +*/ + + +#include +using namespace std; + +class first; +class second +{ + int num2; +public: + void display() + { + cout<<"Enter a number: "; + cin>>num2; + cout<<"Num is "<>num; + cout<<"Num is "< +using namespace std; + +class first; +class second; + +class second +{ + int num2,num1; +public: + void display() + { + cout<<"Enter two numbers: "; + cin>>num2>>num1; + cout<<"Numbers are "<>num3>>num4; + cout<<"Numbers are "< +using namespace std; + +class person2; +class person1; + +class person1 +{ + int nob; //number of books +public: + void num() + { + cout<<"Enter your number of books"<>nob; + } + + friend void diff(person1 obj1, person2 obj2); +}; + +class person2 +{ + int nob; //number of books +public: + void num() + { + cout<<"Enter your number of books"<>nob; + } + + friend void diff(person1 obj1, person2 obj2); +}; + +void diff(person1 obj1, person2 obj2) +{ + int diff; + if (obj1.nob > obj2.nob) + diff = obj1.nob - obj2.nob; + else + diff = obj2.nob - obj1.nob; + + cout<<"The difference in your books is: "< + using namespace std; + + class sem2; + class sem4; + + class sem2{ + int nop; //number of periods + public: + void in() + { + cout<<"Enter your number of periods: "; + cin nop; + } + + friend void product(sem2 o1, sem4 o2); + }; + + class sem4{ + int nop; //number of periods + public: + void in() + { + cout<<"Enter your number of periods: "; + cin nop; + } + + friend void product(sem2 o1, sem4 o2); + }; + + friend void product(sem2 o1, sem4 o2) + { + int pro; + pro = o1.nop*o2.nop; + cout<<"Product of number of period is: "< +using namespace std; + +class first +{ + int num; +public: + void display() + { + cout<<"Enter a number: "; + cin>>num; + cout<<"Num is "< + +int main() +{ + std::cout<<"Hello, World!"; + return 0; +} diff --git a/college/inheritance/hierarchical inheritance/mul.cpp b/college/inheritance/hierarchical inheritance/mul.cpp new file mode 100644 index 0000000..f108037 --- /dev/null +++ b/college/inheritance/hierarchical inheritance/mul.cpp @@ -0,0 +1,76 @@ +/* + +*/ + +#include + +using namespace std; + +class Numbers +{ +protected: + int n1,n2,sum,diff,mul; +}; + +class Add:protected Numbers +{ +public: + void getNumbers() + { + cout<<"Duita anka haalnuhoss: "; + cin>>n1>>n2; + } + void calcultaion() + { + sum=n1+n2; + cout<>n1>>n2; + } + void calcultaion() + { + diff=n1-n2; + cout<>n1>>n2; + } + void calcultaion() + { + mul=n1*n2; + cout< +using namespace std; + +class Numbre1 +{ +protected: + int Num1; +public: + void ask1() + { + cout<<"Pahilo anka: "; + cin>>Num1; + } +}; + +class Numbre2 +{ +protected: + int Num2; +public: + void ask2() + { + cout<<"Pahilo anka: "; + cin>>Num2; + } +}; + +class Sum:public Numbre1,Numbre2 +{ +public: + void um() + { + cout<<"Sum is "< + +using namespace std; + +class Fruit +{ +public: + Fruit() + { + cout<<"i am fruit"; + } +}; + +class Banana:public Fruit +{ +public: + Banana() + { + cout<<"i am banana"; + } +}; + +int main() +{ + cout<<"i. Make object of fruit only"< + +using namespace std; + +class Numbers +{ +protected: + int n1,n2,sum; +}; + +class Add:protected Numbers +{ +public: + void getNumbers() + { + cout<<"Duita anka haalnuhoss: "; + cin>>n1>>n2; + } + void addition() + { + sum=n1+n2; + cout< + +using namespace std; + +inline int max(int a, int b) +{ + return (a>b)?a:b; +} + +int main() +{ + int x,y; + cout<<"Enter x and y:"<>x>>y; + cout<<"Maximum value is:"< +#include +using namespace std; + +class student +{ + int roll; +public: + void getdata(int x) + { + roll=x; + } + + void display() + { + cout<<"Roll number="< +using namespace std; + +class Number +{ +private: + int n1,n2; +public: + Number() + { + n1=4; + n2=8; + } + + display() + { + int add,sub,pro,rem; + add= n1+n2; + sub= n1-n2; + pro= n1*n2; + rem= n1%n2; + cout<<"Add: "< +using namespace std; + +class A +{ +public: + virtual void disp()=0; +}; + +class B:public A +{ +public: + void disp() + { + cout<<"Pure Virtual Function"; + } +}; + +int main() +{ +A *p; +B o; +p = &o; +p -> disp(); +return 0; +} + +/* + +Pure Virtual Function + +*/ diff --git a/college/rabin code.cpp b/college/rabin code.cpp new file mode 100644 index 0000000..82da8d6 --- /dev/null +++ b/college/rabin code.cpp @@ -0,0 +1,61 @@ +#include +#include +using namespace std; +main() +{ + start: + system("cls"); + int h = 0, m = 0, s = 0; + // again for setting an alarm which produces sound for efficiency + int h1 = 0, m1 = 0, s1 = 0; + cout << "Enter in the proper format of HH:MM:SS" << endl; + cin >> h >> m >> s; + cout << "set the alaem in proper time format of HH:MM:SS" << endl; + cin >> h1 >> m1 >> s1; + if (h < 24 && m < 60 && s < 60) + { + + + for (h = 0; h < 24; h++) + { + for (m = 0; m < 60; m++) + { + for (s = 0; s < 60; s++) + { + system("cls"); + // This above code will cler the existing data + // This above code will cler the existing data + cout << h << ":" << m << ":" << s; + // for checkiung of and determination of AM and PM + if (h < 12) + { + cout << "PM"; + } + else + { + cout << "AM"; + } + if (h == h1 && m == m1 && s == s1) + { + cout<<"play the alarm"< +#include +using namespace std; + +class Staff +{ +privte: + int id; + string name; +public: + void ReadData(int i, string n) + { + id = i; + name = n; + } + void DisplayData() + { + cout<<"ID: "< +using namespace std; + +class items +{ +char name[20]; +float price; +static int counter; + +public: +void IO(); +static void Counter(); +}; + +int items::counter={0}; +void items::IO() +{ + cout<<"Enter a name and price of item: "<>name>>price; + cout<<"Name is "< +using namespace std; + +class stirng_test_check +{ +private: + string name; +public: + stirng_test_check(); + ~stirng_test_check(); +}; + +stirng_test_check::stirng_test_check() +{ + cout<<"Enter your name : "; + cin>>name; +} + +stirng_test_check::~stirng_test_check() +{ + // cout<<"Enter your name : "; + // cin>>name; + +} + +int main() +{ + stirng_test_check h[3]; + for (int i = 0; i < 3; i++) + { + sting + } + + // stirng_test_check(); + return 0; + +} diff --git a/college/stirng_test_check.exe b/college/stirng_test_check.exe new file mode 100644 index 0000000..c09eae1 Binary files /dev/null and b/college/stirng_test_check.exe differ diff --git a/college/tempCodeRunnerFile.cpp b/college/tempCodeRunnerFile.cpp new file mode 100644 index 0000000..fb0fc22 --- /dev/null +++ b/college/tempCodeRunnerFile.cpp @@ -0,0 +1,63 @@ +/* +Wap to print sum, difference, product and remainfder of two numbers using +sum(), difference(), product() and remainder() functions by initializing using +parameterized cinstructor. +*/ + +#include + +using namespace std; + +class calc +{ + int x,y; +public: + calc(int n1, int n2) + { + x=n1; + y=n2; + } + + int sum() + { + int sum; + sum = x+y; + cout<<"sum: "<>num1>>num2; + + calc op(num1,num2); + op.sum(); + op.difference(); + op.product(); + op.remainder(); + + return 0; +} \ No newline at end of file diff --git a/college/tempCodeRunnerFile.exe b/college/tempCodeRunnerFile.exe new file mode 100644 index 0000000..90b3356 Binary files /dev/null and b/college/tempCodeRunnerFile.exe differ diff --git a/college/template/2parameter.cpp b/college/template/2parameter.cpp new file mode 100644 index 0000000..2b858db --- /dev/null +++ b/college/template/2parameter.cpp @@ -0,0 +1,22 @@ +#include +using namespace std; + +template +void maximum(A first, B second) +{ + if(first>second) + { + cout< +using namespace std; + +template +class Test +{ + T a; +public: + void add(T x, T y) + { + a = x+y; + } + void show() + { + cout<te; + te.add(12.2f,2.21f); + te.show(); + return 0; +} diff --git a/college/template/classtemplateformat b/college/template/classtemplateformat new file mode 100644 index 0000000..d673134 --- /dev/null +++ b/college/template/classtemplateformat @@ -0,0 +1,18 @@ +//format foe class multiple class template, with multiple parametere + +/* practice quiestions: +1. Make a class template what will show the addition and subbtraction of two float numbers. +2. Make a class template what will show the multiplication and division of two integer numbers. +3. Make a class template that wil display three things(integer, float and character) +*/ + +template +class class_name +{ +........ +.....//Body of class +..... +}; + +Object: +class_nameobject name; diff --git a/college/template/format b/college/template/format new file mode 100644 index 0000000..4e9510b --- /dev/null +++ b/college/template/format @@ -0,0 +1,15 @@ +//Template Format:: + +template +class class_name +{ + +..............//class member +..............//specifications with +..............//anonymous type T +..............//where or approproate + +}; + +Object: +class_name object_name; diff --git a/college/template/max b/college/template/max new file mode 100644 index 0000000..649c2f3 Binary files /dev/null and b/college/template/max differ diff --git a/college/template/max.cpp b/college/template/max.cpp new file mode 100644 index 0000000..c1fe046 --- /dev/null +++ b/college/template/max.cpp @@ -0,0 +1,24 @@ +#include +using namespace std; + +template //Template Function declaration +T maximum(T first, T second) //Template Function definition +{ + if(first>second) + { + return first; + } + else + { + return second; + } +} + +int main() +{ + cout<<"The highest interger number is: "< +using namespace std; + +template +class AB +{ + F add, sub; + I mul, div; +public: + void Add(F a, F b) + { + add = a + b; + cout<<"The addition is "<ab; + ab.Add(21.2,21.2); + ab.Sub(22.1,2.21); + ab.Mul(1,2); + ab.Div(2,1); + return 0; +} diff --git a/college/template/mul3 b/college/template/mul3 new file mode 100644 index 0000000..3b6a96c Binary files /dev/null and b/college/template/mul3 differ diff --git a/college/template/multiplication b/college/template/multiplication new file mode 100644 index 0000000..5d971d6 Binary files /dev/null and b/college/template/multiplication differ diff --git a/college/template/multiplication.cpp b/college/template/multiplication.cpp new file mode 100644 index 0000000..c87ebb5 --- /dev/null +++ b/college/template/multiplication.cpp @@ -0,0 +1,16 @@ +#include +using namespace std; + +template +T mul(T n1, T n2) +{ + return n1*n2; +} + +int main() +{ + cout<<"The multiplication of two integers is: "< +using namespace std; + +template //single parameter +T mul(T n1, T n2, T n3) +{ + return n1*n2*n3; +} + +int main() +{ + cout<<"The multiplication of two integers is: "< +using namespace std; + +template +T sum(T n1, T n2) +{ + return n1+n2; +} + +int main() +{ + cout<<"The sum of two integers is: "< +#include +using namespace std; +class info +{ + string name[100]; + static int count; + +public: + void input() + { + static int n = 1; + cout << "Press 0 for exit :" << endl; + for (int i = 1; i <= n; i++) + { + cout << "name of the item :"; + cin >> name[i]; + + if (name[i] == "0") + { + break; + } + + else + { + count++; + n++; + } + } + } + void output() + { + cout << endl; + for (int i = 1; i <= count; i++) + { + cout << "name of the item :" << name[i] << endl; + } + } + static void displaycount() + { + cout << "The total no. of items stored is : " << count << endl; + } +}; +int info::count; +int main() +{ + system("cls"); + info i; + i.input(); + i.output(); + info::displaycount(); + return 0; +} diff --git a/college/test_string.exe b/college/test_string.exe new file mode 100644 index 0000000..bd97676 Binary files /dev/null and b/college/test_string.exe differ diff --git a/college/virtualfxn.cpp b/college/virtualfxn.cpp new file mode 100644 index 0000000..87b22b4 --- /dev/null +++ b/college/virtualfxn.cpp @@ -0,0 +1,29 @@ +#include +using namespace std; + +class Base +{ +public: + virtual void disp() + { + cout<<"Base Class"; + } +}; + +class Derived: public Base +{ +public: + void disp() + { + cout<<"Derived Class"; + } +}; + +int main() +{ + Base *p; //pointer + Derived d; //object + p = &d; //pointer pointing to object of derived class + p -> disp(); //invokes function of derived class + return 0; +} diff --git a/college/virtualfxn2.cpp b/college/virtualfxn2.cpp new file mode 100644 index 0000000..245b0dc --- /dev/null +++ b/college/virtualfxn2.cpp @@ -0,0 +1,47 @@ +#include +using namespace std; + +class Base +{ +public: + virtual void print() //virtual in base clsas doesn't get invoked + { + cout<<"Print base class"< print(); //virtaual function bind at runtime + bptr -> show(); //non virtual function. bind at compile time + return 0; +} + +/* + + +Print Derived Class +Show Derived Class + +*/