Chapter5 - Program Design and Efficiency
Chapter5 - Program Design and Efficiency
START
statements
statements
conditional
FALSE
TRUE
statements
END
1|2|3
-----
4|5|6
-----
7|8|9
len = strlen(str);
for (i = 1;i<=10;i++)
x += len;
Y = 15 + len;
M = sin(d);
for (i =0; i<100;i++)
plot(i, i*M);
x99 sigmoid(x99)
int main(void)
/* Read a circle's radius from stdin, and compute and write its
diameter and circumference to stdout. Return 0 if successful. */
{
const double PI = 3.14159;
int radius;
int diam;
double circum;
Yes: y = x;
x = x + 1;
Attention!
yes UPPER CASE
yes ( )
#include <stdio.h>
/* conversion constants. */
#define FEET_PER_MILE 5280.0
#define SECONDS_PER_HOUR (60.0 * 60.0)
int main(void)
{
double miles_per_hour; /* input mph */
double feet_per_second; /* corresponding feet/sec */
double feet_per_hour; /* corresponding feet/hr */
return(0);
}
int main () {
FILE * pf;
int errnum;
pf = fopen ("unexist.txt", "rb");
if (pf == NULL) {
errnum = errno;
fprintf(stderr, "Value of errno: %d\n", errno);
perror("Error printed by perror");
fprintf(stderr, "Error opening file: %s\n", strerror( errnum ));
} else {
fclose (pf);
}
return 0;
}
class Device
{
int fd;
public:
Device(const std::string &deviceName) {
fd = open(deviceName.c_str(), O_RDWR);
if (fd < 0) {
throw std::system_error(errno, std::system_category(),
"Failed to open device file");
}
}
~Device() {
close(fd);
}
// continue in next slide …