C++ Questions Need Code Write a function named right Triangle() that accepts the
ID: 3545896 • Letter: C
Question
C++ Questions Need Code
Write a function named right Triangle() that accepts the lengths of two sides of a right triangle as the arguments a and b. The function should determine and return the hypotenuse, c, of the triangle. (Hint: Use Pythagoras' theorem, c2 = a2 + b2) Include the function in a working program that prompts the user for two sides and displays the 3rd side in the right triangle, by calling your function. If the user enters negative numbers print a message that this input is invalid, and exit your program. Note, this is a freebie as we did this in class! Problem 3 Years that arc evenly divisible by 400 or are evenly divisible by 4 but not by 100 are leap years. For example, because 1600 is evenly divisible by 400,1600 was a leap year. Similarly, because 1988 is evenly divisible by 4 but not by 100, it was a leap year. Using this information, write a C++ program that accepts the year as user input and prints a message indicating whether the year is a leap year or not.Explanation / Answer
// PROGRAM 2
#include<iostream>
#include<cmath>
using namespace std;
float rightTriangle(int a,int b)
{
return sqrt(a*a+b*b);
}
int main()
{
int a,b;
cout <<"Please enter two sides of triangle :";
cin >> a >> b;
cout << endl;
if(a<0 || b< 0)
cout << "Your input is invalid ";
else
cout <<"3rd side of right angled triangle given by : " << rightTriangle(a,b) << endl;
return 0;
}
// PROGRAM 3
#include<iostream>
using namespace std;
int main()
{
int year;
cout <<"Please enter year :";
cin >> year;
cout << endl;
if(year%400 ==0 || (year%100 != 0 && year%4 == 0))
cout << "Year "<< year << " is a leap year"<< endl;
else
cout << "Year "<< year << " is not a leap year"<< endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.