Assignment #2 Answers
|
|
- Duane Dustin Horton
- 6 years ago
- Views:
Transcription
1 Assignment #2 Answers Intermediate C Programming UW Experimental College Assignment #2 ANSWERS Question 1. List some differences between text and binary data files. Text files store lines of characters, intended to be human-readable if printed, displayed to the screen, read into a text editor, etc. Binary files contain arbitrary byte values which make little or no sense if interpreted as characters. Binary files may be smaller, and if read and written in a simpleminded way, they may be more efficient to read and write, and the code to do so may be easier to write. Text files tend to be larger, to take longer (than binary files) to read and write, and to require more elaborate code. (However, if binary files are read in safer ways, or written in more portable ways, the code to do so is as complicated as for text files, and will probably be intermediate in efficiency between text files and simpleminded binary files.) Text files are quite portable. Binary files will not necessarily work if they are moved between machines having different word sizes or data formats, or between compilers which lay out data structures differently in memory. It's easy to create, inspect, and modify text files using standard tools. Binary file maintenance generally requires speciallywritten tools. Binary files must be written using fopen mode "wb" and read using mode "rb" Exercise 2. Devise and implement a way for long descriptions to be read from the data file. There are many ways of doing this. All are a bit tricky, given certain constraints imposed by the existing code. The most obvious way is to use lines of the form desc You are in a dark and gloomy cave. in the data file. (Such lines could of course be used for objects as well.) The only problem with this approach is that in the existing data file reading code in io.c, each line read from the data file is immediately broken up into words by calling getwords, and this break-up happens before it's decided what keyword began the line and what's to be done with the rest of the information on the line. In the case of long descriptions, we want the rest of the text on the line (after the keyword desc) to be treated as a single sting, not a series of individual words. One way around this problem is to make a copy of the line read from the data file before breaking it up with getwords. I declared a second array char line2[maxline] at the top of parsedatafile in io.c, and changed the old line (1 of 6)10/31/2005 2:23:46 PM
2 to Assignment #2 Answers ac = getwords(line, av, MAXARGS) strcpy(line2, line) ac = getwords(line2, av, MAXARGS) Now line2 is broken up by getwords (and av ends up containing pointers into line2), but the contents of line remain intact. Then I added this case to the if/else chain that makes up the bulk of parsedatafile: else if(strcmp(av[0], "desc") == 0) char *p for(p = line *p!= '\0' &&!isspace(*p) p++) /* skip "desc" */ for( isspace(*p) p++) /* skip whitespace */ if(currentobject!= NULL) currentobject->desc = chkstrdup(p) else if(currentroom!= NULL) currentroom->desc = chkstrdup(p) else fprintf(stderr, "desc not in object or room\n") The code has two more troublesome spots: first, since the line array hasn't been broken into words (which was the point, so as not to break up the descriptive text), we have to manually skip over the keyword ``desc'' and the whitespace to find the beginning of the description itself. Second, since I've declared the long descriptions in the object and room structures as char *, I have to allocate memory to hold a copy of the description. I do that by calling the function chkstrdup, which makes a duplicate copy of a string in newly-allocated memory, checking the return value of the memory allocation for me so that I don't have to. (On another sheet you'll find the code for chkstrdup and another function chkmalloc which it calls. chkstrdup is declared in chkmalloc.h both chkmalloc.c and chkmalloc.h can be found in the week5 subdirectory of the source tree.) We'll have much more to say about dynamic memory allocation in upcoming weeks, so don't worry about the details of chkstrdup too much. If you chose to use character arrays as the long description fields in the object and room structures, you don't have to worry about memory allocation, but can instead use something like strcpy(currentobject->desc, p) to copy the long description to your array. Just make sure you understand why a single call to strcpy would not work if desc is declared as char *, and why the simple assignment currentobject->desc = p would not work if desc was an array or a pointer (for a different reason in each case). In a real game, room descriptions are likely to be more like a paragraph in length, so cramming them all onto one desc line in the data file is quite cumbersome. How could we spread them across multiple lines in the data file? One way is by allowing (2 of 6)10/31/2005 2:23:46 PM
3 multiple desc lines, and arranging that they all get concatenated together to form the complete description. Here's how I implemented that: else if(strcmp(av[0], "desc") == 0) char *p char *newstr for(p = line *p!= '\0' &&!isspace(*p) p++) /* skip "desc" */ for( isspace(*p) p++) /* skip whitespace */ if(currentobject!= NULL) if(currentobject->desc == NULL) currentobject->desc = chkstrdup(p) else strlen(currentobject->desc) strlen(p) + 1) strcpy(newstr, currentobject->desc) strcat(newstr, p) free(currentobject->desc) currentobject->desc = newstr else if(currentroom!= NULL) if(currentroom->desc == NULL) currentroom->desc = chkstrdup(p) else strlen(currentroom->desc) strlen(p) + 1) strcpy(newstr, currentroom->desc) strcat(newstr, p) free(currentroom->desc) currentroom->desc = newstr else fprintf(stderr, "desc not in object or room\n") Now the memory allocation is more complicated, because when we already have a (partial) long description string for a given room or object, we have to allocate a new, longer one and free the old one. (There's an easier way to do this, involving another standard library memory allocation function called realloc. We'll see it later.) Another option would be to decide that long descriptions span many lines on the data file, followed by some terminator, without having each descriptive line preceded by any keyword. For example, we might have lines in the data file like this: desc (3 of 6)10/31/2005 2:23:46 PM
4 You are in a dark and gloomy cave. The air is stale and damp. In the shadows you can hear various squeaking and chattering noises. desc end Here, the word desc alone on a line indicates that a long description follows, up to the line containing desc end. I implemented that option like this. Notice that the description-reading code therefore has to make more calls to fgetline (i. e. besides the main one at the top of the loop in parsedatafile). In this case, we don't have to worry about the allocation of line vs. line2, and we also don't have to skip over anything to find the start of each descriptive line. else if(strcmp(av[0], "desc") == 0) char *newstr while(fgetline(fp, line, MAXLINE)!= EOF) if(strcmp(line, "desc end") == 0) break if(currentobject!= NULL) if(currentobject->desc == NULL) currentobject->desc = chkstrdup(line) else strlen(currentobject->desc) strlen(line) + 1) strcpy(newstr, currentobject->desc) strcat(newstr, line) free(currentobject->desc) currentobject->desc = newstr else if(currentroom!= NULL) if(currentroom->desc == NULL) currentroom->desc = chkstrdup(line) else strlen(currentroom->desc) strlen(line) + 1) strcpy(newstr, currentroom->desc) strcat(newstr, line) free(currentroom->desc) currentroom->desc = newstr (4 of 6)10/31/2005 2:23:46 PM
5 Exercise 3. Expand the set of allowable exits from rooms. I modified the room structure in game.h like this: #define NEXITS 10 struct room char name[maxname] struct object *contents struct room *exits[nexits] char *desc /* long description */ /* direction indices in exits array: */ #define NORTH 0 #define SOUTH 1 #define EAST 2 #define WEST 3 #define NORTHEAST 4 #define SOUTHEAST 5 #define NORTHWEST 6 #define SOUTHWEST 7 #define UP 8 #define DOWN 9 (By adding the new directions at the end of the array, rather than interspersing them with the original four, any array initializations such as we used to have in main.c would still work, since it's legal to supply fewer initializers for an array than the maximum number of elements in the array.) I added this code to docommand in commands.c: else if(strcmp(verb, "ne") == 0 strcmp(verb, "northeast") == 0) dircommand(player, NORTHEAST) else if(strcmp(verb, "se") == 0 strcmp(verb, "southeast") == 0) dircommand(player, SOUTHEAST) else if(strcmp(verb, "nw") == 0 strcmp(verb, "northwest") == 0) dircommand(player, NORTHWEST) else if(strcmp(verb, "sw") == 0 strcmp(verb, "southwest") == 0) dircommand(player, SOUTHWEST) else if(strcmp(verb, "up") == 0) dircommand(player, UP) else if(strcmp(verb, "down") == 0) dircommand(player, DOWN) I added this code to the roomexits case in parsedatafile in io.c: else if(strcmp(av[i], "ne") == 0) dir = NORTHEAST else if(strcmp(av[i], "se") == 0) (5 of 6)10/31/2005 2:23:46 PM
6 dir = SOUTHEAST else if(strcmp(av[i], "nw") == 0) dir = NORTHWEST else if(strcmp(av[i], "sw") == 0) dir = SOUTHWEST else if(strcmp(av[i], "u") == 0) dir = UP else if(strcmp(av[i], "d") == 0) dir = DOWN This page by Steve Summit // Copyright // mail feedback (6 of 6)10/31/2005 2:23:46 PM
Assignment #5 Answers
Assignment #5 Answers Intermediate C Programming UW Experimental College Assignment #5 ANSWERS Exercise 2. If you didn't use dynamically-allocated memory to hold long object and room descriptions, make
More informationAssignment #4 Answers
Assignment #4 Answers Intermediate C Programming UW Experimental College Assignment #4 ANSWERS Exercise 2. Modify the findobject function in object.c so that it can find objects when they're inside containers.
More informationAssignment #6 Answers
Assignment #6 Answers Introductory C Programming UW Experimental College Assignment #6 ANSWERS Question 1. If we say int i = 5; int *ip = &i; then what is ip? What is its value? ip is a variable which
More informationAssignment #5 Answers
Assignment #5 Answers Introductory C Programming UW Experimental College Assignment #5 ANSWERS Question 1. What's wrong with #define N 10;? The semicolon at the end of the line will become part of N's
More informationOther conditional and loop constructs. Fundamentals of Computer Science Keith Vertanen
Other conditional and loop constructs Fundamentals of Computer Science Keith Vertanen Overview Current loop constructs: for, while, do-while New loop constructs Get out of loop early: break Skip rest of
More informationhttps://www.eskimo.com/~scs/cclass/notes/sx8.html
1 de 6 20-10-2015 10:41 Chapter 8: Strings Strings in C are represented by arrays of characters. The end of the string is marked with a special character, the null character, which is simply the character
More informationCSCI 171 Chapter Outlines
Contents CSCI 171 Chapter 1 Overview... 2 CSCI 171 Chapter 2 Programming Components... 3 CSCI 171 Chapter 3 (Sections 1 4) Selection Structures... 5 CSCI 171 Chapter 3 (Sections 5 & 6) Iteration Structures
More informationEnumerations. Fundamentals of Computer Science
Enumerations Fundamentals of Computer Science Outline Avoiding magic numbers Variables takes on a small set of values Use descriptive names instead of literal values Java enumerations Using in a switch
More informationMul$- state systems CSCI 255: Introduc/on to Embedded Systems Keith Vertanen Copyright 2011
Mul$- state systems CSCI 255: Introduc/on to Embedded Systems Keith Vertanen Copyright 2011 Overview Avoiding magic numbers Variables takes on a small set of values Use descrip:ve names instead of literal
More informationLecture 8: Structs & File I/O
....... \ \ \ / / / / \ \ \ \ / \ / \ \ \ V /,----' / ^ \ \.--..--. / ^ \ `--- ----` / ^ \. ` > < / /_\ \. ` / /_\ \ / /_\ \ `--' \ /. \ `----. / \ \ '--' '--' / \ / \ \ / \ / / \ \ (_ ) \ (_ ) / / \ \
More informationmalloc(), calloc(), realloc(), and free()
1 next CITS2002 CITS2002 schedule Dynamic data structures Initially, we focused on scalar and array variables, whose size is known at compile-time. More recently, we've focused on arrays of values, whose
More informationHexagonal Lattice Systems Based on Rotationally Invariant Constraints
Hexagonal Lattice Systems Based on Rotationally Invariant Constraints Leah A. Chrestien St. Stephen s College University Enclave, North Campus Delhi 110007, India In this paper, periodic and aperiodic
More informationMICROPROCESSORS A (17.383) Fall Lecture Outline
MICROPROCESSORS A (17.383) Fall 2010 Lecture Outline Class # 03 September 21, 2010 Dohn Bowden 1 Today s Lecture Syllabus review Microcontroller Hardware and/or Interface Programming/Software Lab Homework
More informationMichele Van Dyne Museum 204B CSCI 136: Fundamentals of Computer Science II, Spring
Michele Van Dyne Museum 204B mvandyne@mtech.edu http://katie.mtech.edu/classes/csci136 CSCI 136: Fundamentals of Computer Science II, Spring 2016 1 Review of Java Basics Data Types Arrays NEW: multidimensional
More informationCS 237 Meeting 19 10/24/12
CS 237 Meeting 19 10/24/12 Announcements 1. Midterm: New date: Oct 29th. In class open book/notes. 2. Try to complete the linear feedback shift register lab in one sitting (and please put all the equipment
More informationData Structure Series
Data Structure Series This series is actually something I started back when I was part of the Sweet.Oblivion staff, but then some things happened and I was no longer able to complete it. So now, after
More informationLab 10 - Role-Playing Game
UNIVERSITY OF CALIFORNIA, SANTA CRUZ BOARD OF STUDIES IN COMPUTER ENGINEERING CMPE-13/L: COMPUTER SYSTEMS AND C PROGRAMMING SPRING 2014 Lab 10 - Role-Playing Game Introduction This lab puts together everything
More informationIntro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming
Intro to Programming Unit 7 Intro to Programming 1 What is Programming? 1. Programming Languages 2. Markup vs. Programming 1. Introduction 2. Print Statement 3. Strings 4. Types and Values 5. Math Externals
More informationProgramming Standards: You must conform to good programming/documentation standards. Some specifics:
CS3114 (Spring 2011) PROGRAMMING ASSIGNMENT #3 Due Thursday, April 7 @ 11:00 PM for 100 points Early bonus date: Wednesday, April 6 @ 11:00 PM for a 10 point bonus Initial Schedule due Thursday, March
More informationDynamic Allocation in C
Dynamic Allocation in C 1 The previous examples involved only targets that were declared as local variables. For serious development, we must also be able to create variables dynamically, as the program
More informationCSCI-243 Exam 2 Review February 22, 2015 Presented by the RIT Computer Science Community
CSCI-43 Exam Review February, 01 Presented by the RIT Computer Science Community http://csc.cs.rit.edu C Preprocessor 1. Consider the following program: 1 # include 3 # ifdef WINDOWS 4 # include
More informationDocumentation Nick Parlante, 1996.Free for non-commerical use.
Documentation Nick Parlante, 1996.Free for non-commerical use. A program expresses an algorithm to the computer. A program is clear or "readable" if it also does a good job of communicating the algorithm
More informationHowever, in C we can group related variables together into something called a struct.
CIT 593: Intro to Computer Systems Lecture #21 (11/27/12) Structs Unlike Java, C++, and to some extent Python, C is not traditionally considered an objectoriented language. That is, there is no concept
More informationCOSC 3P97 Assignment 1
Due: Oct. 12 @ 5:00 pm. COSC 3P97 Assignment 1 Fall 2018/19 Create a new Android Studio project or Eclipse workspace for the assignment. The app should run on API 23 (Marshmallow). Calculator Write an
More informationPersonal SE. Functions, Arrays, Strings & Command Line Arguments
Personal SE Functions, Arrays, Strings & Command Line Arguments Functions in C Syntax like Java methods but w/o public, abstract, etc. As in Java, all arguments (well, most arguments) are passed by value.
More informationChapter 1 Getting Started
Chapter 1 Getting Started The C# class Just like all object oriented programming languages, C# supports the concept of a class. A class is a little like a data structure in that it aggregates different
More informationM.CS201 Programming language
Power Engineering School M.CS201 Programming language Lecture 9 Lecturer: Prof. Dr. T.Uranchimeg Agenda The char Data Type Using Character Variables Printing extended ASCII characters Arrays of Characters
More informationG Programming Languages - Fall 2012
G22.2110-003 Programming Languages - Fall 2012 Lecture 2 Thomas Wies New York University Review Last week Programming Languages Overview Syntax and Semantics Grammars and Regular Expressions High-level
More informationRaspberry Pi Activity 3: Room Adventure
The Science of Computing II Living with Cyber Raspberry Pi Activity 3: Room Adventure In this activity, you will implement a simple text-based game utilizing the object-oriented paradigm. You will need
More informationadfsymbols Clea F. Rees 3 rd August, 2010
adfsymbols Clea F. Rees 3 rd August, 2010 Abstract Hirwen Harendal, Arkandis Digital Foundry (adf) has produced Symbols adf. This guide outlines the TEX/L A TEX support provided with version 1.001 of the
More informationCourse organization. Course introduction ( Week 1)
Course organization Course introduction ( Week 1) Code editor: Emacs Part I: Introduction to C programming language (Week 2-9) Chapter 1: Overall Introduction (Week 1-3) Chapter 2: Types, operators and
More informationIntroduction to C Language (M3-R )
Introduction to C Language (M3-R4-01-18) 1. Each question below gives a multiple choice of answers. Choose the most appropriate one and enter in OMR answer sheet supplied with the question paper, following
More informationFile Access. FILE * fopen(const char *name, const char * mode);
File Access, K&R 7.5 Dealing with named files is surprisingly similar to dealing with stdin and stdout. Start by declaring a "file pointer": FILE *fp; /* See Appendix B1.1, pg. 242 */ header
More informationLab 10 - Role-Playing Game Git Commit ID Form:
UNIVERSITY OF CALIFORNIA, SANTA CRUZ BOARD OF STUDIES IN COMPUTER ENGINEERING CMPE-13/L: COMPUTER SYSTEMS AND C PROGRAMMING Lab 10 - Role-Playing Game Git Commit ID Form: http://goo.gl/forms/vxbaoukho8hz9de12
More informationIntroduction to C. CS2023 Winter 2004
Introduction to C CS2023 Winter 2004 Outcomes: Introduction to C After the conclusion of this section you should be able to Recognize the sections of a C program Describe the compile and link process Compile
More informationHigh Performance Computing MPI and C-Language Seminars 2009
High Performance Computing - Seminar Plan Welcome to the High Performance Computing seminars for 2009. Aims: Introduce the C Programming Language. Basic coverage of C and programming techniques needed
More informationHere's how you declare a function that returns a pointer to a character:
23 of 40 3/28/2013 10:35 PM Violets are blue Roses are red C has been around, But it is new to you! ANALYSIS: Lines 32 and 33 in main() prompt the user for the desired sort order. The value entered is
More informationCS143 Handout 05 Summer 2011 June 22, 2011 Programming Project 1: Lexical Analysis
CS143 Handout 05 Summer 2011 June 22, 2011 Programming Project 1: Lexical Analysis Handout written by Julie Zelenski with edits by Keith Schwarz. The Goal In the first programming project, you will get
More informationCSC 467 Lecture 13-14: Semantic Analysis
CSC 467 Lecture 13-14: Semantic Analysis Recall Parsing is to translate token stream to parse tree Today How to build trees: syntax direction translation How to add information to trees: semantic analysis
More informationPrintable View of: Week 13: Miscelaneous cool features. Returns from standard functions. returns from standard functions: scanf(), fopen()
1 of 6 9/11/2009 12:57 PM Printable View of: Week 13: Miscelaneous cool features Print Save to File File: returns from standard functions: scanf(), fopen() returns from standard functions: scanf(), fopen()
More informationB.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University
Unit 1 Programming Language and Overview of C 1. State whether the following statements are true or false. a. Every line in a C program should end with a semicolon. b. In C language lowercase letters are
More informationAssignment 1: grid. Due November 20, 11:59 PM Introduction
CS106L Fall 2008 Handout #19 November 5, 2008 Assignment 1: grid Due November 20, 11:59 PM Introduction The STL container classes encompass a wide selection of associative and sequence containers. However,
More informationSlide Set 8. for ENCM 339 Fall 2017 Section 01. Steve Norman, PhD, PEng
Slide Set 8 for ENCM 339 Fall 2017 Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary October 2017 ENCM 339 Fall 2017 Section 01 Slide
More informationCS 61c: Great Ideas in Computer Architecture
Arrays, Strings, and Some More Pointers June 24, 2014 Review of Last Lecture C Basics Variables, functioss, control flow, types, structs Only 0 and NULL evaluate to false Pointers hold addresses Address
More informationCS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco
CS 326 Operating Systems C Programming Greg Benson Department of Computer Science University of San Francisco Why C? Fast (good optimizing compilers) Not too high-level (Java, Python, Lisp) Not too low-level
More informationCS 61C: Great Ideas in Computer Architecture. C Arrays, Strings, More Pointers
CS 61C: Great Ideas in Computer Architecture C Arrays, Strings, More Pointers Instructor: Justin Hsia 6/20/2012 Summer 2012 Lecture #3 1 Review of Last Lecture C Basics Variables, Functions, Flow Control,
More informationCSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files
CSC209 Review CSC209: Software tools Unix files and directories permissions utilities/commands Shell programming quoting wild cards files ... and systems programming C basic syntax functions arrays structs
More informationCSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files. Compiler vs.
CSC209 Review CSC209: Software tools Unix files and directories permissions utilities/commands Shell programming quoting wild cards files... and systems programming C basic syntax functions arrays structs
More informationWriting to and reading from files
Writing to and reading from files printf() and scanf() are actually short-hand versions of more comprehensive functions, fprintf() and fscanf(). The difference is that fprintf() includes a file pointer
More informationC for C++ Programmers
C for C++ Programmers CS230/330 - Operating Systems (Winter 2001). The good news is that C syntax is almost identical to that of C++. However, there are many things you're used to that aren't available
More informationHeap Arrays and Linked Lists. Steven R. Bagley
Heap Arrays and Linked Lists Steven R. Bagley Recap Data is stored in variables Can be accessed by the variable name Or in an array, accessed by name and index Variables and arrays have a type Create our
More informationCSC209 Review. Yeah! We made it!
CSC209 Review Yeah! We made it! 1 CSC209: Software tools Unix files and directories permissions utilities/commands Shell programming quoting wild cards files 2 ... and C programming... C basic syntax functions
More informationReview Chapters 1 to 4. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013
Review Chapters 1 to 4 Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013 Introduction to Java Chapters 1 and 2 The Java Language Section 1.1 Data & Expressions Sections 2.1 2.5 Instructor:
More informationCIS192: Python Programming
CIS192: Python Programming Introduction Harry Smith University of Pennsylvania January 18, 2017 Harry Smith (University of Pennsylvania) CIS 192 Lecture 1 January 18, 2017 1 / 34 Outline 1 Logistics Rooms
More informationUse C++, not C for all work in this course. The biggest difference is how one does input
Chapter 1: Preamble 1.1 Commandments A nationally-known expert has said that C++ is a coding monster that forces us to use a disciplined style in order to tame it. This leads to a fundamental rule for
More informationMr. Giansante. Visual Basic. Adventure Game
Visual Basic Adventure Game August 2016 Difficulty Level: Beginner Intermediate Advanced Help References: Button Control MenuStrip Control Random Numbers Arrays Designing the Game Print the "Adventure
More informationCellular Automata Language (CAL) Language Reference Manual
Cellular Automata Language (CAL) Language Reference Manual Calvin Hu, Nathan Keane, Eugene Kim {ch2880, nak2126, esk2152@columbia.edu Columbia University COMS 4115: Programming Languages and Translators
More informationCpSc 1010, Fall 2014 Lab 10: Command-Line Parameters (Week of 10/27/2014)
CpSc 1010, Fall 2014 Lab 10: Command-Line Parameters (Week of 10/27/2014) Goals Demonstrate proficiency in the use of the switch construct and in processing parameter data passed to a program via the command
More information211: Computer Architecture Summer 2016
211: Computer Architecture Summer 2016 Liu Liu Topic: C Programming Data Representation I/O: - (example) cprintf.c Memory: - memory address - stack / heap / constant space - basic data layout Pointer:
More informationTypes II. Hwansoo Han
Types II Hwansoo Han Arrays Most common and important composite data types Homogeneous elements, unlike records Fortran77 requires element type be scalar Elements can be any type (Fortran90, etc.) A mapping
More informationChapter 10: File Input / Output
C: Chapter10 Page 1 of 6 C Tutorial.......... File input/output Chapter 10: File Input / Output OUTPUT TO A FILE Load and display the file named formout.c for your first example of writing data to a file.
More informationCS201 Some Important Definitions
CS201 Some Important Definitions For Viva Preparation 1. What is a program? A program is a precise sequence of steps to solve a particular problem. 2. What is a class? We write a C++ program using data
More informationCourse Text. Course Description. Course Objectives. StraighterLine Introduction to Programming in C++
Introduction to Programming in C++ Course Text Programming in C++, Zyante, Fall 2013 edition. Course book provided along with the course. Course Description This course introduces programming in C++ and
More informationBASIC ELEMENTS OF A COMPUTER PROGRAM
BASIC ELEMENTS OF A COMPUTER PROGRAM CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING LOGO Contents 1 Identifier 2 3 Rules for naming and declaring data variables Basic data types 4 Arithmetic operators
More informationDynamic Allocation in C
Dynamic Allocation in C C Pointers and Arrays 1 The previous examples involved only targets that were declared as local variables. For serious development, we must also be able to create variables dynamically,
More informationPrograms in memory. The layout of memory is roughly:
Memory 1 Programs in memory 2 The layout of memory is roughly: Virtual memory means that memory is allocated in pages or segments, accessed as if adjacent - the platform looks after this, so your program
More informationChapter 11 Introduction to Programming in C
Chapter 11 Introduction to Programming in C C: A High-Level Language Gives symbolic names to values don t need to know which register or memory location Provides abstraction of underlying hardware operations
More informationAppendix G C/C++ Notes. C/C++ Coding Style Guidelines Ray Mitchell 475
C/C++ Notes C/C++ Coding Style Guidelines -0 Ray Mitchell C/C++ Notes 0 0 0 0 NOTE G. C/C++ Coding Style Guidelines. Introduction The C and C++ languages are free form, placing no significance on the column
More informationChapter 11 Introduction to Programming in C
Chapter 11 Introduction to Programming in C Original slides from Gregory Byrd, North Carolina State University Modified slides by Chris Wilcox, Colorado State University C: A High-Level Language! Gives
More informationFinal Exam 1 /12 2 /12 3 /10 4 /7 5 /4 6 /10 7 /8 8 /9 9 /8 10 /11 11 /8 12 /10 13 /9 14 /13 15 /10 16 /10 17 /12. Faculty of Computer Science
Faculty of Computer Science Page 1 of 21 Final Exam Term: Fall 2018 (Sep4-Dec4) Student ID Information Last name: First name: Student ID #: CS.Dal.Ca userid: Course ID: CSCI 2132 Course Title: Instructor:
More informationLecture 7: Files. opening/closing files reading/writing strings reading/writing numbers (conversion to ASCII) command line arguments
Lecture 7: Files opening/closing files reading/writing strings reading/writing numbers (conversion to ASCII) command line arguments Lecture 5: Files, I/O 0IGXYVI*MPIW 0 opening/closing files reading/writing
More informationPointers in C/C++ 1 Memory Addresses 2
Pointers in C/C++ Contents 1 Memory Addresses 2 2 Pointers and Indirection 3 2.1 The & and * Operators.............................................. 4 2.2 A Comment on Types - Muy Importante!...................................
More information25.2 Opening and Closing a File
Lecture 32 p.1 Faculty of Computer Science, Dalhousie University CSCI 2132 Software Development Lecture 32: Dynamically Allocated Arrays 26-Nov-2018 Location: Chemistry 125 Time: 12:35 13:25 Instructor:
More informationCS 103 Lab The Files are *In* the Computer
CS 103 Lab The Files are *In* the Computer 1 Introduction In this lab you will modify a word scramble game so that instead of using a hardcoded word list, it selects a word from a file. You will learn
More informationLecture 2, September 4
Lecture 2, September 4 Intro to C/C++ Instructor: Prashant Shenoy, TA: Shashi Singh 1 Introduction C++ is an object-oriented language and is one of the most frequently used languages for development due
More informationC mini reference. 5 Binary numbers 12
C mini reference Contents 1 Input/Output: stdio.h 2 1.1 int printf ( const char * format,... );......................... 2 1.2 int scanf ( const char * format,... );.......................... 2 1.3 char
More informationPointers and File Handling
1 Pointers and File Handling From variables to their addresses Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR 2 Basics of Pointers INDIAN INSTITUTE OF TECHNOLOGY
More informationCSE 333 Midterm Exam 7/29/13
Name There are 5 questions worth a total of 100 points. Please budget your time so you get to all of the questions. Keep your answers brief and to the point. The exam is closed book, closed notes, closed
More informationUNIVERSITY OF NEBRASKA AT OMAHA Computer Science 4500/8506 Operating Systems Fall Programming Assignment 1 (updated 9/16/2017)
UNIVERSITY OF NEBRASKA AT OMAHA Computer Science 4500/8506 Operating Systems Fall 2017 Programming Assignment 1 (updated 9/16/2017) Introduction The purpose of this programming assignment is to give you
More informationBC OnLine. Gas Permit System User s Guide
BC OnLine Gas Permit System User s Guide Last Updated January 17, 2008 Copyright Copyright 2008 MDA Access BC Ltd. and the British Columbia Safety Authority. MDA Access BC Ltd. (Access BC) grants consent
More informationFormal Methods of Software Design, Eric Hehner, segment 1 page 1 out of 5
Formal Methods of Software Design, Eric Hehner, segment 1 page 1 out of 5 [talking head] Formal Methods of Software Engineering means the use of mathematics as an aid to writing programs. Before we can
More informationRoom 3P16 Telephone: extension ~irjohnson/uqc146s1.html
UQC146S1 Introductory Image Processing in C Ian Johnson Room 3P16 Telephone: extension 3167 Email: Ian.Johnson@uwe.ac.uk http://www.csm.uwe.ac.uk/ ~irjohnson/uqc146s1.html Ian Johnson 1 UQC146S1 What is
More informationThe Design Process. General Development Issues. C/C++ and OO Rules of Thumb. Home
A l l e n I. H o l u b & A s s o c i a t e s Home C/C++ and OO Rules of Thumb The following list is essentially the table of contents for my book Enough Rope to Shoot Yourself in the Foot (McGraw-Hill,
More informationLast Time. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings
University of British Columbia CPSC 111, Intro to Computation Alan J. Hu Writing a Simple Java Program Intro to Variables Readings Your textbook is Big Java (3rd Ed). This Week s Reading: Ch 2.1-2.5, Ch
More informationCS 11 C track: lecture 6
CS 11 C track: lecture 6 Last week: pointer arithmetic This week: The gdb program struct typedef linked lists gdb for debugging (1) gdb: the Gnu DeBugger http://courses.cms.caltech.edu/cs11/material /c/mike/misc/gdb.html
More informationLecture Notes 4 More C++ and recursion CSS 501 Data Structures and Object-Oriented Programming Professor Clark F. Olson
Lecture Notes 4 More C++ and recursion CSS 501 Data Structures and Object-Oriented Programming Professor Clark F. Olson Reading for this lecture: Carrano, Chapter 2 Copy constructor, destructor, operator=
More informationStudent Name: (in Capital Letters) CSE Introduction to Programming for Engineers and Scientists. Final Exam
Student Name: (in Capital Letters) CSE 1311 Introduction to Programming for Engineers and Scientists Final Exam Fall 2013 1 1. If count is a properly defined integer variable, the following piece of code:
More informationLecture 8: Readin, Writin & Sortin. Wednesday, 04 March 2009
Lecture 8: Readin, Writin & Sortin CS209 : Algorithms and Scientific Computing Wednesday, 04 March 2009 CS209 Lecture 8: Readin, Writin & Sortin 1/25 This afternoon: Last week: Open a file and read its
More informationCS164: Programming Assignment 2 Dlex Lexer Generator and Decaf Lexer
CS164: Programming Assignment 2 Dlex Lexer Generator and Decaf Lexer Assigned: Thursday, September 16, 2004 Due: Tuesday, September 28, 2004, at 11:59pm September 16, 2004 1 Introduction Overview In this
More informationLecture 13: more class, C++ memory management
CIS 330: / / / / (_) / / / / _/_/ / / / / / \/ / /_/ / `/ \/ / / / _/_// / / / / /_ / /_/ / / / / /> < / /_/ / / / / /_/ / / / /_/ / / / / / \ /_/ /_/_/_/ _ \,_/_/ /_/\,_/ \ /_/ \ //_/ /_/ Lecture 13:
More informationDatabase Design. 8-4 Drawing Conventions for Readability. Copyright 2015, Oracle and/or its affiliates. All rights reserved.
1 Database Design 8-4 Objectives This lesson covers the following objectives: Apply the Oracle drawing conventions to a data model diagram Identify high volume entities in a data model diagram and explain
More informationCOMP-202: Foundations of Programming. Lecture 2: Java basics and our first Java program! Jackie Cheung, Winter 2016
COMP-202: Foundations of Programming Lecture 2: Java basics and our first Java program! Jackie Cheung, Winter 2016 Learn about cutting-edge research over lunch with cool profs January 18-22, 2015 11:30
More information2. First Program Stuff
CSE 232 First Midterm, Overview: 1. Getting Started 1. we got started 2. First Program Stuff 1. Compiler vs. Intepreter a. do you know all the steps to create an executable? 2. Variables are declared a.
More informationChapter 8. More Control Statements
Chapter 8. More Control Statements 8.1 for Statement The for statement allows the programmer to execute a block of code for a specified number of times. The general form of the for statement is: for (initial-statement;
More informationCP2 Revision. theme: file access and unix programs
CP2 Revision theme: file access and unix programs file access in C basic access functionality: FILE *fopen(const char *filename, const char *mode); This function returns a pointer to a file stream (or
More informationChapter 11 Introduction to Programming in C
Chapter 11 Introduction to Programming in C C: A High-Level Language Gives symbolic names to values don t need to know which register or memory location Provides abstraction of underlying hardware operations
More informationC programming basics T3-1 -
C programming basics T3-1 - Outline 1. Introduction 2. Basic concepts 3. Functions 4. Data types 5. Control structures 6. Arrays and pointers 7. File management T3-2 - 3.1: Introduction T3-3 - Review of
More informationIntro. Scheme Basics. scm> 5 5. scm>
Intro Let s take some time to talk about LISP. It stands for LISt Processing a way of coding using only lists! It sounds pretty radical, and it is. There are lots of cool things to know about LISP; if
More informationLecture 03 Bits, Bytes and Data Types
Lecture 03 Bits, Bytes and Data Types Computer Languages A computer language is a language that is used to communicate with a machine. Like all languages, computer languages have syntax (form) and semantics
More informationCOMP-202: Foundations of Programming. Lecture 5: Arrays, Reference Type, and Methods Sandeep Manjanna, Summer 2015
COMP-202: Foundations of Programming Lecture 5: Arrays, Reference Type, and Methods Sandeep Manjanna, Summer 2015 Announcements Assignment 2 posted and due on 30 th of May (23:30). Extra class tomorrow
More information