Wednesday, 2 July 2014

Chapter#1 An Overview of Computers and Programming Languages

Leave a Comment


Chapter 1: An Overview of Computers and Programming Languages


EXERCISES

1. Mark the following statements as true or false.

a. The first device known to carry out calculations was the Pascaline.

b. Modern-day computers can accept spoken-word instructions but cannot imitate human    reasoning.

c. In ASCII coding, every character is coded as a sequence of 8 bits.

d. A compiler translates a high-level program into assembly language.

e. The arithmetic operations are performed inside CPU, and if an error is found, it outputs the logical errors.

f. A sequence of 0s and 1s is called a decimal code.

g. A linker links and loads the object code from main memory into the CPU for execution.

h. Development of a C++ program includes six steps.

i. A program written in a high-level programming language is called a source program.

j. ZB stands for zero byte.

k. The first step in the problem-solving process is to analyze the problem.

l. In object-oriented design, a program is a collection of interacting functions.

Questions



2. Name two input devices.

3. Name two output devices.

4. Why is secondary storage needed?

5. What is the function of an operating system?

6. What are the two types of programs?

7. What are the differences between machine languages and high-level languages?

8. What is a source program?

9. Why do you need a compiler?

10. What kind of errors are reported by a compiler?

11. Why do you need to translate a program written in a high-level language into machine language?

12. Why would you prefer to write a program in a high-level language rather than a machine language?

13. What is linking?

14. What are the advantages of problem analysis and algorithm design over directly writing a program in a high-level language?

15. Design an algorithm to find the weighted average of four test scores. The four test scores and their respective weights are given in the following format:

testscore1 weight1

...

For example, sample data is as follows:

75 0.20

95 0.35

85 0.15

65 0.30

16. Design an algorithm to convert the change given in quarters, dimes, nickels, and pennies into pennies.

17. Given the radius, in inches, and price of a pizza, design an algorithm to find the price of the pizza per square inch.

18. A salesperson leaves his home every Monday and returns every Friday. He travels by company car. Each day on the road, the salesperson records the amount of gasoline put in the car. Given the starting odometer reading (that is, the odometer reading before he leaves on Monday) and the ending odometer reading (the odometer reading after he returns home on Friday), design an algorithm to find the average miles per gallon. Sample data is as follows:

68723 71289 15.75 16.30 10.95 20.65 30.00

19. To make a profit, the prices of the items sold in a furniture store are marked up by 60%. Design an algorithm to find the selling price of an item sold at the furniture store. What information do you need to find the selling price?

20. Suppose a, b, and c denote the lengths of the sides of a triangle. Then the area of the triangle can be calculated using the formula:

ffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi

sðs _ aÞðs _ bÞðs _ cÞ

p

; where s = (1/2)(a + b + c). Design an algorithm that uses this formula to find the area of a triangle. What information do you need to find the area?

 21. Suppose that the cost of sending an international fax is calculated as follows:

Service charges

$3.00; $.20 per page for the first 10 pages; and $0.10 for each additional page. Design an algorithm that asks the user to enter the number of pages to be faxed. The algorithm then uses the number of pages to be faxed to calculate the amount due.

22. An ATM allows a customer to withdraw a maximum of $500 per day. If a customer withdraws more than

$300, the service charge is 4% of the amount over

$300. If the customer does not have sufficient money in the account, the

ATM informs the customer about the insufficient fund and gives the option to withdraw the money for a service charge of

$25.00. If there is no money in the account or if the account balance is negative, the ATM does not allow the customer to withdraw any money. If the amount to be withdrawn is greater than

$500, the ATM informs the customer about the maximum amount that can be withdrawn. Write an algorithm that allows the customer to enter the amount to be withdrawn. The algorithm then checks the total amount in the account, dispenses the money to the customer, and debits the account by the amount withdrawn and the service charges, if any.

23. You are given a list of students’ names and their test scores. Design an algorithm that does the following:

a. Calculates the average test scores.

b. Determines and prints the names of all the students whose test scores are below the average test score.

c. Determines the highest test score.

d. Prints the names of all the students whose test scores are the same as the highest test score.

(You must divide this problem into subproblems as follows: The first subproblem determines the average test score. The second subproblem determines and prints the names of all the students whose test scores are below the average test score. The third subproblem determines the highest test score. The fourth subproblem prints the names of all the students whose test scores are the same as the highest test score. The main algorithm combines the solutions of the subproblems.)
If You Enjoyed This, Take 5 Seconds To Share It

0 Questions: