Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Given that the following has already been performed in the code: int x, y, z; ch

ID: 3667832 • Letter: G

Question

Given that the following has already been performed in the code: int x, y, z; char ch; cin >> x >> y >> z; cin >> ch; Write code segments that will solve the following:

1. Write out a message that states whether x divides evenly by 7.

2. Write out the largest of the input values x, y, and z with a message saying “The largest is “ followed by the actual value.

3. If the value of ch is alphabetical (you can use isalpha( )), write out whether ch is a vowel (a,e,i,o,u), the letter ‘y’ which is sometimes a vowel, or a consonant. Consider both upper and lower case in your answer.

4. Use a switch with ch to determine if the input value is a relational character (just check for ‘<’ or ‘>’), a digit, or something else. Write out an appropriate message.

Explanation / Answer

/**C++ program prompts user to enter x, y and z and ch values and
tests the four test cases in the program. */
#include<iostream>
using namespace std;
int main()
{

   //declaration of x,y and z
   int x, y, z; char ch;
   cout<<"Enter x , y and z values : ";
   cin >> x >> y >> z;
   cout<<"Enter a character value :";
   cin >> ch;


   //1.code to test if the x is divisible by 7
   if(x%7==0)
       cout<<x<<"Divisible by"<<7<<endl;
   else
       cout<<x<<"not divisible by"<<7<<endl;


   //2.code find the largest number of three values

   if(x>y && x>z)
   {
       cout<<"The largest is "<<x<<endl;
   }
   else if(y>x && y>z)
   {
       cout<<"The largest is "<<y<<endl;
   }
   else
       cout<<"The largest is "<<z<<endl;


   //3.code to check if ch is alphatical and test if ch is vowel or consonant
   if(isalpha(ch))
   {
       if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u' )
           cout<<ch<<" is vowel"<<endl;
       else
           cout<<ch<<" is consonant"<<endl;
   }

   //4. switch with ch to determine if the input value is a relational character
   //(just check for ‘<’ or ‘>’), a digit, or something else. Write out an appropriate message.
   switch(ch)
   {
   case '<':
       cout<<ch<<" is less than operator"<<endl;
       break;
   case '>':
       cout<<ch<<" is greater than operator"<<endl;
       break;
   case '1':
   case '2':
   case '3':
   case '4':
   case '5':
   case '6':
   case '7':
   case '8':
   case '9':
   case '0':
       cout<<ch<<" a digit"<<endl;
       break;

   default:
       cout<<ch<<" is not relational or digit ."<<endl;
       break;
   }
   system("pause");
   return 0;

}

Sample Output:

Enter x , y and z values : 7
14
21
Enter a character value :>
7 Divisible by7
The largest is 21
> is greater than operator

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote