







Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Notes; Class: Intro to Software Development; Subject: Computer Sci & Software Engr; University: Rose-Hulman Institute of Technology; Term: Unknown 1989;
Typology: Study notes
1 / 13
This page cannot be seen from the preview
Don't miss anything!








^
Just like in Python (almost)
^
Consider the function:^ ^
double
convertCtoF(double
celsius)
{
return
32.
+
9.
celsius
/
5.0;
}
^
How would we get result from a function in Python?^ ^
fahr = convertCtoF(20.0)
^
What's different in C?^ ^
Need to declare the type of fahr Need a semi-colon
^
if gpa > 2.0:
print "safe" elif gpa >= 1.0:
print "trouble" else:
print "sqrt club"
^
Python:^ ^
Colons and indenting elif
^
if (gpa > 2.0) {
printf("safe"); } else if (gpa >= 1.0) {
printf("trouble"); } else {
printf("sqrt club"); }
^
Parentheses, braces else if
^
Braces group statements
^
Can omit for singlestatement bodies
^
if (gpa > 2.0)
printf("safe"); else if (gpa >= 1.0)
printf("trouble"); else
printf("sqrt club");
^
What is printed in eachcase?
^
if (n > 0) {
if (a > 0)
printf("X");
} else {
printf("Y"); }
Case
n^
a
1
1
1
2
-^
1
3
1
4
Use braces toavoid confusion!
^
Enter the following C code in Eclipse: void testBoolean(int n, int m) {
int p = n < m; printf("Is %d less than %d? %d\n", n,
m, p);
}
^
Add a couple of test calls to your
main()
function:
testBoolean(2,3);
testBoolean(3,2);
^
0 in C is like
False
in Python
^
All other numbers are like
True
^
To read input from user in C, use
scanf()
^
Syntax:
scanf(
^
Example:
int age;scanf("%d", &age);
^
To read input from user in C, use
scanf()
^
Syntax:
scanf(
^
Example: double f, g;printf("Enter two real numbers separated by a comma:");fflush(stdout);scanf("%lf,%lf", &f, &g);printf("Average: %5.2f\n", (f + g)/2.0);
Pushes prompt stringto user before askingfor input.
ell-eff = "long float"Why not d for double?
Comma is matchedagainst user input
^
Each team has 5 minutes MAX to demo their Tetrisproject
^
Each team will use the instructor’s laptop to do so
^
A team may use one of their laptops only if theirdemo fails to work on the instructor’s laptop
^
In addition to showing that the project works, teamswill demo and discuss additional features they haveadded to their project