Posts

118: Write a program that takes three integers as input and determines if they can form the sides of a triangle. If they can, check if it's an equilateral, isosceles, or scalene triangle. Display appropriate messages for each case. Make this program using user defined functions.

  // Write a program that takes three integers as input and determines // if they can form the sides of a triangle. // If they can, check if it's an equilateral,isosceles, or scalene triangle. // Display appropriatemessages for each case. #include < iostream > using namespace std ; float inum ( string x ); bool isTriangle ( float x , float y , float z ); void triangle_type ( int x , int y , int z ); int main () {     float side1 = inum ( " Enter the length of first side: " ),           side2 = inum ( " Enter the length of second side: " ),           side3 = inum ( " Enter the length of third side: " );     if ( isTriangle ( side1 , side2 , side3 ))     {         cout << " This triangle is Possible \n" ;         triangle_type ( side1 , side2 , side3 );     }     else     {       ...

117: Write a program that takes a number as input and checks if it's a perfect square. If it's a perfect square, check if it's divisible by 3. If it's divisible by 3, display a message stating both conditions are satisfied. Make this program using user defined functions

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

116: Write a program that takes three numbers as input and determines the largest number among them. If two or more numbers are equal, display anappropriate message

  // Write a program that takes three numbers as input and determines the largest number among them. // If two or more numbers are equal, display anappropriate message #include < iostream > using namespace std ; int inum ( string x ); bool unequal ( int x , int y , int z ); bool anyequal ( int x , int y , int z ); int larger ( int x , int y , int z ); void equal ( int x , int y , int z ); int main () {     int num1 = inum ( " Enter first number: " ), num2 = inum ( " Enter second number: " ),         num3 = inum ( " Enter third number: " );     if ( unequal ( num1 , num2 , num3 ))     {         cout << " The greatest number among these is: " << larger ( num1 , num2 , num3 ) << endl ;         if ( anyequal ( num1 , num2 , num3 ))         {             equal ( num1 , num2 , ...

115: Write a program that takes a year as input and checks if it's a leap year If it's a leap year, check if it's divisible by 100. If it is, further check if it's divisible by 400. Display appropriate messages for each case. Make this program using user defined functions.

  // Write a program that takes a year as input andchecks if it's a leap year // If it's a leap year, check if it's divisible by 100. If it is, further check if it'sdivisible by 400. // Display appropriate messages foreach case. #include < iostream > using namespace std ; int inum ( string x ); bool isLeap ( int x ); int main () {     int year = inum ( " Enter a year: " );     if ( isLeap ( year ))     {         cout << year << " is a leap year \n" ;     }     else     {         cout << year << " is not a leap year \n" ;     }         return 0 ; } int inum ( string x ) {     int y ;     cout << x ;     cin >> y ;     return y ; } bool isLeap ( int x ) {     return (( x % 4 == 0 && x % 100 != 0 ) || ( x % 400 == 0 ...

114: Write a program that takes two integers as input and determines if the first number is positive, negative, or zero. If it's positive, check if it's even or odd. If it's negative, check if it's divisible by 3. Display appropriate messages for each case. Make this program using user defined functions

// Write a program that takes two integers as inputand determines if the first number is positive,negative, or zero. // If it's positive, check if it's even orodd. If it's negative, check if it's divisible by 3. // Display appropriate messages for each case. #include < iostream > using namespace std ; int inum ( string x ); bool isPositive ( int x ); bool isEven ( int x ); bool isDivby3 ( int x ); int main () {     int num1 = inum ( " Enter first number: " ), num2 = inum ( " Enter second number: " );     if ( isPositive ( num1 ))     {         if ( isEven ( num1 ))         {             cout << num1 << " is positive even number \n" ;         }         else         {             cout << num1 << " is positive odd number \n" ;       ...

113: ***(Syntax)*** Arrays

Arrays Array is a data structure that can hold multiple values . These values are accessed by index numbers . " Array is like a variable that can hold multiple values ",  actually array is much more complicated than this but this is a good way of thinking. 1. Making a variable array:                To make a variable array, add   []  after the variable and then close the values in a set of  {}  and inside  {}   separate each value by  ,  . Now  car  is now an array that can hold multiple values ie multiple cars. #include < iostream > using namespace std ; int main () {     string car[] = { " Corvette " , " Ferrari " , " Honda " };         return 0 ; } 2. Output:                Now if you output  car  variable, it will show its memory address where all the values are stored. #include ...