C Programming. Use Code :: Blocks to write a program for this exercise: ( Using
ID: 3695896 • Letter: C
Question
C Programming. Use Code :: Blocks to write a program for this exercise: (Using Pointers and Strings)
Cost Estimate:
(a) Define a pair of parallel arrays that will be used for estimating the cost of a repair job. The first array should contain the names of various parts; the second array, the price of each part.
For example, these arrays might contain data like this:
{ "muffler", "oil filter", "spark plugs", ... }
{ 39.95, 4.95, 6.00, ... }
(b) Write a program that will present a menu of parts for the user, then permit him or her to select any number of parts from the menu. After selecting a part, the program should prompt for the quantity of that part (one or more) that will be used for the repair, calculate the price for those parts, and add it to a total price. When the user selects "Done" from the menu, print the total price of all parts needed, with a sales tax of 6%.
Explanation / Answer
computing, a group of parallel arrays is a data structure for representing arrays of records. It keeps a separate, homogeneousarray for each field of the record, each having the same number of elements. Then, objects located at the same index in each array are implicitly the fields of a single record.
n this chapter, you will learn how to make the computer execute a group of statements over and over as long as certain criterion holds. The group of statements being executed repeatedly is called a loop. There are two loop statements in Python: for and while. We will discuss the difference between these statements later in the chapter, but first let us look at an example of a loop in the real world.
A petrol attendant performs the following actions when serving a customer:
A petrol attendant performs these steps for each customer, but he does not follow them when there is no customer to serve. He also only performs them when it is his shift. If we were to write a computer program to simulate this behaviour, it would not be enough just to provide the steps and ask the computer to repeat them over and over. We would also need to tell it when to stop executing them.
(a) function numdigits(x: integer): integer; var t,n: integer; begin n := 1; t := x; while t >= 10 do begin n := n + 1; t := t div 10; end; numdigits := n; end; (c) numdigits x = if x < 10 then 1 else numdigits(x / 10) + 1 (e) function numdigits(x: Integer) return Integer is t: Integer := x; n: Integer := 1; begin while t >= 10 loop n := n + 1; t := t / 10; end loop; return n; end numdigits; (g) class NumDigits { public static int numdigits(int x) { int t = x, n = 1; while (t >= 10) { n++; t = t / 10; } return n; } } Kenneth C. Louden Programming Languages
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.