Write a Python program to calculate area of an equilateral triangle.
Write a Python program to calculate area of an equilateral triangle. SOLUTION…. # Program to calculate area of an equilateral triangle import math # for square root function # Input side = float(input(“Enter the side of the equilateral triangle: “)) # Formula: (√3 / 4) × side² area = (math.sqrt(3) / 4) * (side ** […]
Write a Python program to enter two angles of a triangle and find the third angle.
Write a Python program to enter two angles of a triangle and find the third angle. SOLUTION…. # Program to find third angle of a triangle # Input angle1 = float(input(“Enter first angle of triangle: “)) angle2 = float(input(“Enter second angle of triangle: “)) # Formula: Sum of angles of a triangle = 180 angle3 […]
Write a Python program to enter two numbers and perform all arithmetic operations.
Write a Python program to enter two numbers and perform all arithmetic operations. SOLUTION…. # Program to perform all arithmetic operations on two numbers # Input a = float(input(“Enter first number: “)) b = float(input(“Enter second number: “)) # Arithmetic operations stored in different variables addition = a + b subtraction = a – b […]
Write a Python program to enter length and breadth of a rectangle and find its Perimeter and Area .
Write a Python program to enter length and breadth of a rectangle and find its Perimeter and Area . SOLUTION…. # Program to calculate Area and Perimeter of a Rectangle # Input values length = float(input(“Enter length of rectangle: “)) breadth = float(input(“Enter breadth of rectangle: “)) # Calculations area = length * breadth perimeter […]
Write a Python program to enter P, T, R and calculate Simple Interest.
Write a Python program to enter P, T, R and calculate Simple Interest. SOLUTION…. # Input values P = float(input(“Enter Principal amount (P): “)) T = float(input(“Enter Time (T in years): “)) R = float(input(“Enter Rate of Interest (R): “)) # Formula for Simple Interest SI = (P * T * R) / 100 # […]
Write a Python program to enter temperature in Celsius and convert it into Fahrenheit and Vice Versa.
Write a Python program to enter temperature in Celsius and convert it into Fahrenheit and Vice Versa. SOLUTION…. # Fahrenheit to Celsius fahrenheit = float(input(“Enter temperature in Fahrenheit: “)) celsius = (fahrenheit – 32) * 5/9 print(f”{fahrenheit}°F = {celsius:.2f}°C”) # Celsius to Fahrenheit celsius = float(input(“nEnter temperature in Celsius: “)) fahrenheit = (celsius * 9/5) […]
Write a program to maintain a telephone directory. Use class and object with methods add() and show() to manage entries.
Write a program to maintain a telephone directory. Use class and object with methods add() and show() to manage entries. SOLUTION…. #include <iostream> #include <string> using namespace std; class Directory { private: string name[100]; string phone[100]; int count; public: Directory() { count = 0; } // Method to add entry void add() { if (count […]
Create a program using `enum` to represent days of the week. Accept a number from the user and display the corresponding day using a `switch` statement.
Create a program using `enum` to represent days of the week. Accept a number from the user and display the corresponding day using a `switch` statement. SOLUTION…. C++ Enum Days Example #include <iostream> using namespace std; int main() { // Enum declaration enum Days { Sunday = 1, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday }; […]
Accept two strings using character arrays. Use string functions `strcpy()`, `strcat()`, `strcmp()`, and `strlen()` to perform various operations.
Accept two strings using character arrays. Use string functions `strcpy()`, `strcat()`, `strcmp()`, and `strlen()` to perform various operations. SOLUTION…. C++ String Functions Example #include <iostream> #include <cstring> // for string functions using namespace std; int main() { char str1[100], str2[100], str3[100]; // Input two strings cout << “Enter first string: “; cin.getline(str1, 100); cout << […]
Create a base class `Animal` with function `speak()`. Derive classes `Dog` and `Cat`, override `speak()` function to display “Bark” and “Meow” respectively.
Create a base class `Animal` with function `speak()`. Derive classes `Dog` and `Cat`, override `speak()` function to display “Bark” and “Meow” respectively. SOLUTION…. C++ Virtual Function Example #include <iostream> using namespace std; // Base class class Animal { public: virtual void speak() { // Virtual function cout << “Animal sound” << endl; } }; // […]
