Skip to main content

Exception Handling

/*
Problem Statement:
Create a class named Television that has data members to hold the model number and the screen size
in inches,and the price.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.
*/


#include
#include


class television
{
int model;
float size;
float price;
public:
television();
friend void operator << (ostream &o,television &t);
friend void operator >> (istream &i,television &t);

};

television::television()
{
model=0;
size=0;
price=0;
}

void operator << (ostream &o,television &t)
{
o<<"\nModel:\t"< o<<"\nSize:\t"< o<<"\nPrice:\t"<}


void operator >> (istream &i,television &t)
{
try
{
cout<<"Enter Model No.:\t";
i>>t.model;
if(t.model>=10000)
throw(1);
cout<<"Enter size:\t";
i>>t.size;
if(t.size<12>17)
throw(1);
cout<<"Enter Price:\t";
i>>t.price;
if(t.price>5000)
throw(1);
}
catch(int i)
{
cout<<"\nInvalid Data";
t.model=0;
t.size=0;
t.price=0;
}
}


void main()
{
television t1;
int ch;
do
{
cout<<"\n\n\tMENU\n";
cout<<"1)Accept Data\n2)Display\n3.Exit\n\n";
cout<<"Enter your choice:\t";
cin>>ch;
switch(ch)
{
case 1:cin>>t1;
break;
case 2:cout< break;
case 3:exit(0);
}
}while(1);

}





Popular posts from this blog

Selenium + Python + UnexpectedAlertPresentException: Dealing with annoying alerts

Handling  UnexpectedAlertPresentException   Alerts who hates them? I Do!  Who doesn't hate an annoying alert causing your tests / scraping job to fail? I must say they are pretty much on point on the Unexpected part!  Fortunately, there are easy ways to mitigate the issue. 1. Disable alerts completely: driver . execute_script( 'window.alert = function(){};' ); execute this script just before where you anticipate the alert and you're golden. 2. You want to see the alert text but not disturb the execution flow. driver . execute_script( 'window.alert = console.info;' ); Now the alerts have been redirected to the console and you don't have to worry about them. (Unless you have to - then you'd have to monitor the console) 3. You know exactly when it comes and want to accept the alert and move on. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 from selenium import webdriver from selenium.webdriver.s

Python Program for Soundex Algorithm

This is a python implementation for Soundex Algorithm. This Program builds a JSON document as a dictionary and is kept on building at every execution. Its constantly appended and referenced while the program  is executed. Program: from re import sub def remove_symbols (input_string): #Convert the characters to lower case and then use #Regular expressions to remove non a-z chars return sub( '[^A-Z]+' , '' , input_string) def clean (input_string): #Convert the characters to lower case and then use #Regular expressions to remove non a-z chars return sub( '[^a-z]+' , '' , input_string . lower()) word = "Input" def soundex (word): #Step 1: Capitalize all letters in the word and drop all punctuation marks. word = remove_symbols(word . upper()) #Step 2: Retain the first letter of the word. first_letter = word[ 0 ] word = word[ 1 :] #Step 3 & 4: Change ( 'A&#

How to convert a Helium Wallet Address to Solana Wallet address?

Helium went to Solana Blockchain, on April 18, 2023. Helium addresses are not available on the Solana blockchain as addresses on the Solana blockchain are base-58 encoded. Here is a quick snippet on how to translate an existing Helium wallet address to a Solana wallet address using Python. You will need the base58 module for this, get it here: pip install base58 Code Chunk: def convert_hnt_wallet_addr_to_sol ( helium_wallet_address ) : return base58. b58encode ( base58. b58decode ( hnt_wallet_address ) [ 2 :- 4 ] ) . decode ( ) Using this convert your Helium wallet address to a Solana address! You can further explore our blog for interesting reads  OR   - you can contact us to learn a bit more over a FREE personal Skype coaching session. Just click on "Leave a message" and reach out to us. We get a lot of volume these days so FREE Sessions won't be here for a long time, Grab this opportunity while you can!