Presentation is loading. Please wait.

Presentation is loading. Please wait.

Administrative things

Similar presentations


Presentation on theme: "Administrative things"— Presentation transcript:

1 Lecture02: Overview of C 2/29/2012 Slides modified from Yin Lou, Cornell CS2022: Introduction to C

2 Administrative things
Textbook is optional C is a simple language, no need for a thick textbook (homework exercises) Slides will cover it TimeString (TA) hour work Friday 10:30 ~ 11:30 Assignment #1 is on the course webpage due next week. Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from , etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?

3 Structure of a C Program
Overall Program <some pre-processor directives> <global declarations> <global variables> <functions> Functions <function header> <local declarations> <statements> Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from , etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?

4 main.c: Hello World #include <stdio.h> int main() { printf("Hello World\n"); return 0; } Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from , etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?

5 CodeBlocks: Compile and Run
Run CodeBlocks Create a new project File → New → Project Select “Console application” Click C → Next Type in Project title: (e.g., “hello”) Click finish Open and edit the main.c File → Open Find “main.c” Compile and run Build → Build and Run Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from , etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?

6 What Happened? Compile (Build → Build)
Compile “main.c” to machine code named “hello.exe” Run (Build → Run) Execute the program “hello.exe” main.c (Hello World) include <stdio.h> /* printf() is declared in this header file. */ int main() /* Main point of execution */ { printf("Hello World\n"); /* Output “Hello World” to console */ return 0; /* Tell OS the program terminates normally */ } Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from , etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?

7 main.c: Variables #include <stdio.h> int main() { int a, b, c;
c = a * b; printf("a = %d b = %d c = %d\n", a, b, c); return 0; } Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from , etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?

8 main.c: CommandLineArgs
#include <stdio.h> #include <stdlib.h> int main(int argc, char **argv) { int n, m; n = atoi(argv[1]); m = atoi(argv[2]); printf("Argument 1: %d\nArgument 2: %d\n", n, m); return 0; } Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from , etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?

9 More on printf printf(format string, val1, val2); Examples
format string can include placeholders that specify how the arguments val1, val2, etc. should be formatted %c : format as a character %d : format as an integer %f : format as a floating-point number %% : print a % character Examples double f = 0.95; printf("f = %f%%\n", f * 100); Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from , etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?

10 Even more on printf Placeholders can also specify widths and precisions %10d : add spaces to take up at least 10 characters %010d : add zeros to take up at least 10 characters %.2f : print only 2 digits after decimal point %5.2f : print 1 decimal digit, add spaces to take up 5 chars Examples int i = 95; double f = 0.95; printf("i = %d\n", i); printf("i = %10d\n", i); printf("i = %010d\n", i); printf("f = %f\n", f); printf("f = %.2f%%\n", f * 100); printf("f = %10.2f%%\n", f * 100); Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from , etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?

11 Warning about printf printf is powerful, but potentially dangerous
What does this code output? int i = 90; double f = 3; printf("f = %f i = %d\n", f); printf("f = %f\n", f, i); printf("i = %d f = %f\n", f, i); Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from , etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?

12 main.c: Scanf #include <stdio.h> int main() { int i; double f; scanf("%d", &i); scanf("%lf", &f); printf("Integer: %d Float: %2.2f\n", i, f); return 0; } Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from , etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?

13 In-Class Exercise Write a program that calculates travel reimbursement for a pizza delivery person at a rate of NT$6.97 per kilometer. Your program should interact with the user in the following manner: (It is okay not to get the program right the first time. Look at the compilation errors and fix them.) KILOMETER REIMBURSEMENT CALCULATOR Enter beginning odometer readings=> Enter ending odometer reading=> You traveled kilometers. At $6.97 per kilometer, Your reimbursement is $ Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from , etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?


Download ppt "Administrative things"

Similar presentations


Ads by Google