Sign up
Login
New paste
English
English
Português
Sign up
Login
New Paste
Browse
EXPERIMENT NO: 1 Aim: - Write a Program to print students name, address and contact number. #include <iostream> using namespace std; struct student{ char name[100]; char address[100]; long long int phone_number; }x; int main (){ cout << "Enter your name : "; cin >> x.name; cout << "Enter your address :"; cin >> x.address; cout << "Enter your mobile number : "; cin >> x.phone_number; cout << "your name is " << x.name << "\n"; cout << "your address is " << x.address << "\n" ; cout << "your contact number is " << x.phone_number << "\n" ; return 0; } OUTPUT: Entering Information Enter Name: Yash Enter Address: Vadodara Enter Contact: 7043749514 Displaying Information Name: Yash Address: Vadodara Contact: 7043749514 OUTPUT SCREENSHOT EXPERIMENT NO: 2 Aim : WAP to find whether number is odd or even #include <iostream> using namespace std; int main(){ int a; cout<<"Enter the number : "; cin>>a; if(a%2==0){ cout<<"Number is even\n"; } else{ cout<<"Number is odd\n"; } return 0; } output screenshot: Aim : WAP to make calculator using switch case # include <iostream> using namespace std; int main() { char op; float num1, num2; cout << "Enter operator: +, -, *, /: "; cin >> op; cout << "Enter first number: "; cin >> num1; cout<<"Enter second number: "; cin >> num2; switch(op) { case '+': cout << num1 << " + " << num2 << " = " << num1 + num2; break; case '-': cout << num1 << " - " << num2 << " = " << num1 - num2; break; case '*': cout << num1 << " * " << num2 << " = " << num1 * num2; break; case '/': cout << num1 << " / " << num2 << " = " << num1 / num2; break; default: cout << "Invalid\n"; break; } return 0; } output screenshot: EXPERIMENT NO: 3 3.1) Aim: - Write a program to print Fibonacci series 0,1,1,2,3,5 using function.(For Looping, Condition, Function) #include<stdio.h> void fibonacciSeries(int range) { int a=0, b=1, c; while (a<=range) { printf("%d\t", a); c = a+b; a = b; b = c; } } int main() { int range; printf("Enter range: "); scanf("%d", &range); printf("The fibonacci series is: \n"); fibonacciSeries(range); return 0; } Output Screenshot:- 3.2) Aim: - Write a program to implement arithmetic operations using inline function. #include<iostream> using namespace std; inline float add(float x,float y) { return(x+y); } inline float sub(float s,float t) { return(s-t); } inline float mul(float p,float q) { return(p*q); } inline float div(float c,float d) { return(c/d); } main() { float a,b; cout<<"enter two number:"<<"\n"; cin>>a>>b; cout<<"\n"<<"ADDITION="; cout<<add(a,b); cout<<"\n"<<"SUBTRACTION="; cout<<sub(a,b); cout<<"\n"<<"MULTIPLICATION="; cout<<mul(a,b); cout<<"\n"<<"DIVISION="; cout<<div(a,b); return 0; } Output Screenshot:- EXPERIMENT NO: 4 4.1) Aim:- Wap for function with default arguments. #include<iostream> using namespace std; void display(char ='*',int=3); int main() { int count=5; cout<<"No argument passed:"; display(); cout<<"First argument passed:"; display('#'); cout<<"Both argument passed:"; display('$',count); return 0; } void display(char c,int count) { for(int **1;i<=count;++i) { cout<<c; } cout<<endl; } Output Screenshot:- 4.2-1) Aim:-Wap to illustrate the concept of call by value. #include<iostream> using namespace std; void change(int data); int main() { int data=3; change(data); cout<<"Value of the data is:"<<data<<endl; return 0; } void change(int data) { data=5; } Output Screenshot:- 4.2-2)Aim:-Wap to illustrate the concept of call by reference. #include<iostream> using namespace std; void swap (int *x,int*y) { int swap; swap =*x; *x=*y; *y=swap; } int main() { int x=500,y=100; swap(&x,&y); cout<<"Value of x is:"<<x<<endl; cout<<"Value of y is:"<<y<<endl; return 0; } Output Screenshot:- EXPERIMENT NO: 5 5.1) Write a program to implement function overloading and return the area of square, rectangle, circle and triangle. #include <iostream> using namespace std; int area(int s) { return (s*s); } int area(int l,int b) { return (l*b); } float area(float r) { return (3.14*r*r); } float area(float bs,float ht) { return ((bs*ht)/2); } int main() { int s,l,b; float r,bs,ht; cout<<"Enter side of a square:"; cin>>s; cout<<"Enter sides of a rectangle:"; cin>>l>>b; cout<<"Enter radius of a circle:"; cin>>r; cout<<"Enter the Base and Height of triangle:"; cin>>bs>>ht; cout<<"Area of a square is: "<<area(s); cout<<"\nArea of a rectangle is: "<<area(l,b); cout<<"\nArea of a circle is: "<<area(r); cout<<"\nArea of a triangle is: "<<area(bs,ht); } Output Screenshot:- 5.2) Write a program to find the mean value of a given number using the friend function. #include <iostream> using namespace std; class base { int val1, val2; public: void get() { cout<<"Enter two values:"<<"\n"; cin>>val1>>val2; } friend float mean(base ob); }; float mean(base ob) { return float(ob.val1+ob.val2)/2; } int main() { base obj; obj.get(); cout<<"Mean value is:"<<mean(obj); } Output Screenshot:- EXPERIMENT NO: 6 6.)AIM: Create an array of 4 objects B[4] to accept and display to details of the three box using methods.(For Array with in class and array of objects concepts) #include<iostream> using namespace std; class box { int l,b,h; public : void getdim() { cout<<"Enter length of box:\n"; cin>>l; cout<<"Enter width of box:\n"; cin>>b; cout<<"Enter height of box:\n"; cin>>h; } void display() { cout<<"The length of box is : "<<l<<endl; cout<<"The width of box is : "<<b<<endl; cout<<"The height of box is : "<<h<<endl<<endl; } }; int main() { int n; cout<<"Enter the number of objects:\n"; cin>>n; box bx[n]; for(int **0;i<n;i++) { cout<<"Enter dimension for box "<<i+1<<"\n"; bx[i].getdim(); } for(int **0;i<n;i++) { cout<<"The dimension for box "<<i+1<<"\n"; bx[i].display(); } return 0; } Ouput : EXPERIMENT NO: 7 7.1) Write a program to create constructor and destructor of the class date with 3 parameters dd,mm,yy. Initialize 2 objects with D1 and D2 with 12-2-2019 and 15-03-2019 values with Parameterized constructor. #include<iostream> using namespace std; class date { int dd,mm,yy; public: date(int,int,int); void show(){ cout<<dd<<"-"<<mm<<"-"<<yy<<endl; } }; date :: date(int d,int m,int y) { dd=d; mm=m; yy=y; } int main() { date D1(12,02,2019); cout<<"Your date D1 is : "; D1.show(); date D2(15,03,2019); cout<<"Your date D2 is : "; D2.show(); } Output Screenshot:- 7.2) Write a program to implement the concept of copy constructor. #include<iostream> using namespace std; class Point { private: int x, y; public: Point(int x1, int y1) { x = x1; y = y1; } Point(const Point &p1) {x = p1.x; y = p1.y; } int getX() { return x; } int getY() { return y; } }; int main() { Point p1(10, 15); Point p2 = p1; cout << " p1.x = " << p1.getX() << ", p1.y = " << p1.getY()<<endl; cout << " p2.x = " << p2.getX() << ", p2.y = " << p2.getY()<<endl; cout <<" Hence we can say , constructor get copied"; return 0; } Output Screenshot:- EXPERIMENT NO: 8 8.1)Aim:- Write a program to add two numbers using operator overloading.(Using Unary operator overloading) INPUT: #include<iostream> using namespace std; class sum { private: int num1; int num2; public: sum(int n1,int n2) { num1=n1; num2=n2; } void operator+() { int sum=0; sum=num1+num2; cout<<"Addition of the two number will be :"<<sum<<endl; } }; int main() { sum a(7,8); +a; return 0; } OUTPUT: 8.2). Write a program to add two numbers using operator overloading. INPUT:- #include<iostream> using namespace std; class overloading { int value; public: void setValue(int temp) { value = temp; } overloading operator+(overloading ob) { overloading t; t.value = value + ob.value; return (t); } void display() { cout << value << endl; } }; int main() { overloading obj1, obj2, result; int a, b; cout << "Enter the value of which you want to add:"; cin >> a>>b; obj1.setValue(a); obj2.setValue(b); result = obj1 + obj2; cout << "Result of the addition is :"; result.display(); return 0; } OUTPUT:- EXPERIMENT NO: 9 9.1) AIM: Write a program to print output of a function using this pointer. INPUT:- #include<iostream> using namespace std; class EXAM { int X; public : void marks(int X) { this -> X = X; } void print() { cout<<"X = "<<X<<endl; } }; int main() { EXAM obj; obj.marks(45); obj.print(); return 0; } OUTPUT: 9.2)Aim :- Write a program to demonstrate basic to class type conversion and class to basic type conversion. INPUT :- #include <iostream> using namespace std; class Time { int hrs, min; public: Time(int t) { cout << "Basic Type to Class Type Conversion...\n"; hrs = t / 60; min = t % 60; } void show(); }; void Time::show() { cout << hrs << ": Hours(s)" << endl; cout << min << " Minutes" << endl; } int main() { int duration; cout << "\nEnter time duration in minutes : "; cin >> duration; Time t1 = duration; t1.show(); } OUTPUT :- 9.3)Aim :- Write a program to one class to another class type conversion. INPUT:- #include <iostream> using namespace std; class Class_type_one { string a = "THIS IS OOPC LAB MANUAL"; public: string get_string() { return (a); } void display() { cout << a << endl; } }; class Class_type_two { string b; public: void operator=(Class_type_one a) { b = a.get_string(); } void display() { cout << b << endl; } }; int main() { Class_type_one a; Class_type_two b; b = a; a.display(); b.display(); return 0; } OUTPUT :- EXPERIMENT-10 AIM:- Consider a class network as shown in figure given below. The class Employee derives information from both Account and Admin classes which in turn derive information from the class Person. Define all the four classes and write a program to create, update and display the information contained in Employee objects. OUTPUT: #include<iostream> using namespace std; class person { string n; int c; public: void pgetdata() { cout<<"\nEnter name : "; cin>>n; cout<<"\nEnter code : "; cin>>c; } void pdisplay() { cout<<"\nName : "<<n; } }; class account: public virtual person { double p; public: void agetdata() { cout<<"\nEnter pay : "; cin>>p; } void adisplay() { cout<<"\nPay : "<<p; } }; class admin: public virtual person { int e; public: void adgetdata() { cout<<"\nEnter experience : "; cin>>e; } void addisplay() { cout<<"\nExperience : "<<e; } }; class master: public account, public admin { public: void getdata() { pgetdata(); adgetdata(); agetdata(); } void display() { pdisplay(); addisplay(); adisplay(); } }; int main() { master m; int a,t=1; do { cout<<"\nEnter 1 for create"; cout<<"\nEnter 2 for update"; cout<<"\nEnter 3 for display"; cin>>a; if(a==1) { if(t==1) { m.getdata(); t++; } else { cout<<"\Cannot Create!"; } } if(a==2) { if(t==1) { cout<<"\nCreate object first!"; } else { m.getdata(); t++; } } if(a==3) { if(t==1) { cout<<"\nCreate object first!"; } else { m.display(); t++; } } }while(a>=1 && a<=3); } OUTPUT: EXPERIMENT-11 11)AIM: Declare a class called item having data members item_code, item_name, cost and discount. Derive two classes from class item, namely employee and customer. The class employee has datamembers like employee_code, employee_name and amount. The class customer has datamembers like customer_name and amount. Define following functions for - initializing data members. - displaying the values of data members. - computing amount to be paid for a purchased item. Also define function main to create objects of both derived classes and to show usage of above functions. OUTPUT: #include<iostream> using namespace std; class item { int code,itemcost; double dis; string itemname; public: void item_code() { cout<<"enter the item-code=\n"; cin>>code; } void item_name() { cout<<"enter the item name\n"; cin>>itemname; } void item_cost() { cout<<"enter the item cost=\n"; cin>>itemcost; } void discount() { cout<<"discount on the item=\n"; cin>>dis; } void display_item() { cout<<"the data of the item=\n"; cout<<"item code="<<code<<"\n"; cout<<"item cost="<<itemcost<<"\n"; cout<<"item discount"<<dis<<"\n"; cout<<"the name of the item="<<itemname<<"\n"; } }; class employee:public item { int empcode,empamount; string empname; public: int emp_code() { cout<<"enter the employee-code=\n"; cin>>empcode; } void emp_name() { cout<<"enter the employee-name=\n"; cin>>empname; } int emp_amount() { cout<<"enter the amount of employee=\n"; cin>>empamount; } void display_employee() {<empcode<<"\n"; cout<<"employee amount="<<empamount<<"\n"; cout<<"employee name="<<empname<<"\n"; } }; class customers:public item { string custname; int custamount; public: void cust_name() { cout<<"enter the customer_name=\n"; cin>>custname; } int cust_amount() { cout<<"enter the amount of the customer=\n"; cin>>custamount; } void display_customers() { cout<<"the data of the cusomers=\n"; cout<<"customer name="<<custname<<"\n"; cout<<"customer amount="<<custamount<<"\n"; } }; int main() { item obj1; employee obj2; customers obj3; obj1.item_code(); obj1.item_name(); obj1.item_cost(); obj1.discount(); obj2.emp_code(); obj2.emp_name(); obj2.emp_amount(); obj3.cust_name(); obj3.cust_amount(); obj1.display_item(); obj2.display_employee(); obj3.display_customers(); return 0; } OUTPUT: EXPERIMENT-12 12.1) AIM: Write a program which adds two numbers using a function template. PROGRAM: #include <iostream> using namespace std; template <class T> T add(T num1, T num2) { return (num1 + num2); } int main() { int res1 = add<int>(6, 3); double res2 = add<double>(3.1, 5.6); cout << res1 << endl; cout << res2; return 0; } OUTPUT:- 12.2)AIM: Write a program which adds two numbers using a class template. PROGRAM: #include <iostream> using namespace std; template <class T> class test { T a, b, c; public: test(T x, T y) { a = x; b = y; } T add() { return a + b; } }; int main() { test<int> obj(6, 12); test<float> obj2(6.4, 8.5); int res1 = obj.add(); float res2 = obj2.add(); cout << res1 << endl; cout << res2 << endl; return 0; } OUTPUT: 18 14.9 EXPERIMENT-13 13.1)AIM:Write a program to read a text file and count the number of characters in it. Input : #include<iostream> #include<fstream> using namespace std; int main() { ifstream fin("text.txt"); char ch; int i, c=0, sp=0; while(fin) { fin.get(ch); **ch; if((i > 63 && i < 91) || (i > 96 && i < 123)) { c++; cout<<ch; } else{ if(ch== ' ') { sp++; cout<<ch; } } } cout<<"\n No. of Characters in a File : "<<c; cout<<"\n Space between the Words : "<<sp; return 0; } OUTPUT: 13.2)AIM:Write a program which merges content of two files and copies that merged content in third file. Input : #include<bits/stdc++.h> #include<iostream> #include<fstream> using namespace std; int main() { fstream f1,f2,f3; string str1,str2,str3; f1.open("file1.txt",ios::in); f2.open("file2.txt",ios::in); f3.open("file3.txt",ios::out); while(getline(f1, str1)){ f3<<str1; f3<<endl; cout<<"Content of file-1 :\n"; cout<<str1<<"\n"; } while(getline(f2, str2)){ f3<<str2; f3<<endl; cout<<"Content of file-2 :\n"; cout<<str2<<"\n"; } while(getline(f3, str3)){ cout<<"Content of file-3 :\n"; cout<<str3<<"\n"; } f1.close(); f2.close(); f3.close(); } Output : Content of file3 :
Paste Settings
Paste Title :
[Optional]
Paste Folder :
[Optional]
Select
Syntax Highlighting :
[Optional]
Select
Markup
CSS
JavaScript
Bash
C
C#
C++
Java
JSON
Lua
Plaintext
C-like
ABAP
ActionScript
Ada
Apache Configuration
APL
AppleScript
Arduino
ARFF
AsciiDoc
6502 Assembly
ASP.NET (C#)
AutoHotKey
AutoIt
Basic
Batch
Bison
Brainfuck
Bro
CoffeeScript
Clojure
Crystal
Content-Security-Policy
CSS Extras
D
Dart
Diff
Django/Jinja2
Docker
Eiffel
Elixir
Elm
ERB
Erlang
F#
Flow
Fortran
GEDCOM
Gherkin
Git
GLSL
GameMaker Language
Go
GraphQL
Groovy
Haml
Handlebars
Haskell
Haxe
HTTP
HTTP Public-Key-Pins
HTTP Strict-Transport-Security
IchigoJam
Icon
Inform 7
INI
IO
J
Jolie
Julia
Keyman
Kotlin
LaTeX
Less
Liquid
Lisp
LiveScript
LOLCODE
Makefile
Markdown
Markup templating
MATLAB
MEL
Mizar
Monkey
N4JS
NASM
nginx
Nim
Nix
NSIS
Objective-C
OCaml
OpenCL
Oz
PARI/GP
Parser
Pascal
Perl
PHP
PHP Extras
PL/SQL
PowerShell
Processing
Prolog
.properties
Protocol Buffers
Pug
Puppet
Pure
Python
Q (kdb+ database)
Qore
R
React JSX
React TSX
Ren'py
Reason
reST (reStructuredText)
Rip
Roboconf
Ruby
Rust
SAS
Sass (Sass)
Sass (Scss)
Scala
Scheme
Smalltalk
Smarty
SQL
Soy (Closure Template)
Stylus
Swift
TAP
Tcl
Textile
Template Toolkit 2
Twig
TypeScript
VB.Net
Velocity
Verilog
VHDL
vim
Visual Basic
WebAssembly
Wiki markup
Xeora
Xojo (REALbasic)
XQuery
YAML
HTML
Paste Expiration :
[Optional]
Never
Self Destroy
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Status :
[Optional]
Public
Unlisted
Private (members only)
Password :
[Optional]
Description:
[Optional]
Tags:
[Optional]
Encrypt Paste
(
?
)
Create New Paste
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Site Languages
×
English
Português
Do you like cookies?
🍪 We use cookies to ensure you get the best experience on our website.
Learn more
I agree