please, help me to solve 5,6,7 questions... Writing functions: a. Write a functi
ID: 3827010 • Letter: P
Question
please, help me to solve 5,6,7 questions...
Writing functions: a. Write a function definition for a function called mean which takes two doubles as parameters and returns their (arithmetic) mean as a double. b. Then write a function call to mean to evaluate the mean of 10 and 100 and output it to the console. Write a full program (including header, namespace, etc.) that reads from the user an integer between 10 and 99 and outputs the following based on the input: The first digit is strictly less than the second digit. The first digit is strictly greater than the second digit. The two digits are equal. Write a full program (including header, namespace, etc.) that takes as console input two strings from the user and exchanges the last character of the first string with the first character of the second string, and outputs the resulting strings to the console.Explanation / Answer
5.
#include <iostream>
using namespace std;
double mean(double a, double b)
{
return (a+b)/2;
}
int main()
{
cout << "Mean of 10 and 100 is : " << mean(10, 100) << endl;
return 0;
}
6.
#include <iostream>
using namespace std;
int main()
{
int n;
while(true)
{
cout << "Enter an integer between 10 and 99: ";
cin >> n;
if (n < 10 || n > 99)
{
cout << "Enter number between 10 and 99 only." << endl;
}
else
{
break;
}
}
int second = n %10;
int first = n/10;
if(first < second)
{
cout << "The first digit is strictly less than the second digit." << endl;
}
else if(first > second)
{
cout << "The first digit is strictly greater than the second digit." << endl;
}
else
{
cout << "Two digits are equal." << endl;
}
return 0;
}
7.
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str1;
string str2;
cout << "Enter string1: ";
cin >> str1;
cout << "Enter string2: ";
cin >> str2;
str1[str1.length()-1] = str2[0];
cout << "Changed string1: " << str1 << endl;
cout << "strings: " << str2 << endl;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.