• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
projectsgeek

ProjectsGeek

Download Mini projects with Source Code, Java projects with Source Codes

  • Home
  • Java Projects
  • C++ Projects
  • VB Projects
  • PHP projects
  • .Net Projects
  • NodeJs Projects
  • Android Projects
    • Project Ideas
      • Final Year Project Ideas
      • JSP Projects
  • Assignment Codes
    • Fundamentals of Programming Language
    • Software Design Laboratory
    • Data Structure and Files Lab
    • Computer Graphics Lab
    • Object Oriented Programming Lab
    • Assembly Codes
  • School Projects
  • Forum

Exception Handling in C++ Language

April 6, 2011 by ProjectsGeek Leave a Comment

Exception Handling in C++ Language

Create a class named Television that has data members to hold the model number and the screen size in inches,and the price for Exception Handling in C++ program.Member functions include overloaded insertion and extraction operators.If more than four digits are entered for the model,if the screen size is smaller than 12 or greater than 70 inches, or if the price is negative or over $5000 then throw an integer.

Write a main() function that instantiates a television object,allows user to enter data and displays the data members .If an exception is caught ,replace all the data member values with zero values .

Exception Handling in C++ Code

#include  
 #include  
 void test(int,int,int);  
 class television  
 {  
   public:  
   int mod_no,price,size;  
   void operator<<(telivision a)  
   {  
     cout<<"\n\t## INPUT ##";  
     cout<<"\n\tENTER THE MODEL NO.:";  
     cin>>mod_no;  
     cout<<"\n\tENTER THE SIZE:";  
     cin>>size;  
     cout<<"\n\tENTER THE PRICE:";  
     cin>>price;  
     test(mod_no,price,size);  
     getch();  
   }  
   void operator>>(television a)  
   {  
     cout<<"\n\t## DISPLAY ##)";  
     cout<<"\nMODEL NO.:"<<mod_no<<"\nsize:"<<size<<"\nprice:"<<price; <br="">     getch();  
   }  
 };  
 void test(int mod_no,int price,int size)  
 {  
   if(mod_no>=10000)  
     throw(1);  
   if(price>5000)  
     throw(2);  
   if(price<0)  
     throw(3);  
   if(size<12)  
     throw(4);  
   if(size>70)  
     throw(5);  
 }  
 void main()  
 {  
   int ch,i;  
   television n,o;  
   do  
   {  
     cout<<"\n\t##### MAIN MENU #####";  
     cout<<"\n\t1.INPUT";  
     cout<<"\n\t2.DISPLAY";  
     cout<<"\n\t3.EXIT";  
     cout<<"\n\tENTER UR CHOICE:";  
     cin>>ch;  
     switch(ch)  
     {  
       case 1:  
         try  
         {  
           n<<o; <br="">         }  
         catch(int i)  
         {  
           if(i==1)  
             cout<<"\nMODEL NO IS NOT CORRECT";  
           else if(i==2)  
             cout<<"\nPRICE IS NOT CORRECT";  
           else if(i==3)  
             cout<<"\nPRICE IS NEGATIVE";  
           else if(i==4)  
             cout<<"\nSIZE IS VERY SMALL";  
           else if(i==5)  
             cout<<"\nSIZE IS VERY LARGE";  
           n.mod_no=0;  
           n.price=0;  
           n.size=0;  
         }  
         getch();  
         break;  
       case 2: n>>o;  
         getch();  
         break;  
       case 3: break;  
     }  
   }while(ch!=3);  
 }

 

Other Projects to Try:

  1. How to Implement Hash Table using C language
  2. Hash table code in C Language
  3. Exception Handling In java
  4. File Handling and IO Handling in Java Programming
  5. Matrix Operations in C Language

Filed Under: C Assignments, Computer Graphics Tagged With: Computer Graphics

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Tags

.Net Projects Download Android Project Ideas Android Projects Angular 2 Assembly Codes C # Projects C & C++ Projects C++ Projects Class Diagrams Computer Graphics Database Project Data Mining Projects DataScience Projects Datastructure Assignments Download Visual Basic Projects Electronics project Hadoop Projects Installation Guides Internet of Things Project IOS Projects Java Java Interview Questions Java Projects JavaScript JavaScript Projects java tutorial JSON JSP Projects Mechanical Projects Mongodb Networking Projects Node JS Projects OS Problems php Projects Placement Papers Project Ideas Python Projects seminar and presentation Struts

Search this Website


Footer

Download Java Project
Download Visual Basic Projects
Download .Net Projects
Download VB Projects
Download C++ Projects
Download NodeJs Projects
Download School Projects
Download School Projects
Ask Questions - Forum
Latest Projects Ideas
Assembly Codes
Datastructure Assignments
Computer Graphics Lab
Operating system Lab
australia-and-India-flag
  • Home
  • About me
  • Contact Form
  • Submit Your Work
  • Site Map
  • Privacy Policy