Presentation is loading. Please wait.

Presentation is loading. Please wait.

EECE.2160 ECE Application Programming

Similar presentations


Presentation on theme: "EECE.2160 ECE Application Programming"— Presentation transcript:

1 EECE.2160 ECE Application Programming
Instructor: Dr. Michael Geiger Fall 2018 Lecture 37: Exam 3 Preview

2 ECE Application Programming: Exam 3 Preview
Lecture outline Announcements/reminders No Thursday office hours this week Th 12/13: last day of classes; Program 8 due M 12/17: Exam 3, 3-6 PM, Ball 210 Course evals online; will also have hard copies available You’ll submit eval at exam W 12/19: All code due by 12:00 PM (noon) Program 9: Worth up to 4 points extra credit on final avg Resubmission deadline for P7 & P8 Today’s class: exam 3 preview Exam outline Review of material 5/25/2019 ECE Application Programming: Exam 3 Preview

3 ECE Application Programming: Exam 3 Preview
Exam 3 notes Allowed one 8.5” x 11” two-sided note sheet No other notes or electronic devices Exam lasts 3 hours (but written for ~50 min) Coverage All lectures after Exam 2 (lectures 26, 29-36) Format similar to Exams 1 & 2 Code reading, writing, multiple choice questions One 10 point extra credit question at end For this exam, you may attempt the extra credit question even if you haven’t attempted to solve all other problems 5/25/2019 ECE Application Programming: Exam 3 Preview

4 ECE Application Programming: Exam 3 Preview
Exam 3 outline (CR = code reading, CW = code writing, MC = multiple choice) Structures: CR/CW questions on Basic structure accesses Dot operator (i.e., s1.x) Pointer access (i.e., p->GPA) Arrays of structures Nested structures File input/output: MC/CW questions on fopen()/fclose() Text file I/O using fprintf()/fscanf() Binary file I/O using fread()/fwrite() Standard I/O streams: stdin, stdout 5/25/2019 ECE Application Programming: Exam 3 Preview

5 ECE Application Programming: Exam 3 Preview
Exam 3 outline (CR = code reading, CW = code writing, MC = multiple choice) Character/line I/O: CR/MC questions on fgetc(), getchar(), ungetc() fgets() Bitwise operators: CR/MC questions on Operator basics Hexadecimal output Extra credit: may focus on any topic above Should clearly understand earlier material, too 5/25/2019 ECE Application Programming: Exam 3 Preview

6 ECE Application Programming: Exam 3 Preview
Review: Structures User-defined types; example: typedef struct { char first[50]; char middle; char last[50]; unsigned int ID; double GPA; } StudentInfo; Can define variables of that type Scalar: StudentInfo student1; Array: StudentInfo classList[10]; Pointer: StudentInfo *sPtr; 5/25/2019 ECE Application Programming: Exam 3 Preview

7 Review: structures (continued)
Initialization very similar to array initialization: StudentInfo student1 = { “John”, ‘Q’, “Smith”, , 3.75 }; Access members using Dot operator: student1.middle = ‘J’; Arrow (if pointers): sPtr->GPA = 3.5; Typically passed to functions by address 5/25/2019 ECE Application Programming: Exam 3 Preview

8 Review: Nested structures
Structures can contain other structures: typedef struct { char first[50]; // First name char middle; // Middle initial char last[50]; // Last name } Name; Name sname; // Student name unsigned int ID; // ID # double GPA; // Grade point } SINew; 5/25/2019 ECE Application Programming: Exam 3 Preview

9 Review: Nested structure accesses
Will need multiple dot operators to access field within nested structure Given SINew s1; s1.sname  Name structure within s1 s1.sname.middle  middle initial of name within s1 Structure pointer typically only to top-level structure Given SINew *sp = &s1; sp->sname  Name structure within s1 sp->sname.middle  middle initial of name within s1 5/25/2019 ECE Application Programming: Exam 3 Preview

10 ECE Application Programming: Exam 3 Preview
Review: File I/O Open file: FILE *fopen(filename, file_access) Close file: fclose(file_handle) Formatted I/O: fprintf(file_handle, format_specifier, 0+ variables) fscanf(file_handle, format_specifier, 0+ variables) Unformatted I/O: size_t fwrite(pointer, element size, # elements, file_handle) size_t fread(pointer, element size, # elements, file_handle) 5/25/2019 ECE Application Programming: Exam 3 Preview

11 ECE Application Programming: Exam 3 Preview
Review: Generic I/O Special I/O streams in C stdin: standard input stdout: standard output printf(“Hello\n”) == fprintf(stdout, “Hello\n”); scanf(“%d”, &x) == fscanf(stdin, “%d”, &x); Can write generic code that deals either with specific file or standard input/output 5/25/2019 ECE Application Programming: Exam 3 Preview

12 ECE Application Programming: Exam 3 Preview
Review: End of file Two ways to check for end of file: Text files: Check if fscanf() == EOF More common: do fscanf() as part of loop condition, and continue while EOF not reached e.g. while (fscanf(fp, “%d”, &y) != EOF) Binary files: feof(file_handle); Note: both functions indicate EOF after failed read operation Must try to read data and discover that there’s nothing to read before testing for EOF 5/25/2019 ECE Application Programming: Exam 3 Preview

13 Review: character/line input
Character input int fgetc(FILE *stream); int getchar(); int ungetc(int c, FILE *stream); Line input char *fgets(char *s, int n, FILE *stream); 5/25/2019 ECE Application Programming: Exam 3 Preview

14 Review: binary and hexadecimal
All data encoded in binary (base 2) Useful knowing bit patterns to evaluate bitwise ops Hexadecimal (base 16) used with bitwise ops Closer to binary than base 10 is Each hexadecimal digit = 4 bits Leading 0x indicates hexadecimal constant Digits 0-9 same as decimal, = A-F 0x0 = 00002, 0x1 = … 0x9 = 10012 0xA = 10102, 0xB = … 0xF = 11112 Variables typically declared as unsigned int Strictly non-negative whole numbers 32 bits in length 5/25/2019 ECE Application Programming: Exam 3 Preview

15 Review: bit manipulation
Bitwise operators: | & ^ ~ Used for desired logical operations Used to set/clear bits Bit shifts: << >> Used to shift bits into position Used for multiplication/division by powers of 2 5/25/2019 ECE Application Programming: Exam 3 Preview

16 Review: hexadecimal output
To print a number in hex, use %x or %X %x prints characters a-f in lowercase %X prints characters A-F in uppercase To show leading 0x, use the # flag To show leading 0s, use precision with total # chars Field width + 0 flag also works unless value = 0 Examples (assume var1 = 0x1A2B) printf(“%x”, var1)  1a2b printf(“%X”, var1)  1A2B printf(“%#x”, var1)  0x1a2b printf(“%.6x”, var1)  001a2b printf(“%#.6x”, var1)  0x001a2b 5/25/2019 ECE Application Programming: Exam 3 Preview

17 ECE Application Programming: Exam 3 Preview
Next time Exam 3: Monday, 12/17, 3-6 PM, Ball 210 Don’t forget to complete your course eval before exam! Hard copies available from my office Reminders: No Thursday office hours this week Th 12/13: last day of classes; Program 8 due W 12/19: All code due by 12:00 PM (noon) Program 9: Worth up to 4 points extra credit on final avg Resubmission deadline for P7 & P8 5/25/2019 ECE Application Programming: Exam 3 Preview


Download ppt "EECE.2160 ECE Application Programming"

Similar presentations


Ads by Google