PLEASE ANSWER ALL 41.Write a C++ code segment to read a character and to determi
ID: 3788870 • Letter: P
Question
PLEASE ANSWER ALL
41.Write a C++ code segment to read a character and to determine if it is a letter of the alphabet. If it is a letter of the alphabet, print it with the message, “it is a letter” otherwise, print it with the message, “it is not a letter.”
2.Write a C++ code segment to read an integer value and to determine if it is a multiple of 5. If it is a multiple of 5, print it with the message “MULTIPLE OF 5”, otherwise, print it with the message NOT MULTIPLE OF 5.”
3.Write a C++ code segment to read an integer value into variable num1and another integer value into variable num2 and to do the following: if the value in variable num1 is greater than the value in variable num2 do the following: add 1 to the value in num1 and 5 to the value in num2 and then print the result of the product of the new value in num1 and the new value in num2; otherwise, do the following: subtract 1from the value in num1 and 5 from the value in num2 and then print the result of the product of the new value in num1 and the new value in num2.
4. A department store offers a rebate of 5% if the total amount of the purchase is at least 100 and a rebate of 2% otherwise. A sale tax of 8.25 % is also imposed on the price of each purchase (after the rebate). Write a C++ code segment to read the unit price and the number of items purchased, and to output the amount of the rebate and the price (including taxes) of the purchase.
Explanation / Answer
//1. C++ code segment to read a character and to determine if it is a letter of the alphabet
#include <iostream>
using namespace std;
int main()
{
char inp;
//read char from console
cout << "Enter the letter:" ;
cin>>inp;
//check with the ascii value
if((inp>=65&&inp<=90)||(inp>=97&&inp<=122))
{
cout<<"it is a letter"<<endl;
}
else
{
cout<<"it is not a letter"<<endl;
}
return 0;
}
OUTPUT:
Enter the letter:e
it is a letter
Enter the letter:3
it is not a letter
//2. C++ code segment to read an integer value and to determine if it is a multiple of 5
#include <iostream>
using namespace std;
int main()
{
int inp;
//read char from console
cout << "Enter the integer:" ;
cin>>inp;
//check with the remainger is zero
if(inp%5==0)
{
cout<<"MULTIPLE OF 5"<<endl;
}
else
{
cout<<"NOT MULTIPLE OF 5"<<endl;
}
return 0;
}
OUTPUT:
Enter the integer:15
MULTIPLE OF 5
Enter the integer:12
NOT MULTIPLE OF 5
//3.
#include <iostream>
using namespace std;
int main()
{
int num1,num2;
//read char from console
cout << "Enter the value for num1:" ;
cin>>num1;
cout << "Enter the value for num2:" ;
cin>>num2;
//compare num1 and num2
if(num1>num2)
{
num1++;
num2+=5;
}
else
{
num1--;
num2-=5;
}
cout<<"num1 : "<<num1<<" , "<<"num2 : "<<num2<<" Product : "<<(num1*num2)<<endl;
return 0;
}
OUTPUT:
Enter the value for num1:4
Enter the value for num2:3
num1 : 5 , num2 : 8 Product : 40
Enter the value for num1:3
Enter the value for num2:4
num1 : 2 , num2 : -1 Product : -2
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.