Posts

Showing posts from June, 2023

169: Make a Credit Card Validator Program in C++ (1. Double every second digit from right to left, If doubled number is 2 digits, split them (9 x 2 = 18, 1 and 8).) (2. Add all single digits from step 1.) (3. Add all odd numbered didgits from right to left.) (4. Sum results from steps 2 & 3.) (5. If step 4 is divisible by 10, credit card # is valid.)

// Make a Credit Card Validator Program in C++ // (1. Double every second digit from right to left, If doubled number is 2 digits, //     split them (9 x 2 = 18, 1 and 8).) // (2. Add all single digits from step 1.) // (3. Add all odd numbered didgits from right to left.) // (4. Sum results from steps 2 & 3.) // (5. If step 4 is divisible by 10, credit card # is valid.) // 4032-6426-9444-5720 #include < iostream > using namespace std ; bool isValid ( string x ); int even_sum ( string x , int size ); // get sum of double of even numbers and broken values from rigth to left int odd_sum ( string x , int size );  // get sum of odd values from right to left int get_num ( string x , int i );     // gets number at position i of string int main () {     string card ;     cout << " Enter your credit card number (without spaces): " ;     cin >> card ;     if ( isValid ( card ))   ...

168: Quizz Game in C++

#include < iostream > #include < iomanip > using namespace std ; bool isValid ( int x ) // checking if the option choosed by user is valid or not {     cin . clear ();       // this is done so that program don't become a mess     fflush ( stdin );     // when user enter some string while choosing option     return ( x == 1 || x == 2 || x == 3 || x == 4 ); } int main () {     string questions[] = { " Choose the capital of France: " ,                           " Which planet is closest to The Sun: " ,                           " Which one of the following is the primary Color: " ,                           " How many legs do spider has: " };     string options[] [ 4 ] = {{ " Madrid ...

167: Write a program to calculate the electricity bill. The rates of electricity per unit are as follow: If the units consumed are equal or less than 300,then the cost is Rs. 3/- per unit. If units consumed are more than 300,then the cost is Rs. 3.5/- per unit

  // Write a program to calculate the electricity bill. The rates of electricity per unit are as follow: // If the units consumed are equal or less than 300,then the cost is Rs. 3/- per unit // If units consumed are more than 300,then the cost is Rs. 3.5/- per unit #include < iostream > using namespace std ; int main () {     cout << " Muhammad Umar Chaudhry " << endl ;     cout << " SU92-BSCSM-S23-007 " << endl ;     cout << " Question # 30 " << endl           << endl ;     int units ;     cout << " Enter the units consumed: " ;     cin >> units ;     if ( units > 300 )     {         cout << " Your electricity bill is: " << units * 3.5 << endl ;     }     else if ( units <= 300 && units >= 0 )     { ...

166: Write a program which will calculate the salary of an employ and detect 5% tax if its more than 50000

  // Write a program which will calculate the salary of an employ and detect 5% tax if its more // than 50000 #include < iostream > using namespace std ; int main () {     cout << " Muhammad Umar Chaudhry " << endl ;     cout << " SU92-BSCSM-S23-007 " << endl ;     cout << " Question # 29 " << endl << endl ;     int salary ;     cout << " Enter your salary: Rs. " ;     cin >> salary ;     if ( salary > 50000 )     {         salary = salary - ( salary * 0.05 );         cout << " Your salary after tax deduction is: Rs. " << salary << endl ;     }     else     {         cout << " Your salary is: Rs. " << salary << " no tax deduction " << endl ;     }     ...

165: Write a menu based program for opening two formulas: // (a+b)^2 // (a-b)^2

  // Write a menu based program for opening two formulas: // (a+b)^2 // (a-b)^2 #include < iostream > using namespace std ; int main () {     cout << " Muhammad Umar Chaudhry " << endl ;     cout << " SU92-BSCSM-S23-007 " << endl ;     cout << " Question # 28 " << endl           << endl ;     int option , a , b ;     do     {         cout << " For formula: (a+b)^2   Press 1 " << endl ;         cout << " For formula: (a-b)^2   Press 2 " << endl ;         cout << " \n Enter option: " ;         cin >> option ;         if ( option == 1 || option == 2 )         {             break ;         }     ...

164: Write a program to read any digit from 0 to 9, display in the word.

  // Write a program to read any digit from 0 to 9, display in the word. #include < iostream > using namespace std ; int main () {     cout << " Muhammad Umar Chaudhry " << endl ;     cout << " SU92-BSCSM-S23-007 " << endl ;     cout << " Question # 26 " << endl           << endl ;     int num ;     cout << " Enter a number: " ;     cin >> num ;     switch ( num )     {     case 0 :         cout << " Zero " << endl ;         break ;     case 1 :         cout << " One " << endl ;         break ;     case 2 :         cout << " Two " << endl ;         break ;     case 3 :       ...

163: Write a C++ program to check whether a triangle is Equilateral, Isosceles or Scalene.

  // Write a C++ program to check whether a triangle is Equilateral, Isosceles or Scalene. #include < iostream > using namespace std ; int main () {     cout << " Muhammad Umar Chaudhry " << endl ;     cout << " SU92-BSCSM-S23-007 " << endl ;     cout << " Question # 24 " << endl           << endl ;     int side1 , side2 , side3 ;     cout << " Enter the length of side 1: " ;     cin >> side1 ;     cout << " Enter the length of side 2: " ;     cin >> side2 ;     cout << " Enter the length of side 3: " ;     cin >> side3 ;     if ( side1 == side2 && side1 == side3 )     {         cout << " The triangle is Equilateral \n " ;     }     else if ( side1 != side2 && sid...

162: Write a C++ program to check whether a triangle can be formed by the given value for the angles.

  // Write a C++ program to check whether a triangle can be formed by the given value for the // angles. #include < iostream > using namespace std ; int main () {     cout << " Muhammad Umar Chaudhry " << endl ;     cout << " SU92-BSCSM-S23-007 " << endl ;     cout << " Question # 25 " << endl << endl ;     int a , b , c ;     cout << " Enter the angle 1: " ;     cin >> a ;     cout << " Enter the angle 2: " ;     cin >> b ;     cout << " Enter the angle 3: " ;     cin >> c ;     if ( a + b + c == 180 )     {         cout << " This triangle can be formed \n " ;     }     else     {         cout << " This triangle cannot be formed \n " ;     }     ret...

161: Write a program to read temperature in centigrade and display a suitable message according to temperature state below : // Temp < 0 then Freezing weather // Temp 0-10 then Very Cold weather // Temp 10-20 then Cold weather // Temp 20-30 then Normal in Temp // Temp 30-40 then Its Hot // Temp >=40 then Its Very Hot

  // Write a program to read temperature in centigrade and display a suitable message according // to temperature state below : // Temp < 0 then Freezing weather // Temp 0-10 then Very Cold weather // Temp 10-20 then Cold weather // Temp 20-30 then Normal in Temp // Temp 30-40 then Its Hot // Temp >=40 then Its Very Hot #include < iostream > using namespace std ; int main () {     cout << " Muhammad Umar Chaudhry " << endl ;     cout << " SU92-BSCSM-S23-007 " << endl ;     cout << " Question # 23 " << endl           << endl ;     float temp ;     cout << " Enter the temperature in degree centigrade: " ;     cin >> temp ;     if ( temp < 0 )     {         cout << " Freezing weather " << endl ;     }     else if ( temp >= 0 &...