Lab 14 Assignment
Problem 1. transfer uppercase to lowercase for the input sentence.
#include<iostream>
//include header file for standard function tolower(x)
usingnamespace std;
int main()
{
char ch;
//prompt user to input a character and save it to variable ch
// if ch is uppercase(between 'A' and 'Z'), convert ch to lowercase
//printout ch
return 0;
}
(1)Complete the upper program, and compile and run successfully.
(2)Modify your program and transfer lowercase to uppercase.
Problem 2. Using some math standard functions.
(1)Write a program with the following requirements:
Prompts the user to enter a double value. You can assume user’s input is a number.
Using thestandard (predefined) math functions ceil, floor, and fabsin the cmathheaderfile to findand display the following values:
_ The smallest whole number greater than or equal to the number
_ The greatest whole number less than or equal to the number
_ The absolute value of the number
The basic structure is:
#include<iostream>
//include cmath header file for functions ceil, floor, and fabs
usingnamespace std;
int main()
{
//delcare a double type variable named num
//delcare three double type variables named x, y, z
//prompts the user to enter a double value
//read in the value and save it to num
//Use the proper function to get the smallest whole number greater than or equal to the input number and save the result to x
//Use the proper functionto get the greatest whole number less than or equal to the number and save the result to y
//Use the proper function to get the absolute value of the number and save the result to z
//printout these three results, for example:
//printout "The smallest whole number greater than or equal to your input is ..."
//printout "the greatest whole number less than or equal to your input is ..."
//printout "the absolute value of the number is ..."
return 0;
}
(2)Modify your program toadd an if statement to judge the user’s input is valid. (Hint: you can use the structure:
if(!cin)
{
cout<”Input Error!”;
exit(0);
}
Or
if(cin)
Statements;
to judge if there is an input failure, if there is a failure, printout the error to the user)
(3)Modify your program to add a while loop to allow the user to enter multiple values until the user chooses to quit theprogram.For example, you can set a sentinel to be -999, and tell user that if he wants to end the program, he can input -999. The basic structure is:
const int SENTINEL=-999
….
int main()
{
……
while (num!=SENTINEL)
{
……
}
}