Thursday, November 15, 2007

Program 1-23

1. Write a program that will read in two integers and then output their sum, difference and product.

2. Write a program that will accept 4 exams in one term. The program will read in a student's four exam scores as integer and output the student's average. A message will appear "Passed" or "Failed".

3. A Celsius (Centigrade) temperature C can be converted to an equivalent Fahrenheit temperature F according to the following formula: F=(9/5)C + 32 . Write a program that will read in Celsius temperature as decimal number and then output the equivalent Fahrenheit temperature.

4. The straight-line method for computing the yearly depreciation in the value D for an item is given by the formula D=(P-S)/Y where P is the purchase price, S is the salvage value, and Y is the number of years the item is used. Write a program that takes as input the purchase price of an item, its expected number of years of service, and its expected salvage value, and then outputs the yearly depreciation for an item.

5. Write programs that gauge the amount of inflation over the past year. The program asks for the price of an item (such as can goods, hot dog, car etc.) both one year ago and today. It estimates the inflation rate as the difference in the price divided by the last year's price.

6. Write a program to read in weight in pounds and ounces and output the weight expressed in kilograms and grams. One pound equals 0.453592 kilograms. Use a constant declaration.

7. Write a program that read in a distance expressed in kilometers and output the distance expressed in miles. One kilometer equals 0.62137 mile. Use a constant declaration.

8. A liter is 0.264179 gallons. Write a program that will read in the number of liters of gasoline consumed by the user's car and the number of miles traveled by the car, and then output the number of miles per gallon the car delivered. Use constant declaration.

9. Write a program that determines if a meeting room is in violation of fire regulation for the maximum room capacity. The program will read in the maximum room capacity and the number of people to attend the meeting. If the number of people is less than or equal to the maximum room capacity, the program announces that it is legal to hold a meeting and tells how many additional people may legally attend the meeting. If the number of people exceeds the maximum room capacity, the program announces that the meeting cannot be held as planned due to fire regulations and tells how many people must be excluded in order to meet the fire regulations and thereby allow the meeting to take place.

10. Write a program to list the numbers from 0-25, their squares, and square roots. The output should be in a three-column format. Use the predefined functions sqr and sqrt.
11. Write a program that will convert from dollar to peso or from peso to dollars depending on the user's desire. The user is asked which conversion is to be performed. If the desired conversion is peso to dollar, then the program reads in an amount in peso as well as the peso-to-dollars, then the program reads in an amount in dollars and cents. If the user instead request a conversion from dollar to peso, then the roles of dollars and peso are interchanged. Use at least four procedure or function: one for input, one for output, one to convert from peso to dollars, and one to convent from dollars to peso.

12. Write a program that will read in a length in feet and inches and output the equivalent length in meters and centimeters. Use at least three procedure or function. One for input, one or more for calculating, and one for output. There are 0.3048 meters in a foot, 100 centimeters in a meter, and 12 inches in a foot.

13. The greatest common divisor of two positive integers is the largest integer that divides them both. For example, thr greatest common divisor of 9 and 6 is 3. Write a procedure or function with two integer arguments that returns their greatest common divisor.

14. Write a program to determine grades in a course with three quizzes, each scored on a basis of 10 points. Grades are determined according to the following rule:9 or over is an A;below 9 down to 8 is a B; below 8 down to 7 is a C; below 7 down to 6 is a D and below 6 is an F.

15. Accept two integers and determine if the value are equal, if the values are equal do not print anything, otherwise print the lowest value.

16. Input three unique numbers and print the highest number.

17. Input unique values for n1, n2, and n3 and arrange the numbers in lowest to highest

18. Input four unique numbers and print the difference of the lowest and highest value. If there is equal nos. If it cannot determine the lowest or highest value print “Can not determine the lowest or highest value. Check if there are equal nos.”

19. Accept three integers and identify if there are equal numbers, if there are equal numbers print the equal numbers otherwise do no print anything.

20. Input three integers and determine if there are equal numbers. If there are equal numbers print the product of the equal numbers, otherwise print the average of the numbers.

21. Create a flowchart/program that will accept a child’s age and print its equivalent education level. The age of a child is considered 1 year old if it reaches 6 months. Given the condition of converting 6 months to 1 year, the flowchart/program should be able to identify the Childs education level. If a child was able to finish college, it is considered that he is no longer a child and is already a young adult and a professional. If the educational level is professional, the flowchart/program should not print anything. The education level in relation to the age is as follows: Age 0-2 Parental Age 3-4 Nursery Age 5-6 Pre-School Age 7-12 Elementary Age 13-16 High School Age 17-21 College

23. Make a program that will accept amount and compute the interest for 12 months. Interest is 5% per annum. ans

History of Turbo C

C stands for COMBINED PROGRAMMING LANGUAGE. Sometimes called SYSTEM PROGRAMMING LANGUAGE or SPL. C parallels with UNIX in 1969, by Bell Laboratories that sought an alternative to the Multics operating system for PDP-7 computer. The original version of Multics operating system was written in assembly language.

The reason why the language is called C is that it is the successor to the language called B which was developed by Ken Thompson in 1970 while working on DEC PDP-7. B was the successor the language called BCPL (Basic Combined Programming Language) which was developed by Martin Richards.

The C Language was designed in 1972 by Dennis Ritchie and first implemented at Bell Laboratory using DEC PDP-11 computer.

In 1978 Brian Kernighan and Dennis Ritchie wrote the famous book called THE C PROGRAMMING LANGUAGE.

C is often called a Middle Level Language but has a functionalism of a high-level language and assembly language. C has only 32 keywords (27 from Kernighan and Ritchie standard and 5 added by the ANSI Standardization committee).

Programming is a series of individual instructions to the computer that collectively perform a meaningful task. It is the act of writing or coding computer instructions. Program Source Code is the finished encoded instructions.

Programmer is the one who write the computer program and the first lady programmer is Lady Augusta "Ada" Byron.

Translator is use to transform the source code into a machine language that the computer can understand. Linker is use to adjust the translated source file so that the program will run.

Linking is usually distinct from the compiling process on a machine running MS-DOS.

____

ALGORITHM An Algorithm is a series of instructions that performs a specific task; It is a procedure that can be used to solve a particular problem.

An Algorithm is a list of instructions for carrying out some problems step by step.

Sequence - All programs are based on sequential execution of sequence instructions.

Decision - The primary way in which you can alter the sequential execution of the statements is to insert a decision step. Branching is a decision steps that lets the execution flow in two or more directions.

Iteration - is often called looping. It causes an iteration instruction or a set of instructions to be executed repeatedly.

Features of C-Language

1. Compact - C has only 32 standard keywords. Manufacturers of C-Compact language compilers are free to use additional keyword.

2. Structured - C permits certain portions of a program to have structured private access to data items stored in the computer memory, as well as the access to data items that are accessible by the rest of the program.

3. Portable - tasks that requires interaction with peripheral device; Portable such as disk drives or the video display, can be handled by standard library routines, which are not part of the c-language itself.

4. Flexible - C has proved to be suitable for variety of programming tasks. C allows relatively
unrestricted conversion of data from one type to another, such as the conversion of character to its numeric equivalent.

DIFFERENCES BETWEEN PASCAL AND C LANGUAGE

1. In Pascal, you can use lower case and uppercase but in C, you are only allowed to use lower case only for input and output.1. In

2. In Pascal comments are enclosed by { } or (* *); In C comment are enclosed in /* */

3. In Pascal, we use BEGIN and END in C {left curly braces signifies the beginning of the program while right curly braces signifies the end of the program.

4. In Pascal, (;) semicolon is used as statement separator. While in C, it is a statement terminator.

5. In Pascal, we use write or writeln to print the output list. In C, printf as write and printf("backslash n") for writeln.

6. In Pascal, we use read or readln to read from the keyboard. In C scanf, gets, getch, getche, getchar in different kind usage.

7. In Pascal it uses unit file, in C built in header file.

8. In Pascal libraries, in C its header file and libraries.

BASIC ELEMENTS OF C PROGRAMMING LANGUAGE

1. Directives - Instructs the C preprocessor to act on text of directives the program.

2. Declarations - Establish names and define characteristics such as size, scope, and data types.

3. Definitions - are declarations that allocate storage.

3.1 Function definition - declares the function name, its parameters, and the data type of the value it returns.
3.2 Statement order - affects how you can use variables and statement order functions.

BASIC COMPONENTS OF A PROGRAM

1. Programs must obtain information from some input source
2. Programs must decide now this input is to arranged and stored
3. Programs must use a set of instructions to manipulate the input
3.1 Single statement
3.2 Conditional Statements
3.3 Loops
3.4 Subroutines
4. Programs must report the results of the data manipulation
5. Well written application incorporates all of the fundamentals just listed, expressed in good modular design, self-documenting codes and good indention scheme.