I Background Getting a computer to do a complex calculation



I. Background Getting a computer to do a complex calculation or to make a decision based on data is great, but doesn\'t go much beyond what a person is capable of doing. The computer might be able to do it faster than a person, but the gain in speed is not significant. The real power of the computer is its ability to perform a repetitive task with great speed and accuracy. Once we understand how to harness this ability, the computer moves beyond a simple calculator to an incredibly versatile tool. In this lab, you will be creating iterative solutions to three different problems. For each problem, you will need to create a flowchart do depict how you would solve it using repetition and simulate several rounds of iteration using Excel. II. Application 1: Processing Data A second application for repetition is the processing of large amounts of data. With the vast number of sensors used in current systems (your phone likely has at least 5-front camera, back camera, microphone, accelerometer, GPS), the amount of data generated is astronomical. It would be impossible person to sift through all of that data to make any meaningful conclusions. However, a computer can very quickly and easily process vast amounts of data and calculate different statistical values to help someone interpret the data. In this problem, you will simulate processing a set of yearly temperature data to determine whether the Earth is indeed warming. for a Inputs Set of temperature data Outputs: Number of years the average temperature increased Number of years the average temperature decreased Number of years the average temperature remained steady Maximum average temperature Minimum average temperature Processing Repeatedly process each temperature data point and determine whether the temperature increased or decreased and whether the temperature is currently the maximum temperature or the minimum temperature o The current temperature is potentially the maximum

Solution

8 #include <stdlib.h> 9 #include <unistd.h> 10 #include <sys/types.h> 11 #include <sys/stat.h> 12 #include <sys/mman.h> 13 #include <fcntl.h> 14 #include <errno.h> 15 #include <string.h> 16 17 void report_error(char *error) 18 { 19 fprintf(stderr, \"Error: %s\ \", error); 20 21 exit(-1); 22 } 23 24 int main(int argc, char *argv[]) 25 { 26 struct stat statbuf; 27 char *fn; 28 int fd; 29 size_t len, i, count; 30 31 char *data; 32 33 if (argc < 2) { 34 if (argc < 1) { 35 report_error(\"no command line\"); 36 fprintf(stderr, \"Usage: %s <file>\ \", argv[0]); 37 } else { 38 report_error(\"Not enough arguments\"); 39 fprintf(stderr, \"Usage: %s <file>\ \", argv[0]); 40 } 41 } 42 43 fn = argv[1]; 44 45 if (stat(fn, &statbuf)) { 46 report_error(strerror(errno)); 47 } 48 49 len = statbuf.st_size; 50 printf(\"File %s: \ \", fn); 51 printf(\" inode %ld\ \", statbuf.st_ino); 52 printf(\" length %ld\ \", len); 53 54 if (S_ISREG(statbuf.st_mode)) { 55 fd = open(fn, O_RDONLY); 56 if (fd == -1) { 57 report_error(strerror(errno)); 58 } 59 data = (char *) mmap(NULL, len, 60 PROT_READ, MAP_SHARED, fd, 0); 61 if (data == MAP_FAILED) { 62 report_error(strerror(errno)); 63 } 64 65 count = 0; 66 for (i=0; i<len; i++) { 67 if (data[i] == \'a\') { 68 count++; 69 } 70 } 71 72 printf(\" a count %ld\ \", count); 73 74 if (munmap(data, len) == -1) { 75 report_error(strerror(errno)); 76 } 77 close(fd); 78 } 79 80 return 0; 81 }


Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site