First, convert feet to inches. The ' denotes foot measurement while the " denotes inches. Since there are 12 inches in a foot,
5'10" = (5*12) + 10 = 70 inches
6'8" = (6*12) + 8 = 80 inches
a.) The lower limit is 70 inches while the upper limit is 80 inches.
b.) First, divide 78 inches by 12. That would 6.5 or 6 and a half feet. Since half foot is 6 inches, the length of the couch is 6'-6"
c.) Since the couch is between the limits, yes it would fit the space.
Answer:
#include <iostream>
#include <array>
using namespace std;
bool isPalindrome(string str)
{
int length = str.length();
for (int i = 0; i < length / 2; i++)
if (toupper(str[i]) != toupper(str[length - 1 - i]))
return false;
return true;
}
int main()
{
array<string, 6> tests = { "madam", "abba", "22", "67876", "444244", "trymEuemYRT" };
for (auto test : tests) {
cout << test << " is " << (isPalindrome(test) ? "" : "NOT ") << "a palindrome.\n";
}
}
Explanation:
The toupper() addition forces characters to uppercase, thereby making the comparison case insensitive.
Answer:
Here's some really bad code that works:
public static double average(int a, int b, int c, int d, int e)
{
return (((double)a + b + c + d + e) / 5);
}
Answer:
21
Explanation:
The values of c that make it into the loop are 1, 4, 7.
The values that are added to sum are 3 higher, i.e., 4,7 and 10.
The sum of those is 21.
p.s. why did you not run the program yourself?
Answer:
#include <iostream>
using namespace std;
class Digits
{
public:
int num;
int read() //method to read num from user
{
cout<<"Enter number(>0)\n";
cin>>num;
return num;
}
int digit_count(int num) //method to count number of digits of num
{
int count=0;
while(num>0) //loop till num>0
{
num/=10;
count++; //counter which counts number of digits
}
return count;
}
int countDigits(int num) //method to return remainder
{
int c=digit_count(num); //calls method inside method
return num%c;
}
};
int main()
{
Digits d; //object of class Digits is created
int number=d.read(); //num is read from user
cout<<"\nRemainder is : "<<d.countDigits(number); //used to find remainder
return 0;
}
Output :
Enter number(>0)
343
Remainder is : 1
Explanation:
As program is missing to find errors , a logically write program is written to find the remainder when a number is divided by its number of digits. A class Digits is constructed which has public variable num and methods read(), digit_count(), countDigits().
- read() - This method reads value of num from the user and return num.
- digit_count() - This method takes a integer as parameter and counts the number of digits of a number passed as argument. while loop is used to increement the counter until num<0. This returns the value of count.
- countDigits() - This method takes a integer as a parameter and returns remainder when the argument is divided by number of digits of argument. Number of digits is calculated by using method digit_count().
At last in main method , object of Digits class is created and its methods are used to find the output.