ITS100 Computer and Programming Lab. - ITPE

advertisement
1
LAB 1: INTRODUCTION
TO C PROGRAMMING
ITS100: Computer and Programming Lab.
Section 1
Instructor: Wirat Chinnan
TAs:
Ms. Sasirassamee Buavirat
Mr. Thanasan Tanhermhong (Tum)
Ms. Pattheera Panitsuk (Fon+)
Mr. Pongsate Tangseng
Mr. Chinorot Wangtragulsang
Mr. Kanin Assantachai (Ob)
2
Group Division
• 60 people in Section 1 / 6 TAs
• 1 TA per 10 people
• TA rotation will be made when quiz
• Remember and do not change your seat !
3
About ITS100 Lab
• Programming techniques with C programming language
• Counterpart of ITS100 lecture.
• Requires a lot of practice !
• Simply memorizing commands will not work.
• Main website: http://ict.siit.tu.ac.th/its100/
• Schedule
• Lecture note download
• Important announcements
• Code template (after midterm)
4
Lab Score Criteria
• Total 50 points from lab
• Attendance + Exercise + Speed test  3 points/week
• Lab’s midterm exam  10 points
• Lab’s final exam  10 points
• No homework 
• Attendance check starts 15 minutes after the class starts
• Do not be late.
• 1 point for attendance
• SIIT regulation: If the attendance is < 70% (for both lectures and
labs), students may not be allowed to take the final exam.
• In-class exercise
• About 5 exercises.
• You can ask TAs for help 
• 1 point for completion of the exercises
5
Speed Test (1)
• Every week ! (except first week)
• 45 minutes
• Speed test time: 15:00 – 15:45
• Grading time: 15:45 – 16:00
• Test covers all the content up to and including that week.
• But, mainly focus on the content of that week itself.
• Always review what you learned weeks before.
• Summary sheet allowed 
• At http://ict.siit.tu.ac.th/its100/Files/ITS100_Summary_Sheet.pdf
• Bring it next week !
6
Speed Test (2)
• Speed test should be treated just like a real exam.
• Rules:
• No talking. Be quiet.
• No mobile phone.
• No electronic devices other than your PC
• No cheating
• Cheating will result in a severe penalty
• TAs will not help you (except when your PC crashes).
7
Today’s Lab
• Review what you learned in lecture 1 & 2
• Already learned lecture 2 ?
• Introduction to Code::Blocks
• http://www.codeblocks.org/
• Write very simple C programs.
8
Code::Blocks
• Free C/C++ IDE (Integrated Development Environment)
• IDE = compiler + editor + debugger + …
• http://www.codeblocks.org/
• Recommended to install and practice at home.
• To download, go to “Downloads” page:
• Select “Download the binary release”
• Select “codeblocks-10.05mingw-setup.exe”
• NOT codeblocks-10.05-setup.exe
• Installation is easy.
9
C Language
• High-level general-purpose programming language
• Designed in 1972 by Dennis Ritchie
• who died in October 2011 (roughly the same time as Steve Jobs)
• One of the most widely used programming languages of
all time.
• Unix is written in C
• Foundation of Windows is written in C
• Mac OS is based on Unix
10
Introduction to C
int main(){
/*statements go here*/
return 0;
}
11
Practice 1
Create a new file, type, compile and run the program
“hello+ world!!”
#include <stdio.h>
int main()
{
printf("hello+ world!!\n");
return 0;
}
12
variable
13
variable type
printf() and scanf()
%c
%d
%d
%ld
%f
%lf
14
printf()
• printf() is for output
15
Creates a variable and prints its value to
the screen
#include <stdio.h>
int main()
{
int var;
var = 10;
printf("The variable var = %d\n", var);
return 0;
}
16
Practice 2
• Adding Two Numbers
#include <stdio.h>
int main()
{
int n1, n2, sum;
n1 = 10;
n2 = 50;
sum = n1 + n2;
printf(“ Summation = %d\n”, sum);
return 0;
}
17
scanf()
• scanf() is for input.
• Do not forget & in front of variable names.
18
Reads two characters and prints them out
in reverse order
#include <stdio.h>
int main()
{
char first, second;
printf(“Enter 2 characters : ”);
scanf(“%c%c”, &first, &second);
printf(“%c %c\n”, second, first);
return 0;
}
19
Practice 3
Adding Two Numbers with getting input from
keyboard
#include <stdio.h>
int main()
{
int n1, n2, sum;
printf(“Enter a Number: “);
scanf(“%d”,&n1);
printf(“Enter a Number: “);
scanf(“%d”,&n2);
sum = n1 + n2;
printf(“ Summation = %d\n”, sum);
return 0;
}
20
Exercise
• Q1: Create a new file, type, compile and run the program “hello+
world!!”
• Q2: Create a new file, type, compile and run the program 2.3
•
•
•
•
(Adding two numbers)
Q3: Create a new file, type, compile and run the program 2.4
(printf() example)
Q4: Create a new file, type, compile and run the program 2.5
(scanf() example). For each run, test the program with the
example input values:
a. 12 and 20 b. 50 and 80 c. 90 and 100 d. -10 and 1
Q5: Modify the program in Q4 to the program 2.6 (scanf()
example 2). Compile and run the program. For each run, test the
program with the example input values:
a. 12 and 20 b. 50 and 80
Q6: Create a new file, type, compile and run the Miles-toKilometres conversion program (slide 17, lecture 2). Test with an
arbitrary example input value given by the TA.
21
Exercise
Do it yourself
1) Create two variables, give them some value, and print
them out to the screen.
(See Example 2)
2) Read in two integers and print them out to the screen.
(See Example 3)
3) Input 3 integers and calculate the summation
(See Example 4).
4) Input 3 integers and print them out in reverse order
(See Example 5).
Download