Posts

Showing posts from May, 2023

128: Write a program that input your ATM password from the user and check if entered password is valid or not. If password is valid, display the messege: "Welcome to the Bank". Otherwise program ask to re-enter password 3 times If user enters the correct password, say: "Welcome to the bank". Otherwise display the messege: "Sorry your card is Captured".

With while loop: // Write a program that input your ATM password from the user and check // if entered password is valid or not. // If password is valid, display the messege: "Welcome to the Bank". // Otherwise program ask to re-enter password 3 times // If user enters the correct password, say: "Welcome to the bank". // Otherwise display the messege: "Sorry your card is Captured". #include < iostream > using namespace std ; int main () {     int pin = 1234 ;     int password ;     cout << " Enter your password: " ;     cin >> password ;     int i = 1 ;     while ( password != pin && i < 3 )     {         cout << " Invalid Input \n" ;         cout << " Re-enter your password: " ;         cin >> password ;         i ++ ;     }     if ( password == pin ) ...

127: Write a program that input a number from the user and displays next five number and square of those five numbers.

  // Write a program that input a number from the user and displays next five number and square of those five numbers. #include < iostream > using namespace std ; int main () {     int num ;     cout << " Enter a number: " ;     cin >> num ;     int i = num + 1 ;     while ( i <= ( num + 5 ))     {         cout << i << " and square of " << i << " is: " << i * i << endl ;         i ++ ;     }     return 0 ; }

126: Make a program in which you declare a cars function and add some cars in it and then make a user defined search function to search in the array the index and position of an element enter by a user. If it is not present in the array, show relevant output

  #include < iostream > using namespace std ; int search_array ( string x [], int y , string z ); int main () {     string cars[] = { " corvette " , " mustang " , " bugatti " , " mitsubishi " , " ferarri " , " honda " , " picanto " };     string input ;     int size = sizeof ( cars ) / sizeof ( string );     cout << " Enter the name of car you wanna search: " ;     cin >> input ;     int index = search_array ( cars , size , input );     if ( index != - 1 )     {         cout << input << " is at index: " << index << " ie at position: " << index + 1 << endl ;     }     else     {         cout << input << " is not present in the array \n" ;     }         return 0 ; } int search_array ( string x ...

125: Find prime numbers between user defined range using while loop and user defined functions

  #include < iostream > using namespace std ; int inum ( string x ); bool isprime ( int x ); int main () {     int start = inum ( " Enter the starting number: " ), end = inum ( " Enter the ending number: " );     cout << " The prime numbers between " << start << " and " << end << " are: " << endl ;     while ( start <= end )     {         if ( isprime ( start ))         {             cout << start << ' ' ;         }         start ++ ;     }     return 0 ; } int inum ( string x ) {     int y ;     cout << x ;     cin >> y ;     return y ; } bool isprime ( int x ) {     int y = 0 ;     for ( int i = 1 ; i <= x ; i ++ )     {   ...

124: Write a program in C++ to find the perfect numbers between starting and ending range using user defined functions. The perfect numbers between 1 to 500 are: 6 28 496. Make this program using user defined functions.

  // Write a program in C++ to find the perfect numbers between starting and ending range using user defined functions. // The perfect numbers between 1 to 500 are: // 6 // 28 // 496 #include < iostream > using namespace std ; int inum ( string x ); bool isPerect_number ( int x ); void Perfect_number_range ( int x , int y ); int main () {     int start = inum ( " Enter starting number of range: " ),         end = inum ( " Enter the ending number of range: " );     Perfect_number_range ( start , end );     return 0 ; } int inum ( string x ) {     int y ;     cout << x ;     cin >> y ;     return y ; } bool isPerect_number ( int x ) {     int y = 0 ;     for ( int i = 1 ; i < x ; i ++ )     {         if ( x % i == 0 )         {             ...

123: Write a program that takes three numbers as input and determines if they form an arithmetic progression. If they do, check if the common difference is positive or negative. Display appropriate messages for each case. Make this program using user defined functions.

// Write a program that takes three numbers as inputand determines if they form an arithmetic progression. // If they do, check if the common difference is positive or negative. // Display appropriate messages for each case. #include < iostream > using namespace std ; int inum ( string x ); bool isAr_Progression ( int x , int y , int z ); int common_difference ( int x , int y , int z ); bool isPositive ( int x ); int main () {     int num1 = inum ( " Enter first number: " ),         num2 = inum ( " Enter second number: " ),         num3 = inum ( " Enter third number: " );     if ( isAr_Progression ( num1 , num2 , num3 ))     {         if ( isPositive ( common_difference ( num1 , num2 , num3 )))         {             cout << num1 << " , " << num2 << " , and " << num3 << "...

122: Write a program that takes a number as input and checks if it's a multiple of 7. If it's a multiple of 7,check if it's divisible by 3. If it's divisible by 3, display a message stating both conditions are satisfied

// Write a program that takes a number as input and checks if it's a multiple of 7. // If it's a multiple of 7, check if it's divisible by 3. // If it's divisible by 3, display a message stating both conditions are satisfied #include < iostream > using namespace std ; int inum ( string x ); bool isMultipleof7 ( int x ); bool isDivby3 ( int x ); int main () {     int num = inum ( " Enter a number: " );     if ( isMultipleof7 ( num ))     {         if ( isDivby3 ( num ))         {             cout << num << " is multiple of 7 and is divisible by 3 \n" ;             cout << " Both conditions are satisfied \n" ;         }         else         {             cout << num << " is multiple of 7 but is not divisible by 3 \n"...

121: Write a program that takes two integers as input and determines if their sum is positive, negative, or zero. If it's positive, check if it's divisible by 4. If it's divisible by 4, display a message stating both conditions are satisfied.

  // Write a program that takes two integers as inputand determines if their sum is positive, negative, orzero. // If it's positive, check if it's divisible by 4. // If it'sdivisible by 4, display a message stating bothconditions are satisfied. #include < iostream > using namespace std ; int inum ( string x ); int sum ( int x , int y ); bool isZero ( int x ); bool isPositive ( int x ); bool isDiv4 ( int x ); int main () {     int num = inum ( " Enter a number: " );     if ( isZero ( num ))     {         cout << num << " is Zero \n" ;     }     else     {         if ( isPositive ( num ))         {             if ( isDiv4 ( num ))             {                 cout << num << " is Positive and divisible by 4 \n" ...

120: Write a program that takes a character as input and checks if it's an uppercase letter, lowercase letter, digit, or special character. If it's a letter, check if it's a vowel or a consonant. Display appropriate messages for each case. Make this program using user defined functions.

  // Write a program that takes a character as input andchecks if it's an uppercase letter, // lowercase letter,digit, or special character. If it's a letter, check if it'sa vowel or a consonant. // Display appropriatemessages for each case. #include < iostream > using namespace std ; template < typename T > T inum ( string x ); void char_type ( char x ); bool isVowel ( char x ); int main () {     char character = inum < char >( " Enter a character: " );     char_type ( character );     return 0 ; } template < typename T > T inum ( string x ) {     T y ;     cout << x ;     cin >> y ;     return y ; } void char_type ( char x ) {     switch ( x )     {     case ' A ' ... ' Z ' :         if ( isVowel ( x ))         {             cout << x <...

119: Write a program that takes two integers as input and determines if their product is positive, negative, or zero. If it's negative, check if it's divisible by 9. If it's divisible by 9, display a message stating both conditions are satisfied. Make this program using user defined functions.

  // Write a program that takes two integers as inputand determines if their product is positive,negative, or zero. // If it's negative, check if it'sdivisible by 9. // If it's divisible by 9, display amessage stating both conditions are satisfied #include < iostream > using namespace std ; int inum ( string x ); int product ( int x , int y ); bool isDivby9 ( int x ); int main () {     int num1 = inum ( " Enter first number: " ),         num2 = inum ( " Enter second number: " );     if ( product ( num1 , num2 ) >= 0 )     {         cout << " Product of " << num1 << " and " << num2 << " is: " << product ( num1 , num2 ) << endl ;     }     else if ( product ( num1 , num2 ) < 0 )     {         cout << " Product of " << num1 << " and " << num2 ...