Documente Academic
Documente Profesional
Documente Cultură
You have seen the programming environment of C in our last meeting. I am very sure your questions are: How can information be displayed on the monitor? How can information or values be manipulated in Turbo C++? Lets first see if you get the correct vibes about the program that you have seen in our last meeting by answering the anticipation guide in the next slide.
Directions: The class shall have 3 members per group. The group shall answer the anticipation guide. On the space in front of each of the numbers, place an X" to indicates where you stand in regard to the statement that follows: Agree _____ Disagree ______ 1. printf() and scanf() use format conversion specifiers _____ ______ 2.scanf() is used to scan text or picture ______ ______ 3. printf() displays text or information on the monitor ______ ______4. C language has print and input statements ______ ______5. C language has printf and scanf functions
Note: Do not panic when you see error messages. Follow the directions and answer the questions after the program. I designed the activities that way to emphasize important points.
How to debug errors: Error#1: Unable to create file noname00.cpp
-Save the program properly in the labserve folder. Dont forget to change directory.
Error#2: Statement missing ; -Check all the C statements. Put a semi-colon at the end of the line/s. Error#3: Declaration syntax error -Put a semi-colon at the end of the variable declaration statement
You have different answers in the anticipation guide. Lets now find out which answers are correct by doing the hands-on activities.
How are you going to debug the code?________________ (Tip: Check the line in blue color. Edit it.)
What is the output? _____________________________
5. View the output by pressing Ctrl+F9 or select the Run command in the Run menu
6. Save the file as print.cpp in the PrintF subfolder. 7. Make an exe file. Press F9.
Questions: Did you see errors on the monitor? __________________ How are you going to debug the code?________________ (Tip: Check the line in blue color. Edit it.) What is the output? _____________________________ 4. View the output by pressing Ctrl+F9 or select the Run command in Run menu.
You have seen simple examples of C programs and their output. You might be wondering now how strings are displayed on the monitor and how computer get information from the user in C. To satisfy your curiosity, it is a must to study first the basic functions that are used in displaying and getting information from the user. 1. Please open the link http://www.geocities.com/learnprogramming123/Clesson4Beginner.htm 2. Check/read the function of printf(), scanf(), and be familiar with the conversion specifiers.
3. Answer the questions in the next slide. Type your answers on the space provided for each number.
Cs data types
Variable Type
Character Integer
Range
-128 to 127 -32768 to 32767
Long Integer
long
-2,147,483,648 to 2,147,483,647
1.2E-38 to 3.4E381 2.2E-308 to 1.8E3082
float double
Arithmetic Operators
Operator + Action Addition
* / %
Subtraction
Multiplication Division Modulus Operation
^
++ --
Exponentiation
Increment Decrement
Examples
1. 10 % 3=1 how? 10/3=3 remainder 1 2. S++ is the same as S=S+1 3. S-- is the same as S=S-1
Identifiers
Identifiers are names that are used to referenced variables, functions, labels and user- defined objects. They consist of a letter or an underscore followed by any combinations of letters, digits or underscores. They can be as long as 127 characters. C has standard identifiers and user-defined identifiers. User-Defined Identifiers start with a letter and may contain any combination of letters and digits. It can be of any length but only the first eight characters will be recognized.
The many things that you have read are the basic concepts in Turbo C. They will make your programming activities easier. Let us see if you understand the lesson on identifiers by answering the exercises below.
I am sure you also want to see mathematical computation in Turbo C. All you need to do is to remember the syntax of the statements and apply math concepts. Lets do them now. The program is intended to ask the user 2 numbers. After entering 2 numbers, the program shall compute and display the sum.
/* This program shall compute the sum of two numbers. (The symbols, asterisk and slash, are used for comments.) */ #include<stdio.h> #include<conio.h> void main() {
int num1,num2,sum; printf("Input your first number:"); scanf("%d", &num1); printf("\nInput your second number:"); scanf("%d", &num2); sum=num1+num2; /*The sum of the values of num1 and num2 shall be saved in the variable sum.*/ printf("\nThe sum of %d and %d is %d., num1,num2,sum); getch(); } 4. Click Compile Menu and select Compile or simply press Alt+F9. 5. View the output by pressing Ctrl+F9 or select the Run command in Run menu. 6. Save the program as sum.cpp in the Sum subfolder. 7.Press F9 to make an EXE file. 8. Update your index.
Comprehension Questions
Diretions: Please answer the questions below as a group. Type the answers on the space provided after each question. 1. What are the variables in the program? 2. What is the data type of the variables? 3. What is the format modifier/conversion specifier for int data type?
What you have seen is just a simple example of solving mathematical problem in Turbo C. I am sure making your own Turbo C program sounds challenging to you. Its time to show your programming skills by doing the average program. You always want to know the average that you get from examinations. Instead of using your calculator in getting the average, all you need to do is to make a simple program in Turbo C. Lets read the details in the next slide.
1. Make the subfolder named AVERAGE in the 3rd term folder. 2. Read the programming problem below: Make a C program that shall get 3 quiz grades from the user. The program should display the quiz grades as well as the average.
Sample output:
Please enter quiz1 grade: 85 Please enter quiz1 grade: 90 Please enter quiz1 grade: 88 You have entered 85, 90 and 88. The average is 87.67. 3. Save the program as average.cpp in the AVERAGE subfolder. Make an EXE file by pressing F9.
Before you make the program, take note of the following: 1. The variable for average must use the %f conversion specifier. ex: scanf(%f, &ave);
Once the program is finished, get 1/8 sheet cross wise. Write your name, section, date , and title of the activity which is Average. Evaluate the output using the rating scale below: 10/10 The output is correct. All requirements are present.
Assignment
Write your answers in cross wise of paper. 1. Do the flowchart of The Average Activity. 2.Write a C program that shall ask for a radius in centimeter(cm) from the user. The program must compute the area of the circle. Output: Please enter a radius in cm: 25 (enter) The area of the circle is 1963.5 sq cm 3. Please study the sample C programs and the Introduction to C lesson. Seatwork#2 shall be given next meeting.
Which of the following are needed by printf() and scanf()? text comma(,) ampersand(&) double quotes()
variable
conversion specifier(%f)
Printf()
Scanf()
1. Please answer the question below in sheet of pad paper. Use 2 to 3 statements only.
Inputs can be your preparations to achieve the desired outputs. Outputs can be your goals or dreams in life.
As a student, what inputs must be done to achieve the desired outputs in life?
2. Submit the paper to the teacher. 3. Be ready to share your answers to the class.