Bartleby Sitemap - Textbook Solutions

All Textbook Solutions for Computer Science: A Structured Programming Approach Using C, Third Edition

Computer software is divided into two broad categories: system software and operational software. a. True b. False2PS3PSThe programmer design tool used to design the whole program is the flowchart. a. True b. FalseBlackbox testing gets its name from the concept that the program is being tested without knowing how it works. a. True b. False6PS7PSWhich of the following is not a computer language? a. Assembly/symbolic language b. Binary language c. High-level languages d. Machine language e. Natural languageThe computer language that most closely resembles machine language is a. Assembly/symbolic b. COBOL c. FORTRAN d. High-level10PS11PS12PSThe is a program design tool that is a visual representation of the logic in a function within a program. a. Flowchart b. Program map c. Pseudocode d. Structure chart e. Waterfall model14PSDescribe the two major components of a computer system.Computer hardware is made up of five parts. List and describe them.17PSDescribe the two major categories of software.19PS20PS21PS22PS23PS24PS25PS26PS27PSDescribe the three tools that a programmer may use to develop a program solution.29PS30PS31PSWrite pseudocode for calcLivingAreas, Figure 1-12, “Structure Chart for Calculating Square Footage.�33PS34PSThe purpose of a header file, such as stdio.h, is to store a program's source code. a. True b. False2PSThe C standard function that receives data from the keyboard is printf. a. True b. FalseWhich of the following statements about the structure of a C program is false? a. A C program starts with a global declaration section. b. Declaration sections contain instructions to the computer. c. Every program must have at least one function. d. One and only one function may be named main. e. Within each function there is a local declaration section.Which of the following statements about block comments is false? a. Comments are internal documentation for programmers. b. Comments are used by the preprocessor to help format the program. c. Comments begin with a /* token. d. Comments cannot be nested. e. Comments end with a */ token.6PSWhich of the following is not a data type? a.charb.floatc.intd.logicale.voidThe code that establishes the original value for a variable is known as a (n): a. assignment b. constant c. initializer d. originator e. value9PS10PSTo print data left justified, you would use a in the conversion specification. a. flag b. precision c. size d. width e. width and precision12PSOne of the most common errors for new programmers is forgetting to use the address operator for variables in a scanf statement. What is the address operator? a. The address modifier in the conversion specification b. The ampersand $ c. The caret d. The percent e. The pound signWhich of the following is not a character constant in C? a.'C'b.'bb'c.Cd.'?'e.''Which of the following is not an integer constant in C? a.320b.+45c.31.80d.1456e.2,456Which of the following is not a floating-point constant in C? a.45.6b.14.05c.ad.pie.4017PSWhich of the following is not a valid identifier in C? a.A3b.4Ac.ifd.IFe.taxrateWhat is the type of each of the following constants? a.7b.3c.3.14159d.'2'e.5.1What is the type of each of the following constants? a.Hellob.15Lc.8.5Ld.8.5fe.'a'Which of the following identifiers are valid and which are invalid? Explain your answer. a. num b. num2 c. 2dNum d. 2d_num e. num#2Which of the following identifiers are valid and which are invalid? Explain your answer. a.num2b.num2c.num2d.num2e.num2What is output from the following program fragment? To show your out-put, draw a grid of at least 8 lines with at least 15 characters per line. //LocalDeclarationsintx=10;charw='Y';floatz=5.1234;//StatementsprintfnFirstnExamplen:;printf5dn,wiscn,x,w;printfnzis8.2fn,z;24PSFind any errors in the following program. #includestdio.hintmainvoidprintHelloWorld;return0;Find any errors in the following program. includestdiointmainvoidprintf'Wearetolearncorrect';printf'Clanguagehere';return0;//main27PS28PS29PSCode the variable declarations for each of the following: a. a character variable named option b. an integer variable, sum, initialized to 0 c. a floating-point variable, product, initialized to 1Code the variable declarations for each of the following: a. a short integer variable named code b. a constant named salesTax initialized to .0825 c. a floating-point named sum of size double initialized to 0Write a statement to print the following line. Assume the total value is contained in a variable named cost. Thesalestotalis:$172.53Write a program that uses four print statements to print the pattern of asterisks shown below. ************************Write a program that uses four print statements to print the pattern of asterisks shown below. **********Write a program that uses defined constants for the vowels in the alphabet and memory constants for the even decimal digits (0, 2, 4, 6, 8). It then prints the following three lines using literal constants for the odd digits. aeiou024681357936PS37PSWrite a program that prompts the user to enter an integer and then prints the integer first as a character, then as a decimal, and finally as a float. Use separate print statements. A sample run is shown below. Thenumberasacharacter:KThenumberasadecimal:75Thenumberasafloat:0.000000Write a C program using printf statements to print the three first letters of your first name in big blocks. This program does not read anything from the keyboard. Each letter is formed using seven rows and five columns using the letter itself. For example, the letter B is formed using 17 B's, as shown below as part of the initials BEF BBBEEEEEFFFFFBBEFBBEFBBBEEEFFFBBEFBBEFBBBEEEEEF This is just an example. Your program must print the first three letters of your first name. Design your printf statements carefully to create enough blank lines at the beginning and end to make your initials readable. Use comments in your program to enhance readability as shown in this chapter.Write a program that reads a character, an integer, and a floating-point number. It then prints the character, first using a character format specification c and then using an integer specification d . After printing the character, it prints the integer and floating-point numbers on separate lines. Be sure to provide complete instructions (prompts) for the user.Write a program that prompts the user to enter three numbers and then prints them vertically (each on one line), first forward and then reversed (the last one first), as shown in the following design. Pleaseenterthreenumbers:153572Yournumbersforward:153572Yournumbersreversed:723515Write a program that reads 10 integers and prints the first and the last on one line, the second and the ninth on the next line, the third and the seventh on the next line, and so forth. Sample input and the results are shown below. Pleaseenter10numbers:10312732465687189Yournumbersare:10931182877362465Write a program that reads nine integers and prints them three in a line separated by commas as shown below. Input:1031273246568718Output10,31,273,24,656,87,18A unary expression consists of only one operand with no operator. a. True b. FalseThe left operand in an assignment expression must be a single variable. a. True b. FalseAssociativity is used to determine which of several different expressions is evaluated first. a. True b. FalseSide effect is an action that results from the evaluation of an expression. a. True b. False5PS6PS7PS8PS9PS10PSWhich of the following statements about mixed expressions is false? a. A cast cannot be used to change an assigned value. b. An explicit cast can be used to change the expression type. c. An explicit cast on a variable changes its type in memory. d. An implicit cast is generated by the compiler automatically when necessary e. Constant casting is done by the compiler automatically.Which of the following statements about compound statements is false? a. A compound statement is also known as a block. b. A compound statement is enclosed in a set of braces. c. A compound statement must be terminated by a semicolon. d. The declaration and definition section in a compound statement is optional. e. The statement section in a compound statement is optional.13PS14PSWhich of the following is not a binary expression? a.3*5b.x+=6c.y=5+2d.2e.yz16PSIf originally x=4, what is the value of x after the evaluation of the following expression? a.x=2b.x+=4c.x+=x+3d.x*=2e.x/=x+218PS19PSWhat is the value of each of the following expressions? a.6.2+5.1*3.2b.2.0+3.0/1.2c.4.0*3.0+2.0/6.0d.6.0/2.0+4.0*1.2e.2.7+3.25.3*1.1Given the following definitions, which of the following statements are valid assignments? #defineNUM1010intx;inty=15;a.x=5;b.y=5;c.x=y=50;d.x=50=y;e.x=x+1;f.y=1+NUM10;g.5=y;If originally x=2,y=3,andz=2, what is the value of each of the following expressions? a.x+++y++b.++xzc.x+y++d.x+xye.x+yx+x++y23PSIf x=2945, what is the value of each of the following expressions? a.x10b.x/10c.x/1010d.x/100e.x/1001025PS26PSWrite a program that reads two integers from the keyboard, multiplies them, and then prints the two numbers and their product.Write a program that extracts and prints the rightmost digit of the integral portion of a float.29PSWrite a program that calculates the area and perimeter of a rectangle from a user-supplied (scanf) length and width.31PS32PSWrite a program that changes a temperature reading from Fahrenheit to Celsius using the following formula: Celsius=100.0/180.0*Fahrenheit32 Your program should prompt the user to enter a Fahrenheit temperature. It then calculates the equivalent Celsius temperature and displays the results as shown below. EnterthetemperatureinFahrenheit:98.6Fahrenheittemperatureis:98.6Celsiustemperatureis:37.0Write the C code for each of the following formulas. Assume that all variables are defined as double. a.KinEn=mv22b.res=b+c2bc35PSWrite a program that converts and prints a user-supplied measurement in inches into a. foot (12 inches) b. yard (36 inches) c. centimeter (2.54/inch) d. meter (39.37 inches)37PSWrite a program that prompts a user for an integer value in the range 0 to 32,767 and then prints the individual digits of the numbers on a line with three spaces between the digits. The first line is to start with the leftmost digit and print all five digits; the second line is to start with the second digit from the left and print four digits, and so forth. For example, if the user enters 1234, your program should print 01234123423434439PS1PSThe function definition contains the code for a function. a. True b. FalseFunction calls that return void may not be used as a part of an expression. a. True b. FalseThe address operator (&) is used to tell the compiler to store data at an address. a. True b. FalseVariables defined within a block have global scope. a. True b. False6PSWhich of the following statements about function declaration and definition is true? a. The function call is found in the called function. b. The function declaration requires that the parameters be named. c. The function definition is done with a function declaration. d. The function definition contains executable statements that perform the function's task. e. The function definition header concludes with a semicolon (;).Which of the following is not a part of a function header? a. name b. parameter list c. return type d. titleWhich of the following statements about function parameters is true? a. Empty parameter lists are declared with the keyword void. b. If there is only one parameter, the function list parentheses are not required. c. In the definition of a function, the parameters are known as actual parameters. d. Parameters are separated by semicolons. e. The parameters in a function definition are defined in the function's body (local declaration section).Which of the following statements about local variables is false? a. A local variable's value may be returned through a return statement. b. Local variables are defined inside a function. c. Local variables cannot be referenced through their identifiers outside the function. d. Local variables may be initialized with an initializes. e. Local variables' names can be the same as the function's parameter names.11PS12PSWhich of the following statements will generate a random number in the range 30-50? a.rand33b.rand20+1c.rand21+20d.rand21+30e.rand51+1Which of the following statements about structure charts is false? a. Structure charts are a replacement for flowcharts. b. Structure charts are the primary design tool for a program. c. Structure charts are used in a structured walk-through to validate the design. d. Structure charts can be used to assess the testability of a program. e. Structure charts should be created before you start writing a program.Find any errors in the following function definition: voidfunintx,intyintz;...returnz;//funFind any errors in the following function definition: intfunintx,yintz;...returnz;//funFind any errors in the following function definition: intfunintx,inty...intsunintt......returnt+3;...returnz;//funFind any errors in the following function definition: voidfun(int,x)...return;//funFind any errors in the following function declarations: a. int sun (int x, y); b. int sun (int x, int y) c. void sun (void, void); d. void sun (x int, y float);Find any errors in the following function calls: a.voidfun;b.funvoid;c.voidfunintx,inty;d.fun;Evaluate the value of the following expressions: a.fabs9.5b.fabs2.4c.fabs3.4d.fabs7e.fabs7Evaluate the value of the following expressions: a.floor9.5b.floor2.4c.floor3.4d.ceil9.5e.ceil2.4f.ceil3.423PSDefine the range of the random numbers generated by the following expressions: a.rand10b.rand4c.rand10+1d.rand52e.rand2+1f.rand525What would be printed from Program 4-17 when run using 3 5 as data? PROGRAM 4-17 Program for Exercise 25 1#includestdio.h23//FunctionDeclarations4intstrangeintx,inty;56intmainvoid78//LocalDeclarations9inta;10intb;11intr;12ints;1314//Statements15scanfdd,a,b;16r=strangea,b;17s=strangeb,a;18printfdd,r,s;19return0;20//main21//==================strange=================22intstrangeintx,inty2324(//Statements25returnxy;26//strange26PS27PS28PS29PSWrite a program that generates a random number from the following set: 1,4,7,10,13,1631PSCode and run Program 4-16, "Top—down Development Example," to demonstrate how stubs work.33PS34PSExpand the calculator program, Program 4-15, to calculate the difference, product, quotient, and modulus of the numbers. Calculate the quotient and modulus in one function.36PSWrite a function that receives a positive floating-point number and rounds it to two decimal places. For example, 127.565031 rounds to 127.570000. 12.456789123.49999912.50000138PS39PSPrepare a payroll earnings statement for the sales force at the Arctic Ice Company. All of Arctic's employees are on a straight commission basis of 12.5 of sales. Each month, they also receive a bonus that varies depending on the profit for the month and their length of service. The sales manager calculates the bonus separately and enters it with the salesperson's total sales for the month. Your program is also to calculate the withholding taxes and retirement for the month based on the following rates: a. 25 Federal withholding b. 10 State withholding c. 8 Retirement plan Use the test data in Table 4-2 to test the program.Write a program that, given a beginning balance in your savings account, calculates the balance at the end of 1 year. The interest is 5.3 compounded quarterly. Show the interest earned and balance at the end of each quarter. Present the data in tabular columns with appropriate headings. Use separate functions to compute the interest and print the balance.The formula for converting centigrade temperatures to Fahrenheit is F=32+C180.0100.0 Write a program that asks the user to enter a temperature reading in centigrade and then prints the equivalent Fahrenheit value. It then asks the user to enter a Fahrenheit value and prints out the equivalent centigrade value. Run the program several times. Be sure to include at least one negative temperature reading in your test cases. Provide separate functions as needed by your design. One possible design is shown in Figure 4-40. (Your main function should have only function calls.)Write a program that uses standard functions. The program may be written entirely in main and must follow the pseudocode shown in Algorithm 4-1. Give the output appropriate captions, and align the data. ALGORITHM 4-1 Pseudocode for Project 43 1 Prompt the user to enter a number 2 Read number 3 Display number 4 Get a random number and scale to range 3...37 5 Display random number 6 Set product to number * random number 7 Display product 8 Display ceiling of random number 9 Display floor of product 10 Display number raised to power of random number 11 Display square root of random numberWrite a C program that creates customers' bills for a carpet company when the following information is given: a. the length and the width of the carpet in feet b. the carpet price per square foot c. the percent of discount for each customer The labor cost is fixed at $0.35 per square foot. It is to be defined as a constant. The tax rate is 8.5 applied after the discount. It is also to be defined as a constant. The input data consist of a set of three integers representing the length and width of the room to be carpeted, the percentage of the discount the owner gives to a customer, and a real number representing the unit price of the carpet. The program is to prompt the user for this input as shown below. (Colored numbers are typical responses.) The program's design should use main and at least the six functions described below: a. Read data from the keyboard. This function is to use addresses to read all data and place them in the calling function's variables. b. Calculate values. This function calls three subfunctions. Each function is to use addresses to store their results. Calculate the installed price. This function calculates area, carpet cost, labor cost, and installed price. The installed price is the cost of the carpet and the cost of the labor. Calculate the subtotal. This function calculates the discount and subtotal. Calculate the total price with discount and tax. This function calculates the tax and the total price. c. Print the result. Use two subfunctions to print the results: one to print the measurements, and one to print the charges. Test your program with the test data shown in Table 4-3.1PSThe expression in a selection statement can have no side effects. a. True b. FalseEach labeled statement may identify one or more statements. a. True b. FalseThe character classification functions are found in the standard library (stdlib.h). a. True b. False5PSThe logical operator is true only when both operands arc true. a.andb.greaterthanc.lessthand.ore.not!7PSTwo-way selection is implemented with the statement. a. case b. else if c. switch d. the if...else and the switch e. if...else9PSWhich of the following statements creates the "dangling else problem"? a. a nested if statement without a false statement b. a nested if statement without a true statement c. a switch statement without a default d. an if statement without a true or a false statement e. any nested if statementThere are two different ways to implement a multiway selection in C. They are a. if...else and switch b. else-if and switch c. if...else and else if d. else-if and case e. switch and caseWhich of the following statements about switch statements is false? a. No two case labels can have the same value. b. The switch control expression must be an integral type. c. The case-labeled constant can be a constant or a variable. d. Two case labels can be associated with the same statement series. e. A switch statement can have at most one default statement.Which of the following statements about the else-if is false? a. Each expression in the else-if must test the same variable. b. The else-if is a coding style rather than a C construct. c. The else-if requires integral values in its expression. d. The else-if is used for multiway selections. e. The last test in the else-if series concludes with a single else, which is the default condition.14PS15PSIf x=0,y=5,z=5, what is the value of x, y, and z for each of the following code fragments? (Assume that x, y, and z are their original values for each fragment.) a.ifz!=0y=295;elsex=10;b.ify+z10y=99;z=8;x=++z;c.ifx==0x=x3;z=z+3;elsey=99;If x=3,y=0,andz=4, what is the value of the following expressions? a.xyzb.xyzc.xyzd.xyze.xzySimplify the following expressions by removing the ! operator and the parentheses: a.!xyb.!x=yc.!x==yd.!x!=ye.!!xy19PSIf originally x=4,y=0,andz=2, what is the value of ; y, and z after executing the following code? ifx!=0y=3;elsez=2;If originally x=4,y=0,andz=2, what is the value of x, y, and z after executing the following code? ifz==2y=1;elsex=3;If originally x=4,y=0,andz=2, what is the value of x, y, and z after executing the following code? ifxyx=3;elsey=2;If originally x=4,y=0,andz=2, what is the value of x, y, and z after executing the following code? ifxyzy=1;elsez=3;If originally x=0,y=0,andz=1, what is the value of x, y, and z after executing the following code? ifxifyz=3;elsez=2;If originally x=4,y=0,andz=2, what is the value of x, y, and z after executing the following code? ifz==0x!yif!zy=1;elsex=2;If originally x=0,y=0,andz=1, what is the value of x, y, and z after executing the following code? ifxifyifzz=3;elsez=2;If originally x=0,y=0,andz=1, what is the value of x, y, and z after executing the following code? ifzxy=zz==1ifzyy=1;elsex=1;If originally x=0,y=0,andz=1, what is the value of x, y, and z after executing the following code? ifz=yy++;z;elsex;If originally x=0,y=0,andz=1, what is the value of x, y, and z after executing the following code? ifz=xyx+=3;y=1;elsex=y++;If originally x=0,y=0,andz=1, what is the value of x, y, and z after executing the following code? switchxcase0:x=2;y=3;case1:x=4;default:y=3;x=1;If originally x=2,y=1,andz=1, what is the value of x, y, and z after executing the following code? switchxcase0:x=2;y=3;case1:x=4;break;default:y=3;x=1;If originally x=1,y=3,andz=0, what is the value of x, y, and z after executing the following code? switchxcase0:x=2;y=3;break;case1:x=4;break;default:y=3;x=1;Evaluate the value of the following expressions: a.tolowerc'b.tolower?'c.tolowerc'd.tolower5'Evaluate the value of the following expressions: a.toupper'c'b.toupper'c'c.toupper'?'d.toupper'7'Write an if statement that will assign the value 1 to the variable best if the integer variable score is 90 or greater.36PSWrite the code to add 4 to an integer variable, num, if a float variable, amount, is greater than 5.4.38PSWrite the code to print either zero or not zero based on the integer variable num.If the variable divisor is not zero, divide the variable dividend by divisor, and store the result in quotient. If divisor is zero, assign it to quotient. Then print all three variables. Assume that dividend and divisor are integers and quotient is a double.41PSRewrite the following code using one if statement: ifaChar=='E'c++;ifaChar=='E'printfValueisEn;Rewrite the following code fragment using one switch statement: ifch=='E'ch=='e'countE++;elseifch=='A'ch==a'countA++elseifch=='I'ch=='i'countI++;elseprintErrorNotA,E,orIan;Write a code fragment that tests the value of an integer num1. If the value is 10, square num1. If it is 9, read a new value into num1. If it is 2 or 3, multiply num1 by 99 and print out the result. Implement your code using nested if statements, not a switch.45PS46PSWrite a function called smallest that, given three integers, returns the smallest value.48PSWrite a function called month_of_year that, given an integer between 1 and 12, prints the corresponding month of the year.Write a function called parkingcharge that, given the type of vehicle (c for car, b for bus, t for truck) and the hours a vehicle spent in the parking lot, returns the parking charge based on the rates shown below. car$2perhourbus$3perhourtruck$4perhour51PSComplete the incremental implementation of Program 5-13. First write the code to implement the multiply function, then the divide function, and finally the print results function. The print results function should use a switch to determine which option was requested and then print the results in the format shown below. numberoperatornumber=result You may pattern the function after the print results in Chapter 4, but it will need extensive modification.Write a program that determines a student's grade. It reads three test scores (between 0 and 100) and calls a function that calculates and returns a student's grade based on the following rules: a. If the average score is 90 or more, the grade is A. b. If the average score is 70 or more and less than 90, it checks the third score. If the third score is more than 90, the grade is A; other-wise, the grade is B. c. If the average score is 50 or more and less than 70, it checks the average of the second and third scores. If the average of the two is greater than 70, the grade is C; otherwise, it is D. d. If the average score is less than 50 percent, then the grade is F. The program's main is to contain only call statements. At least three subfunctions are required: one to read scores, one to determine the grade, and one to print the results.54PSGiven a point, a line from the point forms an angle with the horizontal axis to the right of the line. The line is said to terminate in one of four quadrants based on its angle (a) from the horizontal, as shown in figure 5-30. Write a program that determines the quadrant, given a user-input angle. Use a function to read and validate the angle. Note: If the angle is exactly 0, it is not in a quadrant but lies on the positive X-axis; if it is exactly 90, it lies on the positive Y-axis; if it is exactly 180, it lies on the negative X-axis; and if it is exactly 270, it lies on the negative Y-axis. Test your program with the following data: 0,48.3,90,179.8,180,186,270,300,and36056PSWrite a program that asks the user to enter the current date and a person's birth date in the form month, day, year. The program then calculates the person's age in integral years. Use separate functions to enter the dates (pass by address), calculate the person's age, and print the results. Test your program with the following dates: 11/14/1957, 5/10/1989, and 1/5/2000.58PSThis program is a simple guessing game. The computer is to generate a random number between 1 and 20. The user is given up to five tries to guess the exact number. After each guess, you are to tell the user if the guessed number is greater than, less than, or equal to the random number. If it is equal, no more guesses should be made. If the user hasn't guessed the number after five tries, display the number with a message that the user should know it by now and terminate the game. A possible successful dialog: Iamthinkingofanumberbetween1and20.Canyouguesswhatitis?10Yourguessislow.Tryagain:15Yourguessislow.Tryagain:17Yourguessishigh.Tryagain:16Congratulations!Youdidit. A possible unsuccessful dialog: Iamthinkingofanumberbetween1and20.Canyouguesswhatitis?10Yourguessislow.Tryagain:20Yourguessishigh.Tryagain:10Yourguessislow.Tryagain:18Yourguessishigh.Tryagain:12Sorry.Thenumberwas15.Youshouldhavegottenitbynow.Betterlucknexttime. Your design for this program should include a separate function to get the user's guess, a function to print the unsuccessful message, one to print the successful message, and one to print the sorry message.Write a program that, given a person's birth date (or any other date in the Gregorian calendar), will display the day of the week the person was born. To determine the day of the week, you will first need to calculate the day of the week for December 31 of the previous year. To calculate the day for December 31, use the following formula. year1365+year14year1100+year14007 The formula determines the day based on the values as shown below. Day0:SundayDay1:MondayDay2:TuesdayDay3:WednesdayDay4:ThursdayDay5:FridayDay6:Saturday Once you know the day for December 31, you simply calculate the days in the year before the month in question. Use a switch statement to make this calculation. If the desired month is 12, add the number of days for November (30). If it is 11, add the number of days for October (31). If it is 3, add the number of days for February (28). If it is 2, add the number of days for January (31). If you do not use a break between the months, the switch will add the days in each month before the current month. To this figure, add the day in the current month and then add the result to the day code for December 31. This number modulo seven is the day of the week. There is one more refinement. If the current year is a leap year, and if the desired date is after February, you need to add 1 to the day code. The following formula can be used to determine if the year is a leap year. !year4year100!year400 Your program should have a function to get data from the user, another to calculate the day of the week, and a third to print the result. To test your program, run it with the following dates: a.February28,1900,andMarch1,1900b.February28,1955,andMarch1,1955c.February28,1996,andMarch1,1996d.February28,2000,andMarch1,2000e.December31,1996f.Thefirstandlastdatesofthecurrentweek .Write a program that calculates the change due a customer by denomination; that is, how many pennies, nickels, dimes, etc. are needed in change. The input is to be the purchase price and the size of the bill tendered by the customer $100,$50,$20,$10,$5,$1.Write a menu-driven program that allows a user to enter five numbers and then choose between finding the smallest, largest, sum, or average. The menu and all the choices are to be functions. Use a switch statement to determine what action to take. Provide an error message if an invalid choice is entered. Run the program five times, once with each option and once with an invalid option. Each run is to use the following set of data: 18,21,7,54,9Write a program that tests a user-entered character and displays its classification according to the ASCII classifications shown in Figure 5-25, "Classifications of the Character Type." Write the program starting at the top of the classification tree and display all classifications that the char-acter belongs to. For instance, if the user enters a digit, you should display that it is printable, graphical, alphanumeric, and a digit.Write a program to compute the real roots of a quadratic equation ax2+bx+c=0. The roots can be calculated using the following formulas: x1=b+b24ac2aandx2=bb24ac2a Your program is to prompt the user to enter the constants (a, b, c). It is then to display the roots based on the following rules: a. If both a and b are zero, there is no solution. b. If a is zero, there is only one root c/b . c. If the discriminate b24ac is negative, there are no real roots. d. For all other combinations, there are two roots. Test your program with the data in Table 5-13.1PS2PS3PS4PS5PS6PS7PS8PS9PS10PS11PS12PS13PS14PS15PS16PS17PS18PS19PS20PS21PS22PS23PS24PS25PS26PS27PS28PS29PS30PS31PS32PSWrite a for loop that will produce each of following sequences: a. 6, 8, 10, 12, ..., 66 b. 7, 9, 11, 13, ..., 67 c. The sum of the numbers between 1 and 15 inclusive d. The sum of the odd numbers between 15 and 45 inclusive e. The first 50 numbers in the series 1, 4, 7, 10, ... (calculate the total 1 + 4 + 7 + 10 + ...)34PS35PS36PS37PS38PS39PSWrite a function that creates the following pattern, given the height (number of rows): ************************************41PS42PS43PS44PS45PS46PS47PS48PS49PS50PS51PS52PS53PSWrite a C program that can create four different patterns of different sizes. The size of each pattern is determined by the number of columns or rows. For example, a pattern of size 5 has 5 columns and 5 rows. Each pattern is made of character $ and a digit, which shows the size. The size must be between 2 and 9. Table 6-6 shows the four patterns in size 5. Your program displays a menu and asks the user to choose a pattern and size. But note that it must be robust; it must prompt the user to choose an option only between 1 and 5, and a pattern size only between 2 and 9. You are to print the menu and the user's response. The following example shows all user menu responses, including potential errors (user responses are in color): MENU1.PatternOne2.PatternTwo3.PatternThree4.PatternFour5.QuitChooseanOptionbetween1and5:11YourOptionisincorrect.Pleasetryagain.ChooseanOptionbetween1and5:3ChooseaPatternSizebetween2and9:12YourPatternsizeisincorrect.Tryagain.ChooseaPatternSizebetween2and9:4 The program must consist of a main function and six other functions called getOption,getSize,patternOne,patternTwo,patternThree,andpatternFour. Run your program once with the options and sizes shown in Table 6-7. Note that some options and sizes are missing because either the previous option or the size is invalid.55PS56PS57PS58PS59PS1PS2PS3PS4PS5PS6PS7PS8PS9PS10PS11PS12PS13PS14PS15PS16PS17PS
Page: [1][2][3]