Bartleby Sitemap - Textbook Solutions

All Textbook Solutions for C++ for Engineers and Scientists

Numerical analysis) Given a number, n, and an approximation for its square root, a closer approximation of the actual square root can be found by using this formula: newapproximation=(n/previousapproximation)+previousapproximation2 Using this information, write a C++ program that prompts the user for a number and an initial guess at its square root. Using this input data, your program should calculate an approximation of the square root that’s accurate to 0.00001. (Hint: Stop the loop when the difference between the two approximations is less than 0.00001.)(Numerical analysis) Here’s a challenging problem for those who know a little calculus. The Newton-Raphson method can be used to find the roots of any equation y(x)=0. In this method, the (i+1)stapproximation,xi+1,toarootofy(x)=0 is given in terms of the ith approximation, xi, by the following formula, where y’ denotes the derivative of y(x) with respect to x: xi+1=xiy(xi)/y(xi) For example, if y(x)=3x2+2x2,theny(x)=6x+2 , and the roots are found by making a reasonable guess for a first approximation x1 and iterating by using this equation: xi+1=xi(3xi2+2xi2)/(6xi+2) a. Using the Newton-Raphson method, find the two roots of the equation 3x2+2x2=0. (Hint: There’s one positive root and one negative root.) b. Extend the program written for Exercise 6a so that it finds the roots of any function y(x)=0, when the function for y(x) and the derivative of y(x) are placed in the code.(Probability) The probability that a phone call will last less than t minutes can be pproximated by the exponential probability function: Probability that a call lasts less than t minutes=1et/a aistheaveragecalllength.eisEulersnumber( 2.71828). For example, assuming the average call length is 2 minutes, the probability that a call will last less than 1 minute is calculated as 1e1/2=0.3297. Using this probability equation, write a C++ program that calculates and displays a list of probabilities of a call lasting less than 1 minute to less than 10 minutes, in 1-minute increments.(Mechanics) The deflection at any point along the centerline of a cantilevered beam, such as the one used for a balcony (see Figure 5.15), when a load is distributed evenly along the beam is given by this formula: d=wx224EI(x2+6l24lx) d is the deflection at location x (ft). xisthedistancefromthesecuredend( ft).wistheweightplacedattheendofthebeam( lbs/ft).listhebeamlength( ft). Eisthemodulesofelasticity( lbs/f t 2 ).Iisthesecondmomentofinertia( f t 4 ). For the beam shown in Figure 5.15, the second moment of inertia is determined as follows: l=bh312 b is the beam’s base. h is the beam’s height. Using these formulas, write, compile, and run a C++ program that determines and displays a table of the deflection for a cantilevered pine beam at half-foot increments along its length, using the following data: w=200lbs/ftl=3ftE=187.2106lb/ft2b=.2fth=.3ft(Physics) A golf ball is dropped from an airplane. The distance, d, the ball falls in t seconds is given by the formula d=gt2, where g is the acceleration caused by gravity and is equal to 32ft/sec2. Using this information, write and run a C++ program that displays the distance fallen in each 1-second interval for 10 seconds and the total distance the golf ball falls at the end of each interval. The output should complete the following chart4PP5PP6PP7PP8PP9PP10PP11PP(Practice) For the following function headers, determine the number, type, and order(sequence) of the values that must be passed to the function: a. void factorial(int n) b. void volts(int res, double induct, double cap) c. void power(int type, double induct, double cap) d. void flag(char type, double current, double time) e. void total(double amount, double rate) f. void roi(int a, int b, char c, char d, double e, double f) g. void getVal(int item, int iter, char decflag, char delim)2E3E(Statics) A beam’s second moment of inertia, also known as its area moment of inertia, is used to determine its resistance to bending and deflection. For a rectangular beam (see Figure 6.6), the second moment of inertia is given by this formula: Ibh3/12 I is the second moment of inertia (m4). b is the base (m). h is the height (m). a. Using this formula, write a function called beamMoment() that accepts two double- precision numbers as parameters (one for the base and one for the height), calculates the corresponding second moment of inertia, and displays the result. b. Include the function written in Exercise 4a in a working program. Make sure your function is called from main(). Test the function by passing various data to it.(Statics) An annulus is a cylindrical rod with a hollow center, as shown in Figure 6.7. Its second moment of inertia is given by this formula: I4(r24r14) I is the second moment of inertia (m4). r2 is the outer radius (m). r1 is the inner radius (m). a. Using this formula, write a function called annulusMoment ( ) that accepts two double-precision numbers as parameters (one for the outer radius and one for the inner radius), calculates the corresponding second moment of inertia, and displays the result. b. Include the function written in Exercise 5a in a working program. Make sure your function is called from main(). Test the function by passing various data to it.6E(Physics) Buoyancy is the upward force a liquid exerts on a submerged object, as shown in Figure 6.9. The buoyancy force is given by this formula: B=pgV Bisthebuoyancyforce( lbforN).isthefluiddensity( slug/f t 3 orkg/ m 3 ).gistheaccelerationcausedbygravity( 32.2ft/se c 2 or9.8m/ s 2 ).Vistheobjectsvolume( f t 3 or m 3 ). a. Using this formula, write a function named buoyantForce(double ro, double vol, int units) that accepts a fluid density, the volume of an object placed in the fluid, and the units to be used(1=U.S.Customaryunits,2=metricunits), and returns the buoyancy force exerted on the object. b. Include the function written for Exercise 6a in a working C++ program, and use your program to complete the following chart:(Numerical) a. Write a C++ program that accepts an integer argument and determines whether the passed integer is even or odd. (Hint: Use the % operator.) b. Enter, compile, and run the program written for Exercise 8a.(Practice) a. Write a function that produces a table of the numbers from 1 to 10, their squares, and their cubes. The function should produce the same display as Program 5.11. b. Include the function written in Exercise 9a in a working program. Make sure your function is called from main(). Test the function by passing various data to it.10E11E12E13E14E15E1E(Practice) For the following function headers, determine the number, type, and order (sequence) of values that should be passed to the function when it’s called and the data type of the value the function returns: a. int factorial(int n) b. double volts(int res, double induct, double cap) c. double power(int type, double induct, double cap) d. char flag(char type, float current, float time) e. int total(float amount, float rate) f. float roi(int a, int b, char c, char d, float e, float f) g. void getVal(int item, int iter, char decflag, char delim)3E(General math) a. Write a function named rightTriangle() that accepts the lengths of two sides of a right triangle as the arguments a and b. The subroutine should determine and return the hypotenuse, c, of the triangle. (Hint:UsePythagorastheorem,c2=a2+b2.) b. Include the function written for Exercise 4a in a working program. The main() function should call rightTriangle() correctly and display the value the function returns.(General math) a. The volume, V, of a cylinder is given by this formula: V=r2L r is the cylinder’s radius, and L is its length. Using this formula, write a C++ function named cylvol() that accepts a cylinder’s radius and length and returns its volume. b. Include the function written in Exercise 5a in a working program. Make sure your function is called from main() and returns a value to main() correctly. Have main() use a cout statement to display the returned value. Test the function by passing various data to it.6E7E8E9E10E(Numerical) a. The following is an extremely useful programming algorithm for rounding a real number to n decimal places: Step 1: Multiply the number by 10n Step 2: Add 0.5 Step 3: Delete the fractional part of the result Step 4: Divide by 10n For example, using this algorithm to round the number 78.374625 to three decimal places yields: Step1:78.374625103=78374.625 Step2:78374.625+0.5=78375.125 Step3:Retainingtheintegerpart=78375Step4:78375dividedby103=78.375 Using this algorithm, write a C++ function that accepts a user-entered value and returns the result rounded to two decimal places. b. Enter, compile, and run the program written for Exercise 11a.12E13E14E1E2E3E4E5E6E7E(Practice) The volume, v, and side surface area, s, of a cylinder are given by these formulas: v=r2ls=2rl r is the cylinder’s radius, and l is its length. Using these formulas, write and test a function named cylinder() that accepts a cylinder’s radius and length and returns its volume and side surface area.(Practice) Write a C++ program that accepts the rectangular coordinates of two points (x1,y1)and(x2,y2), calculates the distance of each point from the origin, and calculates the distance between the two points. The distance, d, between two points is given by this formula: d=(x2x1)2+(y2y1)23E4E5E6E(Simulation) Write a program to simulate the roll of two dice. If the total of the two dice is 7 or 11, you win; otherwise, you lose. Embellish this program as much as you like, with betting, different odds, different combinations for win or lose, stopping play when you have no money left or reach the house limit, displaying the dice, and so forth. (Hint: Calculate the dots showing on each die with the expression dots=(int)(6.0randomnumber+1), where the random number is between 0 and 1.)8E(Numerical) Write a program that tests the effectiveness of the rand() library function. Start by initializing 10 counters to 0, and then generate a large number of pseudorandom integers between 0 and 9. Each time a 0 occurs, increment the variable you have designated as the zero counter; when a 1 occurs, increment the counter variable that’s keeping count of the 1s that occur; and so on. Finally, display the number of 0s, 1s, 2s, and so on that occurred and the percentage of the time they occurred.1E2E3E4E5E1E2E3E4E5E6E1PP2PP3PP4PP5PP6PP(Numerical) Heron’s formula for the area, A, of a triangle with sides of length a, b, and c is A=s(sa)(sb)(sc) where s=(a+b+c)2 Write, test, and execute a function that accepts the values of a, b, and c as parameters from a calling function, and then calculates the values of sand[s(sa)(sb)(sc)]. If this quantity is positive, the function calculates A. If the quantity is negative, a, b, and c do not form a triangle, and the function should set A=1. The value of A should be returned by the function.8PP9PP10PP(Practice) Write array declarations for the following: a. A list of 100 double-precision voltages b. A list of 50 double-precision temperatures c. A list of 30 characters, each representing a code d. A list of 100 integer years e. A list of 32 double-precision velocities f. A list of 1000 double-precision distances g. A list of 6 integer code numbers(Practice) Write correct notation for the first, third, and seventh elements of the following arrays: a. int grades[20] b. double volts[10] c. double amps[16] d. int dist[15] e. double velocity[25] f. double time[100]3E(Practice) a. Write output statements using cout that can be used to display values from the first, third, and seventh elements of each array declared in Exercise 2. b. Write a for loop that can be used to display values for the complete array declared in Exercise 2.(Desk check) List the elements displayed by the following sections of code: a.for( m=1;m=5;m++)couta[m];b.for( k=1;k=5;k=k+2)couta[k];c.for( j=3;j=10;j++)coutb[j];d.for( k=3;k=12;k=k+3)coutb[k];e.for( i=2;i11;i=i+2)coutc[i];(Practice) a. Write a program to input the following values in an array named volts: 11.95, 16.32, 12.15, 8.22, 15.98, 26.22, 13.54, 6.45, and 17.59. After the data has been entered, have your program display the values. b. Repeat Exercise 6a, but after the data has been entered, have your program display it in the following form: 11.9516.3212.158.2215.9826.2213.546.4517.59(Practice) Write a program to input eight integer numbers in an array named temp. As each number is input, add the numbers to a total. After all numbers are input, display the numbers and their average.(Data processing) a. Write a program to input 10 integer numbers in an array named fmax and determine the maximum value entered. Your program should contain only one loop, and the maximum should be determined as array element values are being input. (Hint: Set the maximum equal to the first array element, which should be input before the loop used to input the remaining array values.) b. Repeat Exercise 8a, keeping track of both the maximum element in the array and the index number for the maximum. After displaying the numbers, print these two messages (replacing the underlines with the correct values): The maximum value is: ___ This is element number ___ in the list of numbers c. Repeat Exercise 8b, but have your program locate the minimum of the data entered.9E(Electrical eng.) Write a program that specifies three one-dimensional arrays named current, resistance, and volts. Each array should be capable of holding 10 elements. Using a for loop, input values for the current and resistance arrays. The entries in the volts array should be the product of the corresponding values in the current and resistance arrays (sovolts[i]=current[i]resistance[i]). After all the data has been entered, display the following output, with the appropriate value under each column heading: CurrentResistance Volts(Practice) Write array declarations, including initializers, for the following: a. A list of 10 integer voltages: 89, 75, 82, 93, 78, 95, 81, 88, 77, and 82 b. A list of five double-precision slopes: 11.62, 13.98, 18.45, 12.68, and 14.76 c. A list of 100 double-precision distances; the first six distances are 6.29, 6.95, 7.25, 7.35, 7.40, and 7.42 d. A list of 64 double-precision temperatures; the first 10 temperatures are 78.2, 69.6, 68.5, 83.9, 55.4, 67.0, 49.8, 58.3, 62.5, and 71.6 e. A list of 15 character codes; the first seven codes are f, j, m, q, t, w, and z(Data processing) Write an array declaration statement that stores the following values in an array named volts: 16.24, 18.98, 23.75, 16.29, 19.54, 14.22, 11.13, and 15.39. Include these statements in a program that displays the values in the array.(Data processing) Write a program that uses an array declaration statement to initialize the following numbers in an array named slopes: 17.24, 25.63, 5.94, 33.92, 3.71, 32.84, 35.93, 18.24, and 6.92. Your program should locate and display the maximum and minimum values in the array.(Electrical eng.) Write a program that stores the following resistance values in an array named resistance: 16, 27, 39, 56, and 81. Your program should also create two arrays named current and power, each capable of storing five double-precision numbers. Using a for loop nd a cin statement, have your program accept five user-input numbers in the current array when the program is run. Your program should store the product of the values of the squares of the current array and the resistance array in the power array. For example, use power[1]=resistance[1]pow(current[1],2). Your program should then display the following output (fill in the chart):(Practice) a. Write a declaration to store the string "This is a test" in an array named strtest. Include the declaration in a program to display the message using the following loop: for( i=0;iNUMDISPLAY;i++)coutstrtest[i]; NUMDISPLAY is a named constant for the number 14. b. Modify the for statement in Exercise 5a to display only the array characters t, e, s, and t. c. Include the array declaration written in Exercise 5a in a program that uses a cout statement to display characters in the array. For example, the statement cout << strtest; causes the string stored in the strtest array to be displayed. Using this statement requires having the end-of-string marker, \0, as the last character in the array. d. Repeat Exercise 5a, using a while loop. (Hint: Stop the loop when the \0 escape sequence is detected. The expression while (strtest[i]!=0)canbeused.)(Practice) Write specification statements for the following: a. An array of integers with 6 rows and 10 columns b. An array of integers with 2 rows and 5 columns c. An array of characters with 7 rows and 12 columns d. An array of characters with 15 rows and 7 columns e. An array of double-precision numbers with 10 rows and 25 columns f. An array of double-precision numbers with 16 rows and 8 columns(Desk check) Determine the output produced by the following program: includeiostreamusingnamespacestd;intmain()inti,j,val[3][4]={8,16,9,52,3,15,27,6,14,25,2,10};for( i=0;i3;++i)for( j=0;j4;++j)coutval[i][j];return0;(Practice) a. Write a C++ program that adds the values of all elements in the val array used in Exercise 2 and displays the total. b. Modify the program written for Exercise 3a to display the total of each row separately.(Practice) Write a C++ program that adds equivalent elements of the two-dimensional arrays named first and second. Both arrays should have two rows and three columns. For example, element [1][2] of the resulting array should be the sum of first [1][2]andsecond[1][2]. The first and second arrays should be initialized as follows: first second 16 18 23 24 52 77 54 9111 16 19 595E6E(Electrical eng.) a. An engineer has constructed a two-dimensional array of real numbers with three rows and five columns. This array currently contains test voltages of an amplifier. Write a C++ program that interactively inputs 15 array values, and then determines the total number of voltages in these ranges: less than 60, greater than or equal to 60 and less than 70, greater than or equal to 70 and less than 80, greater than or equal to 80 and less than 90, and greater than or equal to 90. b. Entering 15 voltages each time the program written for Exercise 7a runs is cumbersome. What method could be used for initializing the array during the testing phase? c. How might the program you wrote for Exercise 7a be modified to include the case of no voltage being present? That is, what voltage could be used to indicate an invalid voltage, and how would your program have to be modified to exclude counting such a voltage?1E2E3E4E5E(Electrical eng.) Write a program that declares three one-dimensional arrays named volts, current, and resistance. Each array should be declared in main() and be capable of holding 10 double-precision numbers. The numbers to store in current are 10.62, 14.89, 13.21, 16.55, 18.62, 9.47, 6.58, 18.32, 12.15, and 3.98. The numbers to store in resistance are 4, 8.5, 6, 7.35, 9, 15.3, 3, 5.4, 2.9, and 4.8. Your program should pass these three arrays to a function named calc_volts(), which should calculate elements in the volts array as the product of the corresponding elements in the current and resistance arrays (for example ,volts[1]=current[1]resistance[1]). After calc_volts() has passed values to the volts array, the values in the array should be displayed from inside main().(Statistics) Write a program that includes two functions named calcavg() and variance(). The calcavg() function should calculate and return the average of values stored in an array named testvals. The array should be declared in main() and include the values 89, 95, 72, 83, 99, 54, 86, 75, 92, 73, 79, 75, 82, and 73. The variance() function should calculate and return the variance of the data. The variance is obtained by subtracting the average from each value in testvals, squaring the values obtained, adding them, and dividing by the number of elements in testvals. The values returned from calcavg() and variance() should be displayed by using cout statements in main().1E(Practice) Run Program 7.10 to determine the average and standard deviation of the following list of 15 grades: 68, 72, 78, 69, 85, 98, 95, 75, 77, 82, 84, 91, 89, 65, and 74.3E(List maintenance) a. Write a complete C++ program that can be used to update an ordered list of numbers. Use the list of numbers shown in Figure 7.13 to test that your program is working correctly. b. Test the program you wrote for Exercise 4a, using a new part number of 86 with the list of numbers shown in Figure 7.13. This test should place this new code at the beginning of the existing list. c. Test the program you wrote for Exercise 4a, using a part number of 200 with the list of numbers shown in Figure 7.13. This test should place this new part number at the end of the existing list5E(List maintenance) The following letters are stored in an alphabet array: B, J, K, M, S, and Z. Write and test a function named adlet(), which accepts the alphabet array and a new letter as arguments, and then inserts the new letter in the correct alphabetical order in the array.(File creation) Write a C++ program that creates an array containing the integer numbers 60, 40, 80, 90, 120, 150, 130, 160, 170, and 200. Your program should then write the data in the array to a text file. (Alternatively, you can create the file with a text editor.)8E9E10E11E12E13E14E15E1E2E3E4E5E6E7E8E(Practice) Use the max_element and min_element algorithms to determine the maximum and minimum values in the vector created for Exercise 8. (Hint: Use the expression max_ element(vectorName.begin(), vectorName.end()) to determine the maximum value stored in the vector. Then use the same arguments for the min_element algorithm.)(Statistics) a. Write a C++ program that reads a list of double-precision grades from the keyboard into an array named grade. The grades are to be counted as they’re read, and entry is to be terminated when a negative value has been entered. After all grades have been input, your program should find and display the sum and average of the grades. The grades should then be listed with an asterisk (*) placed in front of each grade that’s below the average. b. Extend the program written for Exercise 1a to display each grade and its letter equivalent, using the following scale: Between90and100=AGreaterthanorequalto80andlessthan90=BGreaterthanorequalto70andlessthan80=CGreaterthanorequalto60andlessthan70=DLessthan60=F(Practice) Define an array named peopleTypes that can store a maximum of 50 integer valuesentered at the keyboard. Enter a series of 1s, 2s, 3s, and 4s into the array to represent people at a local school function; 1 represents an infant, 2 represents a child, 3 represents a teenager, and 4 represents an adult. No other integer value should be accepted as valid input, and data entry should stop when a negative value is entered. Your program should count the number of each 1, 2, 3, and 4 in the array and display a list of how many infants, children, teenagers, and adults were at the school function.(Numerical) Given a one-dimensional array of integer numbers, write and test a function that displays the array elements in reverse order.(Numerical) Write and test a function that returns the position of the largest and smallest values in an array of double-precision numbers.(Sorting) Read a set of numerical grades from the keyboard into an array. The maximum number of grades to be entered is 50, and data entry should be terminated when a negative number is entered. Have your program sort and print the grades in descending order.(Numerical) a. Define an array with a maximum of 20 integer values, and fill the array with numbers input from the keyboard or assigned by the program. Then write a function named split() that reads the array and places all zeros or positive numbers in an array named positive and all negative numbers in an array named negative. Finally, have your program call a function that displays the values in both the positive and negative arrays. b. Extend the program written for Exercise 6a to sort the positive and negative arrays into ascending order before they’re displayed.(Numerical) Using the srand() and rand() C++ library functions, fill an array of 1000 floating-point numbers with random numbers that have been scaled to the range 1 to 100. Then determine and display the number of random numbers having values between 1 and 50 and the number having values greater than 50. What do you expect the output counts to be?(Statistical) In many statistical analysis programs, data values considerably outside the range of the majority of values are simply dropped from consideration. Using this information, write a C++ program that accepts up to 10 floating-point values from a user and determines and displays the average and standard deviation of the input values. All values more than four standard deviations away from the computed average are to be displayed and dropped from any further calculation, and a new average and standard deviation should be computed and displayed.(Data processing) Your professor has asked you to write a C++ program that determines grades at the end of the semester. For each student, identified by an integer number between 1 and 60, four exam grades must be kept, and two final grade averages must be computed. The first grade average is simply the average of all four grades. The second grade average is computed by weighting the four grades as follows: The first grade gets a weight of 0.2, the second grade gets a weight of 0.3, the third grade gets a weight of 0.3, and the fourth grade gets a weight of 0.2. That is, the final grade is computed as follows: 0.2grade1+0.3grade2+0.3grade3+0.2grade4 Using this information, construct a 60-by-7 two-dimensional array, in which the first column is used for the student number, the next four columns for the grades, and the last two columns for the computed final grades. The program’s output should be a display of the data in the completed array. For testing purposes, the professor has provided the following data:(Modify) Modify the program written for Exercise 9 by adding an eighth column to the array. The grade in the eighth column should be calculated by computing the average of the top three grades only.11PP(Data processing) The answers to a true-false test are as follows: T T F F T. Given a twodimensional answer array, in which each row corresponds to the answers provided on one test, write a function that accepts the two-dimensional array and number of tests as parameters and returns a one-dimensional array containing the grades for each test. (Each question is worth 5 points, so the maximum possible grade is 25.) Test your function with the following data:13PP(Data processing) Construct a three-dimensional weather array for a two-week time period. Include this array in a C++ program that displays the temperatures correctly in response to any of the following user requests: • Any day’s high and low temperatures • Average high and low temperatures for a given month • Month and day with the highest temperature • Month and day with the lowest temperature(Computation) A magic square is a square of numbers with N rows and N columns, in which each integer value from 1 to (N * N) appears exactly once, and the sum of each column, each row, and each diagonal is the same value. For example, Figure 7.21 shows a magic square in which N=3, and the sum of the rows, columns, and diagonals is 15. Write a program that constructs and displays a magic square for a given odd number N. This is the algorithm:(Computation) Among other applications, Pascal’s triangle (see Figure 7.22) provides a means of determining the number of possible combinations of n things taken r at a time. For example, the number of possible combinations of five people (n = 5) taken two at a time (r=2)is10. Each row of the triangle begins and ends with 1. Every other element in a row is the sum of the element directly above it with the element to the left of the one above it. That is, element[n][r]=element[n1][r]+element[n1][r1] Using this information, write and test a C++ program to create the first 11 rows of a twodimensional array representing Pascal’s triangle. For any given value of n less than 11 and r less than or equal to n, the program should display the correct element. Use your program to determine in how many ways a committee of 8 can be selected from a group of 10 people1E(Practice) a. Write a set of two statements declaring the following objects as ifstream objects, and then opening them as text input files: inData.txt, prices.txt, coupons.dat, and exper.dat. b. Rewrite the two statements for Exercise 2a, using a single statement.3E4E5E6E7E8E9E10E1E(Practice and modify) a. Enter and run Program 8.6. b. Modify Program 8.6 by replacing cout with cerr, and verify that the output for the standard error stream is the screen. c. Modify Program 8.6 by replacing cout with clog, and verify that the output for the standard log stream is the screen.(Practice and modify) a. Write a C++ program that accepts lines of text from the keyboard and writes each line to a file named text.dat until an empty line is entered. An empty line is a line with no text that’s created by pressing the Enter (or Return) key. b. Modify Program 8.6 to read and display the data stored in the text.dat file created in Exercise 3a.(Practice) Determine the OS command or procedure your computer provides to display the contents of a saved file.5E(Data processing) a. Write a C++ program that opens a file and displays its contents with line numbers. That is, the program should print the number 1 before displaying the first line, print the number 2 before displaying the second line, and so on for each line in the file. b. Modify the program written in Exercise 6a to list the file’s contents on the printer assigned to your computer.7E8E9E1E2E3E4E5E6E1E2E3E4E(Practice) Write a C++ program to create the pollen.in file shown in Figure 8.3.2E3E4E5E1PP(Data processing) a. Store the following data in a file, or use the numbers.dat file provided on this book’s Web site. 5 96 87 78 93 21 4 92 82 85 87 6 72 69 85 75 81 73 b. Write a C++ program to calculate and display the average of each group of numbers in the file created in Exercise 2a. The data is arranged in the file so that each group of numbers is preceded by the number of data items in the group. Therefore, the first number in the file, 5, indicates that the next five numbers should be grouped together. The number 4 indicates that the following four numbers are a group, and the 6 indicates that the last six numbers are a group. (Hint: Use a nested loop. The outer loop should terminate when the end of file has been encountered.)(Data processing) Write a C++ program that allows the user to enter the following information from the keyboard for each student in a class (up to 20 students): Name Exam 1 Grade Exam 2 Grade Homework Grade Final Exam Grade For each student, your program should first calculate a final grade, using this formula: FinalGrade=0.20Exam1+0.20Exam2+0.35Homework+0.25FinalExam Then assign a letter grade on the basis of 90100=A,8089=B,7079=C,6069=D, and less than 60=F . All the information, including the final grade and the letter grade, should then be displayed and written to a file.(Data processing) Write a C++ program that permits users to enter the following information about your small company’s 10 employees and then writes the information to a file: ID No. Sex (M/F) Hourly Wage Years with the Company(Data processing) Write a C++ program that reads the file created in Exercise 4, permits the user to change the hourly wage or years for any employee, and creates a new updated file.(Data processing) Write a C++ program that reads the file created in Exercise 4 one record at a time, asks for the number of hours each employee worked each month, and calculates and displays each employee’s total pay for the month.7PP(Data processing) A bank’s customer records are to be stored in a file and read into a set of arrays so that a customer’s record can be accessed randomly by account number. Create the file by entering five customer records, with each record consisting of an integer account number (starting with account number 1000), a first name (maximum of 10 characters), a last name (maximum of 15 characters), and a double-precision number for the account balance. After the file is created, write a C++ program that requests a user-input account number and displays the corresponding name and account balance from the file.(Inventory) Create an ASCII file with the following data, or use the shipped.dat file available on this book’s Web site. The headings aren’t part of the file but indicate what the data represents Using this data file, write a C++ program that reads the file and produces a report listing the shipped date, part number, first name, last name, and company name.1E2E3E4E5E6E7E1E2E3E4E5E6E7E1E2E3E4E5E(Program) Using the at() function, write a C++ program that reads in a string by using getline() and then displays the string in reverse order. (Hint: After the string has been entered and saved, retrieve and display characters, starting from the end of the string.)7E8E9E1E2E3E4E5E6E7E8E9E1E2E3E4E5E6E7E8E9E10E11E1E2E(For thought) a. What’s an advantage of namespaces? b. What’s a possible disadvantage of namespaces?4E5E6E1PP2PP(Program) Write a C++ program that accepts a string from the user and then replaces all occurrences of the letter e with the letter x.(Useful utility) Modify the program written for Exercise 3 to search for the first occurrence of a user-entered sequence of characters, and then replace this sequence, when it’s found in the string, with a second user-entered sequence. For example, if the entered string is Figure 4-4 illustrates the output of Program 4-2 and the user enters that 4- is to be replaced by 3-, the resulting string is Figure 3-4 illustrates the output of Program 4-2. (Only the first occurrence of the searched-for sequence has been changed.)5PP6PP7PP8PP9PP10PP1E2E3E4E5E6E7E8E9E10E11E12E1E2E3E(Program) Write a declaration to store the following values in an array named rates: 12.9, 18.6, 11.4, 13.7, 9.5, 15.2, and 17.6. Include the declaration in a program that displays the values in the array by using pointer notation.1E2E3E4E5E1E2E3E4E5E6E1PP2PP3PP4PP5PP6PP1E2E3E4E5E6E7E8E9E1E2E3E4E5E6E7E8E
Page: [1][2][3]