0% found this document useful (0 votes)
128 views63 pages

Visual C++: Click On All Programs Visual Studio Visual C++

Visual C++ allows creating and running C++ programs. The key steps are: 1. Create a workspace/project in Visual Studio and add a C++ source file. 2. Compile the source file to generate an object file and link to generate an executable. 3. Run the executable and view output. 4. Experiments demonstrate concepts like classes, constructors, inheritance, operator overloading etc.

Uploaded by

anon_768827884
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
128 views63 pages

Visual C++: Click On All Programs Visual Studio Visual C++

Visual C++ allows creating and running C++ programs. The key steps are: 1. Create a workspace/project in Visual Studio and add a C++ source file. 2. Compile the source file to generate an object file and link to generate an executable. 3. Run the executable and view output. 4. Experiments demonstrate concepts like classes, constructors, inheritance, operator overloading etc.

Uploaded by

anon_768827884
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 63

Visual c++

Click on All Programs

Visual Studio
Visual C++

Steps for running a c++ source file


Creating workspace in Visual studio(C++) Adding c++ Source file to workspace Compiling (.obj) and building (.exe), the c++ Source file Saving Program and Out put window Deleting old program before starting next Program Save And open workspace(.dsw) for future use

File

1. CREATING NEW WORKSPACE (Project)


New Project (Tab)
WIN 32 CONSOLE APPLICATION

Enter Project Name, folder to save


Select Create new workspace Platforms WIN 32 Kind of console application Empty Project Finish

OK

Setting Source,Out put window font


Increase the Font in vc++ source file Tools Options Formats Source window font Arial size 14 Out put window font Arial size 14

File New File(TAB) C++ source file Select ADD to Project Enter the file name and folder (same as project) to save OK

2. CREATING NEW PROGRAM IN EXITING PROJECT

3. COMPILING AND LINKING PROJECT


Build(Menu) Compile (To make .obj file) If no errors then build Build Build ( To make .exe file) If no errors then Execute Build Execute ( To run the exe file)

4. Saving Program and Out put window


Save the C++ source file in a word document using : Ctrl+a ( To select whole prog) Ctrl+c ( To copy) Ctrl+v ( To paste) Output Window: Click on Output Window (any where) Alt+Prt Sc (Print Screen) and Ctrl+v ( To paste) in word

5. REMOVING PROGRAM FROM PROJECT


Click on Workspcace Window(view menu) File View (LHS) + (source files)
Select old program (.CPP) Press delete key Build Clean

6. OPENING EXITING WORKSPACE OR PROJECT


File open workspace Select the name of your project previously saved (.dsw file ) To start a new program repeat steps from 2 to 6

Experiment 1 //members_insideclass.cpp // Write a program that uses a class where the member functions are defined inside a class. #include<iostream.h> class add // class definition { private: int a,b; public: void input() //member functions are defined inside the class { cout<<"Enter the values of a and b\n"; cin>>a>>b; } void output() { cout<<"Result of addition is:\n"; cout<<a+b<<endl; } }; Continue to next Slide

Experiment 1 //members_insideclass.cpp void main() { add obj; //object declaration for class add obj.input(); obj.output(); }

Experiment 2 //classmembers_outside.cpp // Write a program that uses a class where the member functions are defined outside a class. #include<iostream.h> class add { private: int a,b; public: void input(); void output(); };
Continue to next Slide

Experiment 2 //classmembers_outside.cpp void add :: input() /*member functions are defined outside a class*/ { cout<<"Enter the values of a and b\n"; cin>>a>>b; } void add :: output() { cout<<"Result of addition is:\n"; cout<<a+b<<endl; }
Continue to next Slide

Experiment 2 //classmembers_outside.cpp void main() { add obj; //declaring object obj for class add obj.input(); obj.output();

Experiment 3 //static data members.cpp // Write a program to demonstrate the use of static data members. #include<iostream.h> class book { private: static int count; // static data member public: book() { count=1; } void addbook() { count++; } void displaybook() { cout<< "The Number Of The Books Are:"<< count<<endl; } }; Continue to next Slide

Experiment 3
//static data members.cpp

int book::count; void main() { book b1,b2;


b1.addbook(); b1.displaybook(); cout<<endl; b2.addbook(); b2.displaybook(); }

Experiment 4 //const data members.cpp

// Write a program to demonstrate the use of const data members. #include<iostream.h> class a { const int b; public: a(int c):b(c) // syntax for declaring constant data member { } void dis() { cout<<b<<endl; } }x(9);
Continue to next Slide

Experiment 4 //const data members.cpp


void main() { x.dis(); }

Experiment 5 //c_zero_parameterised.cpp
//Write a program to demonstrate the use of zero argument and parameterized constructor. #include<iostream.h> class numbers { private: int a,b; public: numbers() // zero argument { a=10; b=20; } numbers(int x,int y) // parameterized argument { a=x; b=y; } void display() { cout<<"a="<<a<<endl<<"b="<<b<<endl; } }; Continue to next Slide

Experiment 5 //c_zero_parameterised.cpp
void main() { numbers obj,obj1(30,40); obj.display(); obj1.display(); }

Experiment 6 //copy_constructor.cpp /*WAP to show the example of dynamic constructor (copy constructor ). WAP which reads a complex number and copies to another number using copy constructor*/ # include<iostream.h> class complex { int r,i; public: complex( int a, int b) { r = a ; i = b; }
complex( complex &c) { r = c.r ; i = c.i; } void show() { cout<< r <<" + i" << i <<endl; } };
Continue to next Slide

Experiment 6 //copy_constructor.cpp void main() { int x ,y; cout<<"Enter the Real Part :" ; cin >> x; cout<<"Enter the Imag Part :" ; cin>>y; complex c1(x,y); // 1st constructor is called complex c2(c1); // copy constructor is called cout<<"first Number is :"; c1.show(); cout<<"Second Number is :"; c2.show(); }

Experiment 7 //explict_constructor.cpp // WAP to show the example of explicit constructor. # include<iostream.h> class number { int m,n; public: number( int, int); //constructor declared void display( void) { cout<<"m = "<<m<<endl; cout<<"n = "<<n<<endl; } }; number::number(int x, int y) //constructor defined { m = x; n = y; } Continue to next Slide

Experiment 7 //explict_constructor.cpp
void main() { number n1 = number(56,78); /*constructor called explicitly */ cout<<"The number are: "<<endl; n1.display(); }

Experiment 8 //overloading_inc_dec_operator.cpp
//Write a program to demonstrate the overloading of increment and decrement operators. #include<iostream.h> class incdec { private: int a,b; public: incdec() { a=5; b=8; } void operator ++() { a++; b++; } void operator --() { a--; b--; } void out() { cout<<"a="<<a<<endl; cout<<"b="<<b<<endl; cout<<endl; } }; Continue to next Slide

Experiment 8 //overloading_inc_dec_operator.cpp

void main() { incdec a1,b1; ++a1; --b1; a1.out(); b1.out(); }

Experiment 9 //overlo_binary.cpp
// WAP to show the example of operator overloading (unary operator) #include<iostream.h> class complex { int r,i; public: void getdata() { cout<<"Enter the Real part : "; cin>>r; cout<<"Enter the Imag part : "; cin>>i; } void operator ++() //overload ++ { ++r; ++i; } void showdata() { cout<< r << " + i " << i <<endl; } }; Continue to next Slide

Experiment 9 //overlo_binary.cpp

void main() { complex c1; c1.getdata(); cout << "Number before increament "<<endl; c1.showdata(); c1++; cout << "Number after increament "<<endl; c1.showdata(); }

Experiment 10 //typecasting_basic.cpp
//Write a program to demonstrate the typecasting of basic type to class type. #include<iostream.h> class distance { int feet; float inches; public: distance(float mtr) { float f=3.28*mtr; feet=int(f); inches=12*(f-feet); } void show() { cout<<"distance in feet and inches is : "<<endl; cout<<feet<<"\'-"<<inches<<"\""<<endl; } }; Continue to next Slide

Experiment 10 //typecasting_basic.cpp

void main() { float meter; cout<<"enter a distance in meters:"; cin>>meter; distance d1=meter; d1.show(); }

Experiment 11 //typecasing_class_basic.cpp
//Write a program to demonstrate the typecasting of class to basic type. #include<iostream.h> class distance { int feet; float inches; public: distance(int f,float i) { feet=f; inches=i; } void show() { cout<<feet<<"\'-"<<inches<<"\""<<endl; } operator float () { float ft=inches/12; ft=ft+feet; return(ft/3.28); } }; Continue to next Slide

Experiment 11 //typecasing_class_basic.cpp

void main() { distance d1(3,3.36); float m=d1; cout<<"distance in meter:"<<m<<endl; cout<<"distance in feet and inches:"<<endl; d1.show(); }

Experiment 12 //typecasting_class_class.cpp
//Write a program to demonstrate the typecasting of class type to class type. #include<iostream.h> #include<math.h> class polar { float rd; float ang; public: polar() { rd=ang=0.0; } polar(float r,float a) { rd=r; ang=a; } float getrd() { return(rd); } float getang() { return(ang); } void show() { cout<<rd<<","<<ang<<endl; } }; Continue to next Slide

Experiment 12 //typecasting_class_class.cpp
class rec { float x; float y; public: rec() { x=y=0.0; } rec(float xco,float yco) { x=xco; y=yco; } rec(polar p) { float r=p.getrd(); float a=p.getang(); x=r*cos(a); y=r*sin(a); } void showrec() { cout<<x<<","<<y<<endl; } }; Continue to next Slide

Experiment 12 //typecasting_class_class.cpp

void main() { rec r1; polar p1(2.0,90.0); r1=p1; cout<<"polar co."<<endl; p1.show(); cout<<"rec co."<<endl ; r1.showrec(); }

Experiment 13 //multilevel inheritance.cpp


//Write a program to demonstrate the multilevel inheritance. #include<iostream.h> class base { private: int x; public: void inout() { cout<<"Enter X:"; cin>>x; cout<<"\nx="<<x<<endl; } }; Continue to next Slide

Experiment 13 //multilevel inheritance.cpp


class derive:public base */ { private: int y; public: /* 'DERIVE ' class is derived from 'BASE' class

void inout1() { cout<<"Enter y:"; cin>>y; cout<<"\ny="<<y<<endl; } }; Continue to next Slide

Experiment 13 //multilevel inheritance.cpp


class derive1:public derive */ { private: int z; public: /* 'DERIVE1' class is derived from 'DERIVE' class

void inout2() { cout<<"Enter z:"; cin>>z; cout<<"\nz="<<z<<endl; } }; Continue to next Slide

Experiment 13 //multilevel inheritance.cpp


void main() { derive1 obj; obj.inout(); obj.inout1(); obj.inout2(); }

//object declaration for 'DERIVE1' //member function of 'BASE" //member function of 'DERIVE" //member function of 'DERIVE1"

Experiment 14 // multiple inheritance.cpp


//write a program to demonstrate the multiple inheritance. #include<iostream.h> class base1 { private: int x; public: void inout() { cout<<"Enter X:"; cin>>x; cout<<"\nx="<<x<<endl; } }; Continue to next Slide

Experiment 14 // multiple inheritance.cpp


class base2 { private: int y; public: void inout1() { cout<<"Enter y:"; cin>>y; cout<<"\ny="<<y<<endl; } };
Continue to next Slide

Experiment 14 // multiple inheritance.cpp


class derive:public base1,public base2 /* 'DERIVE' is derived from 'BASE1' and 'BASE2*/ { private: int z; public: void inout2() { cout<<"Enter z:"; cin>>z; cout<<"\nz="<<z<<endl; } };
Continue to next Slide

Experiment 14 // multiple inheritance.cpp


void main() { derive obj; // declaring object for 'DERIVE' obj.inout(); // member of 'BASE1' obj.inout1(); // member of 'BASE2' obj.inout2(); // member of 'DERIVE' }

Experiment 15 //virtual_derivation_class.cpp
//Write a program to demonstrate the virtual derivation of a class. #include<iostream.h> class base // virtual class { protected: int data; public: base() { data=10; } };
Continue to next Slide

Experiment 15 //virtual_derivation_class.cpp
class d1:virtual public base // 'D1' derived from 'BASE' { }; class d2:virtual public base // 'D2' derived from 'BASE' { }; class c:public d1,public d2 // 'c' derived from 'D1' and 'D2' { public: int showdata() { return(data); } }; Continue to next Slide

Experiment 15 //virtual_derivation_class.cpp
void main() { c obj ; // declaring object for 'c' int k; k=obj.showdata(); cout<<"k="<<k<<endl; }

Experiment 16 //runtime polymorphism.cpp


//Write a program to demonstrate the runtime polymorphism. #include<iostream.h> class base { public: virtual void show() { cout<<"this is in class base \n"; } }; class derive:public base // 'DERIVE' is derived from 'BASE' { public: void show() { cout<<"this is in class derive \n"; } }; Continue to next Slide

Experiment 16 //runtime polymorphism.cpp


void main() { base *p; // declaring pointer to 'base' base obj1; // declaring object to 'base' derive obj2; // declaring object to 'DERIVE ' p=&obj1; // pointing to object from 'BASE ' p->show(); // showing member function from 'BASE ' p=&obj2; // pointing to object from 'DERIVE ' p->show(); // showing member function from 'DERIVE ' }

Experiment 17 //exception_handling.cpp
//Write a program to demonstrate the exception handling. #include<iostream.h> void main() { int f,s; cout<<"Enter the first no."; cin>>f; cout<<"Enter the second no.( any number to check division and 0 to show exception)"; cin>>s; try { if(s!=0) { cout<<"division="<<f/s<<endl; } else { throw(s); /* 'throw' and 'catch' are keywords for error handling*/ } } catch(int n) { cout<<"There is an exception division by "<<n<<endl; } } Continue to next Slide

Experiment 18 // function_template.cpp
// Write a program to demonstrate the use of function template. #include<iostream.h> template<class T> T max(T a,T b) // declaring member function 'max' for template 'T' { return (a>b?a:b); /* returns the greater no: if a > b then returns a else b */ } void main() { cout<<max(10,15)<<endl; cout<<max('K','s')<<endl; cout<<max(10.1,20.2)<<endl; }

//Write a program to demonstrate the use of class template. #include<iostream.h> template<class T> class A { T a,b; public: A() {

Experiment 19 //class_template.cpp

// zero parameter constructor

a=b=0; } A(T x,T y) // parameterised constructor { a=x; b=y; } void display() { cout<<a<<endl<<b<<endl; } T add() { return(a+b); } }; Continue to next Slide

Experiment 20 //class_template.cpp
void main() { A<int>a1(10,20); /* declaring object for 'A' to return int sum of two numbers*/ A<float>a2(10.5,19.7); /* declaring object for 'A' to return float sum of two numbers*/ int r1; float r2; r1=a1.add(); r2=a2.add(); a1.display(); // show int sum a2.display(); // show float sum cout<<endl<<r1<<endl<<r2; }

You might also like