Download presentation
Presentation is loading. Please wait.
1
EECE.2160 ECE Application Programming
Instructor: Dr. Michael Geiger Spring 2018 Lecture 36: Exam 3 Preview
2
ECE Application Programming: Exam 3 Preview
Lecture outline Announcements/reminders Late/regrade submissions: Dr. Geiger + TA Program 7 regrades due tomorrow (5/3) Program 8 regrades due Monday (5/7) Program 9 due today Program 10 (extra credit) due Wednesday, 5/9 Deals with file I/O and bitwise operators Up to 4 points of extra credit on your final average Only one chance to turn in—no resubmissions Grading will be tougher than typical assignment Exam 3: Thursday, 5/10, 6:30-9:30 PM in Ball 210 Course evaluation to be posted Today’s class Exam 3 outline 4/8/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 Strings + all lectures after Exam 2 (lectures 22, 24-25, 27-34) Format similar to Exams 1 & 2 Code reading, writing, and 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 4/8/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) Strings: CR questions on String basics String functions 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: CR/CW questions on fopen()/fclose() Formatted I/O using fprintf()/fscanf() Unformatted I/O using fread()/fwrite() Standard I/O streams: stdin, stdout 4/8/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 Set/clear/flip bits Extracting bits Dynamic allocation: MC questions on Basic allocation: malloc(), calloc(), realloc(), free() Extra credit: may cover any topic above 4/8/2019 ECE Application Programming: Exam 3 Preview
6
ECE Application Programming: Exam 3 Preview
Review: strings Represented as character arrays Can be initialized using string constants char hello[] = “Hello”; Can access individual elements hello[3] = ‘l’; Can print directly or with formatting Print directly: printf(hello); Print w/formatting using %s: printf(“%s\n”, hello); Reading strings: scanf(“%s”, str); Reads all characters up to (but not including) first space, tab, or newline Must leave enough room for terminating ‘\0’ 4/8/2019 ECE Application Programming: Exam 3 Preview
7
Review: String functions
In <string.h> library: Copying strings: char *strcpy(char *dest, const char *source); char *strncpy(char *dest, const char *source, size_t num); Return dest strncpy() not guaranteed to add null terminator Comparing strings: int strcmp(const char *s1, const char *s2); int strncmp(const char *s1, const char *s2, size_t num); Character-by-character comparison of character values Returns 0 if s1 == s2, >0 if s1 > s2, <0 if s1 < s2 4/8/2019 ECE Application Programming: Exam 3 Preview
8
Review: String functions (cont.)
Find # of characters in a string size_t strlen(const char *s1); Returns # characters before ‘\0’ Not necessarily size of array “Add” strings together—string concatenation char *strcat(char *dest, const char *source); char *strncat(char *dest, const char *source, size_t num); Returns dest strncat() guaranteed to add null terminator 4/8/2019 ECE Application Programming: Exam 3 Preview
9
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; Access members using Dot operator: student1.middle = ‘J’; Arrow (if pointers): sPtr->GPA = 3.5; Typically passed to functions by address 4/8/2019 ECE Application Programming: Exam 3 Preview
10
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; 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 4/8/2019 ECE Application Programming: Exam 3 Preview
11
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) 4/8/2019 ECE Application Programming: Exam 3 Preview
12
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); 4/8/2019 ECE Application Programming: Exam 3 Preview
13
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 Common operations Setting/clearing/flipping individual bit Setting/clearing/flipping multiple bits Extracting bits i.e. x = (x & 0x00FFFF00) >> 8; 4/8/2019 ECE Application Programming: Exam 3 Preview
14
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 4/8/2019 ECE Application Programming: Exam 3 Preview
15
Review: dynamic memory allocation
Basic block allocation: void *malloc(size_t size); Allocate block and clear it: void *calloc(size_t nmemb, size_t size); Resize previously allocated block: void *realloc(void *ptr, Deallocation function: void free(void *ptr); Dynamically allocated array arr = (int *)malloc(n * sizeof(int)); Can then use array notation: arr[i] = 0; 4/8/2019 ECE Application Programming: Exam 3 Preview
16
ECE Application Programming: Exam 3 Preview
Next time Exam 3 Q & A session Reminders: Late/regrade submissions: Dr. Geiger + TA Program 7 regrades due tomorrow (5/3) Program 8 regrades due Monday (5/7) Program 9 due today Program 10 (extra credit) due Wednesday, 5/9 Deals with file I/O and bitwise operators Up to 4 points of extra credit on your final average Only one chance to turn in—no resubmissions Grading will be tougher than typical assignment Exam 3: Thursday, 5/10, 6:30-9:30 PM in Ball 210 Course evaluation to be posted 4/8/2019 ECE Application Programming: Exam 3 Preview
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.