Discrete Structures Lecture 11
|
|
- Sharlene Richardson
- 6 years ago
- Views:
Transcription
1 Lecture 11 Overview Programming Instructions 1. Create file p02.cpp that manages command line arguments and directs the process of creating a Cartesian product Start by entering the command line arguments program found lecture note 1 of CMSC 2613 Programming II Modify the program so that it accepts three file names, two input file names and one output file name Make the manager function CartesianMgr as shown below. void CartesianMgr(istream& i1,istream& i2,ostream& o) { List L1(i1); L1.Print(o,"L1"); //Create List L1. Scan input file stream i1 into the list. //Print the list. List L2(i2); L2.Print(o,"L2"); // Create List L1. Scan input file stream i1 into the list. //Print the list. List C; //Create an empty list C for the Cartesian product. CartesianProduct(L1,L2,C); //Create the Cartesian product from lists L1 and L2. //Store the product in list C. C.Print(o,"C"); //Print the Cartesian product Create function CartesianProduct. void CartesianProduct(List& L1,List& L2,List& C) { for (L1.First();!L1.IsEol();L1.Next()) { for (L2.First();!L2.IsEol();L2.Next()) { C.Insert(Pair(L1.Member(),L2.Member())); 1.5. You will also need function Pair. string Pair(string x,string y){return "(" + x + "," + y + ")"; 1.6. File p02.cpp is organized as shown below. //File p02.cpp directs the process of creating a Cartesian product. //Author Identification block ---- //C++ include files and namespace std. #include <cstdlib> #include <cstring> #include <iostream> #include <iomanip> #include <string> #include <fstream> 1
2 Lecture 11 Overview using namespace std; //Application include files #include "List02.h" string Pair(string x,string y){ void CartesianProduct(List& L1,List& L2,List& C){ void CartesianMgr(istream& i1,istream& i2,ostream& o){ struct CommandLineException { ; struct FileException { ; int main(int argc, char* argv[]) { try { char ifn1[255],ifn2[255],ofn[255]; switch (argc) { case 1: case 2: //Prompt for 2 input file names and 1 output file name. //Copy input file name 1. Prompt for the input file name 2 and the //output file name. case 3: case 4: default: throw CommandLineException(3,argc-1); //end switch ifstream i1(ifn1); if (!i1) throw FileException(ifn1); ifstream i2(ifn2); if (!i2) throw FileException(ifn2); ofstream o(ofn); if (!o) throw FileException(ofn); CartesianMgr(i1,i2,o); o.close(); i1.close(); i2.close(); catch (... ) { return 0; //Read input file names 1 and 2. Prompt for the output file name. //Read input file names 1 and 2. Read the output file name. 2
3 Overview 2. Create file List02.h that contains class List. #ifndef List02 #define List02 1 //Author Identification Comment ---- //C++ include files and namespace std. #include <cstdlib> #include <cstring> #include <iostream> #include <iomanip> #include <string> #include <fstream> using namespace std; struct ListException { ; class List { int size; //Number of elements available in the list int count; //Actual number of elements occupied. //Index of the next available element string* L; //A pointer to a list of strings. int cursor; //Index of the current element public: List(int sz=100):size(sz),count(0),cursor(-1){l=new string[size]; List(istream& i,int sz=100):size(sz),count(0),cursor(0){l=new string[size];scan(i); ~List(){if (L) delete[] L; bool IsFull(void){ void Insert(string v){ void Scan(istream& i){ void Print(ostream& o,const char* title){ void First(void){cursor=0; void Next(void){if (cursor<count) cursor++; bool IsEol(void){return cursor>=count; string Member(void){return L[cursor]; ; #endif 3
4 Overview Submission Instructions 1. Create file p02.cpp in the root directory of your account for this class on the departmental computer cs.uco.edu. 2. Enter your author identification block consisting of 2.1. Your name, for example, Mr. Alan Turing 2.2. Your student identifier, for example, * You address, for example, 2.4. This course Discrete Structures 2.5. The CRN, term, and year of the class in which you are enrolled, for example, 12599, Autumn, The project identifier p The date that the project is due, for example, October 10, The account number of the account that you were assigned tt Design, code, and test your algorithm for producing the results of operations specified in the project assignment. 4. Download a copy of the Project Template (MS Word) from the class webpage changing the name of the file to crn-last-first-p02.docx where crn is the CRN of the class in which you are enrolled, last is your last name, and first is your first name. For example, if your name is Alan Turing and you are enrolled in CRN 12599, the name of the file you downloaded is Turing-Alan-p02.docx. 5. Complete the author identification block in the document you downloaded changing the name and other fields in the block to appropriate values. 6. Change the name in the header of the document to your name. 7. Create a new section and a new header in your document Select the Page Layout tab Select Breaks drop-down list Select the Next Page in the Section Breaks list In the Navigation Tab uncheck Link to Previous 7.5. Change Cover Page to File p02.cpp. 8. Employ WinSCP3 that can be obtained from Dr. McDaniel s web page to copy the source file p02.cpp from your account on the departmental computer to the PC having the document that you will submit to your instructor. 9. Insert File p02.cpp into the section having the header p02.cpp Select Insert In the Text tab, select the Object drop-down list Select Text from file Navigate to the folder containing file p02.cpp Select file p02.cpp to be inserted. 10. Submit the project to your instructor by sending the document to your instructor. The fields of your note contain: To: trturner@uco.edu Subject: crn-last-first-p02 where crn is the CRN of the class in which you are enrolled, last is your last name, and first is your first name. For example, if your name is Alan Turing and you are enrolled in CRN 12599, the name of the file you downloaded is Turing-Alan-p Attach the document containing your project template and source file. 4
5 File p02.cpp //File p02.cpp exercises class Stack // //Author: Ms. Petunia Perfect //Student ID: * //Course: - Discrete Structures //CRN: 11786, Autumn, 2014 //Project: p02 //Due: October 8, 2014 //Account: tt000 //Copyright October, 2014 by Ms. Petunia Perfect //Do not reproduce without permission from Ms. Petunia Perfect //C and C++ standard include files #include <iostream> #include <fstream> #include <iomanip> #include <string> #include <cstring> #include <cstdlib> using namespace std; //Application include files #include "Stack02.h" -- //Function ReverseMgr scans the input stream i for strings, pushes them on the //Stack, then pops them from the stack in reverse order. -- void ReverseMgr(istream& i,ostream& o) { Stack S; for (;;) { string c; i >> c; if (i.eof()) o << " " << c; S.Push(c); o << endl; while (!S.IsEmpty()) o << " " << S.Pop(); o << endl; // 5
6 File p02.cpp //FileException is thrown when too many arguments appear on the command line. struct FileException { FileException(const char* fn) { cout << "File " << fn << "could not be opened."; ; // //CommandLineException is thrown when too many arguments appear //on the command line. // struct CommandLineException { CommandLineException(int m,int a) { cout << "Too many arguments on the command line."; cout << "A maximum of " << m << " arguments may appear on the command line."; cout << a << " arguments were on the command line."; ; // //Function main processes command line arguments main(int argc,char* argv[]) { try { char ifn[255],ofn[255]; switch (argc) { case 1: cout << "Enter the input file name. "; cin >> ifn; cout << "Enter the output file name. "; cin >> ofn; case 2: strcpy(ifn,argv[1]); cout << "Enter the output file name. "; cin >> ofn; case 3: strcpy(ifn,argv[1]); strcpy(ofn,argv[2]); default: throw CommandLineException(2,argc-1); ifstream i(ifn); if (!i) throw FileException(ifn); ofstream o(ofn); if (!o) throw FileException(ofn); 6
7 File p02.cpp ReverseMgr(i,o); o.close(); i.close(); catch (...) { cout << "Program terminated!"; cout << "I won't be back!"; exit(exit_failure); return 0; 7
8 File Stack02.h #ifndef Stack02_h #define Stack02_h 1 //-- //File Stack02.h defines class Stack. Class Stack is implemented //using a dynamically allocated array of strings. //Author: Ms. Petunia Perfect // pperfect@uco.edu //Student ID: * //Course: - Discrete Structures //CRN: 11786, Autumn, 2014 //Project: p02 //Due: October 8, 2014 //Account: tt000 //Copyright October, 2014 by Ms. Petunia Perfect. //Do not reproduce without permission from Ms. Petunia Perfect. // //C++ Standard include files // #include <iostream> #include <fstream> #include <iomanip> #include <string> #include <cstring> #include <cstdlib> using namespace std; //class Stack contains the attributes and member functions of a //stack implemented using a dynamically allocated array class Stack { int size; int tos; string* S; public: Stack(int sz=100); ~Stack(); void Push(string v); bool IsFull(void); bool IsEmpty(void); string Pop(void); ; #endif //Number of available elements //Top Of Stack - index of the //element on top of //the stack //Points to an array of strings. //Constructor //Destructor //Push a string onto the stack //Is the stack full? //Is the stack empty? //Pop a string from the stack 8
9 File Stack02.cpp -- //File Stack02.cpp implements class Stack //Author: Ms. Petunia Perfect //Student ID: * //Course: - Discrete Structures //CRN: 11786, Autumn, 2014 //Project: p02 //Due: October 8, 2014 //Account: tt000 //Copyright October, 2014 by Ms. Petunia Perfect //Do not reproduce without permission from Ms. Petunia Perfect //C and C++ standard include files #include <iostream> #include <fstream> #include <iomanip> #include <string> #include <cstring> #include <cstdlib> using namespace std; //Application include files #include "Stack02.h" //A StackException is thrown when the stack is empty or full. struct StackException { StackException(const char* m) { cout << "I am the stack and I am " << m << "."; ; Stack::Stack(int sz):size(sz),tos(-1){s=new string[size]; -- //Destructor 9
10 File Stack02.cpp -- Stack::~Stack(){if (S) delete[] S; -- //Member function Push -- void Stack::Push(string v) { if (IsFull()) throw StackException("full"); S[++tos]=v; -- //Member function Pop -- string Stack::Pop(void) { if (IsEmpty()) throw StackException("empty"); return S[tos--]; -- //Member function IsFull -- bool Stack::IsFull(void){return tos>=size-1; -- //Member function IsEmpty -- bool Stack::IsEmpty(void){return tos<0; 10
11 File p02make # # File p02make contains instructions that create executable file # p02. # # Author: Ms. Petunia Perfect # Student ID: * # pperfect@uco.edu # Course: - Discrete Structures # CRN: 11786, Autumn, 2014 # Project: p02 # Due: Ocotber 8, 2014 # # Object files (no colon) # obj = p02.o Stack02.o # # Bind (Link) the object files and create executable p02 # p02: ${obj g++ -o p02 ${obj -lm # # Compile p02.cpp that exercises class Stack. # p02.o: p02.cpp Stack02.h g++ -g -c p02.cpp # # Compile Stack02.cpp that implements class Stack. # Stack02.o: Stack02.cpp Stack02.h g++ -g -c Stack02.cpp 11
12 File i02.dat One, two, buckle my shoe. 12
13 File o02.dat One, two, buckle my shoe. shoe. my buckle two, One, 13
Programming II Test 1 Revision 1 CMSC 2613 Autumn 2003
CMSC 2613 Autumn 2003 1. Write your name on your scantron in the space labeled NAME. 2. Write your CRN number in the space labeled HOUR. 3. Write the date in the space labeled DATE. 4. Write the handwritten
More informationCMSC 4023 Chapter 11
11. Topics The Concept of Abstraction Introduction to Data Abstraction Design Issues for Abstract Data Types Language Examples Parameterized Abstract Data Types Encapsulation Constructs Naming Encapsulations
More informationProgramming II Test 3 Revision 1 CS 2613 Autumn 2003
1. Write your name on your scantron in the space labeled NAME. 2. Write your CRN number in the space labeled HOUR. 3. Write the date in the space labeled DATE. 4. Write the handwritten test number of this
More informationMore Group HW. #ifndef Stackh #define Stackh. #include <cstdlib> using namespace std;
More Group HW The following code is contained in the file ex1stck.h. Fill in the blanks with the C++ statement(s) that will correctly finish the method. Each blank may be filled in with more than one statement.
More informationCOMP 2355 Introduction to Systems Programming
COMP 2355 Introduction to Systems Programming Christian Grothoff christian@grothoff.org http://grothoff.org/christian/ 1 Today Class syntax, Constructors, Destructors Static methods Inheritance, Abstract
More informationDue Date: See Blackboard
Source File: ~/2305/lab06.(C CPP cpp c++ cc cxx cp) Input: Under control of main function Output: Under control of main function Value: 2 Extend the IntegerSet class from Lab 04 to provide the following
More informationProgramming C++ Lecture 5. Howest, Fall 2013 Instructor: Dr. Jennifer B. Sartor
Programming C++ Lecture 5 Howest, Fall 2013 Instructor: Dr. Jennifer B. Sartor Jennifer.sartor@elis.ugent.be S Templates S Function and class templates you specify with a single code segment an entire
More informationProgramming II Test 2 Revision 2 CMSC 2613 Autumn 2003
Programming II Test 2 Revision 2 1. Write your name on your scantron in the space labeled NAME. 2. Write your CRN number in the space labeled HOUR. 3. Write the date in the space labeled DATE. 4. Write
More informationLinked List using a Sentinel
Linked List using a Sentinel Linked List.h / Linked List.h Using a sentinel for search Created by Enoch Hwang on 2/1/10. Copyright 2010 La Sierra University. All rights reserved. / #include
More informationProgramming II Lecture 2 Structures and Classes
3. struct Rectangle { 4. double length; 5. double width; 6. }; 7. int main() 8. { Rectangle R={12.5,7}; 9. cout
More informationObjects and streams and files CS427: Elements of Software Engineering
Objects and streams and files CS427: Elements of Software Engineering Lecture 6.2 (C++) 10am, 13 Feb 2012 CS427 Objects and streams and files 1/18 Today s topics 1 Recall...... Dynamic Memory Allocation...
More informationC++ For Science and Engineering Lecture 27
C++ For Science and Engineering Lecture 27 John Chrispell Tulane University Monday November 1, 2010 Classes and the This pointer Every C++ object has a curious pointer called this. If we want to extend
More informationWentworth Institute of Technology COMP201 Computer Science II Spring 2015 Derbinsky. Stacks and Queues. Lecture 11.
Lecture 11 1 More Data Structures In this lecture we will use a linked list to implement two abstract data types (ADT) An ADT provides the interface, or what a data structure does We can then use code
More informationThe number of nodes, N, in a binary tree of height, h is: 2 N 2 The height of a binary tree is: h =
1. Structure Property A heap is a binary tree that is completely filled, with the possible exception of the bottom level, which is filled from left to right. B Figure 1. A complete binary tree. Figure
More informationDue Date: See Blackboard
Source File: ~/2315/04/lab04.(C CPP cpp c++ cc cxx cp) Input: Under control of main function Output: Under control of main function Value: 3 In this assignment create an IntegerSet class that will provide
More informationUnified Modeling Language a case study
Unified Modeling Language a case study 1 an online phone book use case diagram encapsulating a file 2 Command Line Arguments arguments of main arrays of strings 3 Class Definition the filesphonebook.h
More informationCPSC 427: Object-Oriented Programming
CPSC 427: Object-Oriented Programming Michael J. Fischer Lecture 10 October 1, 2018 CPSC 427, Lecture 10, October 1, 2018 1/20 Brackets Example (continued from lecture 8) Stack class Brackets class Main
More informationDue Date: See Blackboard
Source File: ~/2315/06/lab06.(C CPP cpp c++ cc cxx cp) Input: Under control of main function Output: Under control of main function Value: 2 Extend the IntegerSet class from Lab 04 to provide the following
More informationCE221 Programming in C++ Part 1 Introduction
CE221 Programming in C++ Part 1 Introduction 06/10/2017 CE221 Part 1 1 Module Schedule There are two lectures (Monday 13.00-13.50 and Tuesday 11.00-11.50) each week in the autumn term, and a 2-hour lab
More informationAN OVERVIEW OF C++ 1
AN OVERVIEW OF C++ 1 OBJECTIVES Introduction What is object-oriented programming? Two versions of C++ C++ console I/O C++ comments Classes: A first look Some differences between C and C++ Introducing function
More informationStrings and Streams. Professor Hugh C. Lauer CS-2303, System Programming Concepts
Strings and Streams Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2 nd edition, by Kernighan and Ritchie, Absolute C++, by Walter
More informationl Determine if a number is odd or even l Determine if a number/character is in a range - 1 to 10 (inclusive) - between a and z (inclusive)
Final Exam Exercises Chapters 1-7 + 11 Write C++ code to: l Determine if a number is odd or even CS 2308 Fall 2016 Jill Seaman l Determine if a number/character is in a range - 1 to 10 (inclusive) - between
More informationProgramming Languages Test 2 Revision 1 CMSC 4023 CRN Spring 2007
1. Pr your name on your scantron in the space labeled NAME. 2. Pr CS 4023 in the space labeled SUBJECT. 3. Pr 4-2-2007, the date in the space labeled DATE. 4. Pr your 24290, your CRN-number in the space
More informationDue Date: See Blackboard
Source File: ~/2315/45/lab45.(C CPP cpp c++ cc cxx cp) Input: under control of main function Output: under control of main function Value: 4 Integer data is usually represented in a single word on a computer.
More informationC++_ MARKS 40 MIN
C++_16.9.2018 40 MARKS 40 MIN https://tinyurl.com/ya62ayzs 1) Declaration of a pointer more than once may cause A. Error B. Abort C. Trap D. Null 2Whice is not a correct variable type in C++? A. float
More informationFile I/O Christian Schumacher, Info1 D-MAVT 2013
File I/O Christian Schumacher, chschuma@inf.ethz.ch Info1 D-MAVT 2013 Input and Output in C++ Stream objects Formatted output Writing and reading files References General Remarks I/O operations are essential
More informationReview: C++ Basic Concepts. Dr. Yingwu Zhu
Review: C++ Basic Concepts Dr. Yingwu Zhu Outline C++ class declaration Constructor Overloading functions Overloading operators Destructor Redundant declaration A Real-World Example Question #1: How to
More informationCS 117 Programming II, Spring 2018 Dr. Ghriga. Midterm Exam Estimated Time: 2 hours. March 21, DUE DATE: March 28, 2018 at 12:00 PM
CS 117 Programming II, Spring 2018 Dr. Ghriga Midterm Exam Estimated Time: 2 hours March 21, 2018 DUE DATE: March 28, 2018 at 12:00 PM INSTRUCTIONS: Do all exercises for a total of 100 points. You are
More informationLab: Supplying Inputs to Programs
Steven Zeil May 25, 2013 Contents 1 Running the Program 2 2 Supplying Standard Input 4 3 Command Line Parameters 4 1 In this lab, we will look at some of the different ways that basic I/O information can
More informationIV. Stacks. A. Introduction 1. Consider the 4 problems on pp (1) Model the discard pile in a card game. (2) Model a railroad switching yard
IV. Stacks 1 A. Introduction 1. Consider the problems on pp. 170-1 (1) Model the discard pile in a card game (2) Model a railroad switching yard (3) Parentheses checker () Calculate and display base-two
More informationInterview Questions of C++
Interview Questions of C++ Q-1 What is the full form of OOPS? Ans: Object Oriented Programming System. Q-2 What is a class? Ans: Class is a blue print which reflects the entities attributes and actions.
More informationDue Date: See Blackboard
Source File: ~/2315/11/lab11.(C CPP cpp c++ cc cxx cp) Input: Under control of main function Output: Under control of main function Value: 1 The purpose of this assignment is to become more familiar with
More informationWhat will happen if we try to compile, link and run this program? Do you have any comments to the code?
1 # include < iostream > 2 3 int main () 4 { 5 std :: cout
More informationADTs: Stacks and Queues
Introduction to the Stack ADTs: Stack: a data structure that holds a collection of elements of the same type. - The elements are accessed according to LIFO order: last in, first out - No random access
More informationFile Operations. Lecture 16 COP 3014 Spring April 18, 2018
File Operations Lecture 16 COP 3014 Spring 2018 April 18, 2018 Input/Ouput to and from files File input and file output is an essential in programming. Most software involves more than keyboard input and
More informationIntermediate Programming, Spring 2017*
600.120 Intermediate Programming, Spring 2017* Misha Kazhdan *Much of the code in these examples is not commented because it would otherwise not fit on the slides. This is bad coding practice in general
More informationChapter 19: Program Design. Chapter 19. Program Design. Copyright 2008 W. W. Norton & Company. All rights reserved.
Chapter 19 Program Design 1 Introduction Most full-featured programs are at least 100,000 lines long. Although C wasn t designed for writing large programs, many large programs have been written in C.
More informationIntroduction to C++ Professor Hugh C. Lauer CS-2303, System Programming Concepts
Introduction to C++ Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2 nd edition, by Kernighan and Ritchie, Absolute C++, by Walter
More informationG52CPP C++ Programming Lecture 17
G52CPP C++ Programming Lecture 17 Dr Jason Atkin http://www.cs.nott.ac.uk/~jaa/cpp/ g52cpp.html 1 Last Lecture Exceptions How to throw (return) different error values as exceptions And catch the exceptions
More informationCSCE 110 PROGRAMMING FUNDAMENTALS
CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 15. Dictionaries (1): A Key Table Class Prof. amr Goneid, AUC 1 Dictionaries(1): A Key Table Class Prof. Amr Goneid, AUC 2 A Key Table
More informationProgram Organization and Comments
C / C++ PROGRAMMING Program Organization and Comments Copyright 2013 Dan McElroy Programming Organization The layout of a program should be fairly straight forward and simple. Although it may just look
More informationCourse "Data Processing" Name: Master-1: Nuclear Energy Session /2018 Examen - Part A Page 1
Examen - Part A Page 1 1. mydir directory contains three files: filea.txt fileb.txt filec.txt. How many files will be in the directory after performing the following operations: $ ls filea.txt fileb.txt
More informationCMSC 341 Lecture 7. Announcements. Proj 2 up Project Preview tonight and tomorrow
CMSC 341 Lecture 7 Announcements Proj 2 up Project Preview tonight and tomorrow 1 Comparing Performance Linear S Linked D Linked Cursor constructor O(1) O(1) O(1) O(1) find O(n) O(n) O(n) O(n) findprev
More informationC++ Programming Fundamentals
C++ Programming Fundamentals 281 Elvis C. Foster Lecture 12: Exception Handling One of the things you are required to do as a responsible programmer is to ensure that your program allows only valid data
More informationBITG 1113: Files and Stream LECTURE 10
BITG 1113: Files and Stream LECTURE 10 1 LEARNING OUTCOMES At the end of this lecture, you should be able to: 1. Describe the fundamentals of input & output files. 2. Use data files for input & output
More informationLecture-5. STL Containers & Iterators
Lecture-5 STL Containers & Iterators Containers as a form of Aggregation Fixed aggregation An object is composed of a fixed set of component objects Variable aggregation An object is composed of a variable
More informationProgramming in C/C Lecture 3
Programming in C/C++ 2005- Lecture 3 http://few.vu.nl/~nsilvis/c++/ Natalia Silvis-Cividjian e-mail: nsilvis@few.vu.nl vrije Universiteit amsterdam Object Oriented Programming in C++ about object oriented
More informationStack memory - "scratch pad" memory that is used by automatic variables.
Dynamic Memory Allocation In C and C++ three types of memory are used by programs: Static memory - where global and static variables live Stack memory - "scratch pad" memory that is used by automatic variables.
More informationC++ Programming Classes. Michael Griffiths Corporate Information and Computing Services The University of Sheffield
C++ Programming Classes Michael Griffiths Corporate Information and Computing Services The University of Sheffield Email m.griffiths@sheffield.ac.uk Presentation Outline Differences between C and C++ Object
More informationHomework 5. Yuji Shimojo CMSC 330. Instructor: Prof. Reginald Y. Haseltine
Homework 5 Yuji Shimojo CMSC 330 Instructor: Prof. Reginald Y. Haseltine July 13, 2013 Question 1 Consider the following Java definition of a mutable string class. class MutableString private char[] chars
More informationการทดลองท 8_2 Editor Buffer Array Implementation
การทดลองท 8_2 Editor Buffer Array Implementation * File: buffer.h * -------------- * This file defines the interface for the EditorBuffer class. #ifndef _buffer_h #define _buffer_h * Class: EditorBuffer
More informationC++ Addendum: Inheritance of Special Member Functions. Constructors Destructor Construction and Destruction Order Assignment Operator
C++ Addendum: Inheritance of Special Member Functions Constructors Destructor Construction and Destruction Order Assignment Operator What s s Not Inherited? The following methods are not inherited: Constructors
More informationBEng (Hons) Electronic Engineering. Resit Examinations for / Semester 1
BEng (Hons) Electronic Engineering Cohort: BEE/10B/FT Resit Examinations for 2016-2017 / Semester 1 MODULE: Programming for Engineers MODULE CODE: PROG1114 Duration: 3 Hours Instructions to Candidates:
More informationCSc Introduc/on to Compu/ng. Lecture 19 Edgardo Molina Fall 2011 City College of New York
CSc 10200 Introduc/on to Compu/ng Lecture 19 Edgardo Molina Fall 2011 City College of New York 18 Standard Device Files Logical file object: Stream that connects a file of logically related data to a program
More informationCMSC 341 Lecture 6 Templates, Stacks & Queues. Based on slides by Shawn Lupoli & Katherine Gibson at UMBC
CMSC 341 Lecture 6 Templates, Stacks & Queues Based on slides by Shawn Lupoli & Katherine Gibson at UMBC Today s Topics Data types in C++ Overloading functions Templates How to implement them Possible
More informationC++ STREAMS; INHERITANCE AS
C++ STREAMS; INHERITANCE AS PUBLIC, PROTECTED, AND PRIVATE; AGGREGATION/COMPOSITION Pages 731 to 742 Anna Rakitianskaia, University of Pretoria C++ STREAM CLASSES A stream is an abstraction that represents
More informationReading from and Writing to Files. Files (3.12) Steps to Using Files. Section 3.12 & 13.1 & Data stored in variables is temporary
Reading from and Writing to Files Section 3.12 & 13.1 & 13.5 11/3/08 CS150 Introduction to Computer Science 1 1 Files (3.12) Data stored in variables is temporary We will learn how to write programs that
More informationCSE au Midterm Exam Nov. 2, 2018 Sample Solution
Question 1. (16 points) Build tools and make. We re building a C++ software back-end prototype for a new food web site. So far, we ve got the following source files with the code for two main programs
More informationDATA STRUCTURES AND ALGORITHMS LECTURE 08 QUEUES IMRAN IHSAN ASSISTANT PROFESSOR AIR UNIVERSITY, ISLAMABAD
DATA STRUCTURES AND ALGORITHMS LECTURE 08 S IMRAN IHSAN ASSISTANT PROFESSOR AIR UNIVERSITY, ISLAMABAD S ABSTRACT DATA TYPE An Abstract Queue (Queue ADT) is an abstract data type that emphasizes specific
More informationInput and Output File (Files and Stream )
Input and Output File (Files and Stream ) BITE 1513 Computer Game Programming Week 14 Scope Describe the fundamentals of input & output files. Use data files for input & output purposes. Files Normally,
More informationCSC 222: Computer Programming II. Spring 2004
CSC 222: Computer Programming II Spring 2004 Stacks and recursion stack ADT push, pop, top, empty, size vector-based implementation, library application: parenthesis/delimiter matching run-time
More informationCSCE 110 PROGRAMMING FUNDAMENTALS
CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 16. Linked Lists Prof. amr Goneid, AUC 1 Linked Lists Prof. amr Goneid, AUC 2 Linked Lists The Linked List Structure Some Linked List
More informationCSCI 104 Classes. Mark Redekopp David Kempe
CSCI 104 Classes Mark Redekopp David Kempe CLASSES 2 C Structs Needed a way to group values that are related, but have different data types NOTE: struct has changed in C++! C C++ Only data members Some
More informationLab 6 Due Date: Wednesday, April 5, /usr/local/3302/include/direct linking loader.h Driver File:
Source File: ~/3302/lab06.C Specification File: /usr/local/3302/include/direct linking loader.h Driver File: /usr/local/3302/src/lab06main.c Implementation Starter File: /usr/local/3302/src/lab06.c.start
More informationG52CPP C++ Programming Lecture 16
G52CPP C++ Programming Lecture 16 Dr Jason Atkin http://www.cs.nott.ac.uk/~jaa/cpp/ g52cpp.html 1 Last Lecture Casting static cast dynamic cast const cast reinterpret cast Implicit type conversion 2 How
More informationWelcome Back. CSCI 262 Data Structures. Hello, Let s Review. Hello, Let s Review. How to Review 1/9/ Review. Here s a simple C++ program:
Welcome Back CSCI 262 Data Structures 2 - Review What you learned in CSCI 261 (or equivalent): Variables Types Arrays Expressions Conditionals Branches & Loops Functions Recursion Classes & Objects Streams
More informationTemplates (again) Professor Hugh C. Lauer CS-2303, System Programming Concepts
Templates (again) Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2 nd edition, by Kernighan and Ritchie, Absolute C++, by Walter
More informationWhat can go wrong in a Java program while running?
Exception Handling See https://docs.oracle.com/javase/tutorial/ essential/exceptions/runtime.html See also other resources available on the module webpage This lecture Summary on polymorphism, multiple
More informationCSCI 104 Templates. Mark Redekopp David Kempe
1 CSCI 104 Templates Mark Redekopp David Kempe 2 Overview C++ Templates allow alternate versions of the same code to be generated for various data types FUNCTION TEMPLATES 3 4 How To's Example reproduced
More informationSeptember 19,
September 19, 2013 1 Problems with previous examples Changes to the implementation will require recompilation & relinking of clients Extensions will require access to the source code Solutions Combine
More informationChapter 2. Procedural Programming
Chapter 2 Procedural Programming 2: Preview Basic concepts that are similar in both Java and C++, including: standard data types control structures I/O functions Dynamic memory management, and some basic
More informationOverview of today s lecture. Quick recap of previous C lectures. Introduction to C programming, lecture 2. Abstract data type - Stack example
Overview of today s lecture Introduction to C programming, lecture 2 -Dynamic data structures in C Quick recap of previous C lectures Abstract data type - Stack example Make Refresher: pointers Pointers
More informationAppendix M: Introduction to Microsoft Visual C Express Edition
Appendix M: Introduction to Microsoft Visual C++ 2005 Express Edition This book may be ordered from Addison-Wesley in a value pack that includes Microsoft Visual C++ 2005 Express Edition. Visual C++ 2005
More informationChapter 14 Sequential Access Files
Chapter 14 Sequential Access Files Objectives Create file objects Open a sequential access file Determine whether a sequential access file was opened successfully Write data to a sequential access file
More informationCSE 333. Lecture 10 - references, const, classes. Hal Perkins Paul G. Allen School of Computer Science & Engineering University of Washington
CSE 333 Lecture 10 - references, const, classes Hal Perkins Paul G. Allen School of Computer Science & Engineering University of Washington Administrivia New C++ exercise out today, due Friday morning
More informationExam duration: 3 hours Number of pages: 10
INFOMGEP 2011 Retake exam Student name: Student number: Exam duration: 3 hours Number of pages: 10 All the answers have to be written in the corresponding boxes. It is allowed to have: - lecture notes
More informationObject Oriented Programming COP3330 / CGS5409
Object Oriented Programming COP3330 / CGS5409 Intro to Data Structures Vectors Linked Lists Queues Stacks C++ has some built-in methods of storing compound data in useful ways, like arrays and structs.
More informationCPSC 427: Object-Oriented Programming
CPSC 427: Object-Oriented Programming Michael J. Fischer Lecture 7 September 21, 2016 CPSC 427, Lecture 7 1/21 Brackets Example (continued) Storage Management CPSC 427, Lecture 7 2/21 Brackets Example
More informationProgramming in C++: Assignment Week 8
Programming in C++: Assignment Week 8 Total Marks : 20 September 9, 2017 Question 1 Consider the following code segment. Mark 2 void myfunction(int test) { try { if (test) throw test; else throw "Value
More informationLab 1: First Steps in C++ - Eclipse
Lab 1: First Steps in C++ - Eclipse Step Zero: Select workspace 1. Upon launching eclipse, we are ask to chose a workspace: 2. We select a new workspace directory (e.g., C:\Courses ): 3. We accept the
More informationCS 103 Unit 14 - Streams
CS 103 Unit 14 - Streams 1 2 I/O Streams '>>' operator used to read data from an input stream Always skips leading whitespace ('\n', ' ', '\t') and stops at first trailing whitespace '
More informationStrings and Stream I/O
Strings and Stream I/O C Strings In addition to the string class, C++ also supports old-style C strings In C, strings are stored as null-terminated character arrays str1 char * str1 = "What is your name?
More informationIntroduction to Programming using C++
Introduction to Programming using C++ Lecture One: Getting Started Carl Gwilliam gwilliam@hep.ph.liv.ac.uk http://hep.ph.liv.ac.uk/~gwilliam/cppcourse Course Prerequisites What you should already know
More informationLab 2: ADT Design & Implementation
Lab 2: ADT Design & Implementation By Dr. Yingwu Zhu, Seattle University 1. Goals In this lab, you are required to use a dynamic array to design and implement an ADT SortedList that maintains a sorted
More informationECE 2036 Lab 1: Introduction to Software Objects
ECE 2036 Lab 1: Introduction to Software Objects Assigned: Aug 24/25 2015 Due: September 1, 2015 by 11:59 PM Reading: Deitel& Deitel Chapter 2-4 Student Name: Check Off/Score Part 1: Check Off/Score Part
More informationC++ Programming Fundamentals
C++ Programming Fundamentals 205 Elvis C. Foster Lecture 08: Working with Vectors In lectures 5 and 6, it was established that C++ allows you to create and manage a dynamic list by declaring the list as
More informationChapter 7: Stacks. Exercises 7.2
hapter 7: Stacks Exercises 7.2 1. mytop == 0; myrray contains 3 elements: 10, 22, 37,?,? but note that only element 10 is considered to be in the stack. 2. mytop == 1; myrray contains 3 elements: 10, 9,
More informationFundamentals of Programming. Lecture 19 Hamed Rasifard
Fundamentals of Programming Lecture 19 Hamed Rasifard 1 Outline C++ Object-Oriented Programming Class 2 C++ C++ began as an expanded version of C. C++ improves on many of C s features and provides object-oriented-programming
More informationChapter 15 - C++ As A "Better C"
Chapter 15 - C++ As A "Better C" Outline 15.1 Introduction 15.2 C++ 15.3 A Simple Program: Adding Two Integers 15.4 C++ Standard Library 15.5 Header Files 15.6 Inline Functions 15.7 References and Reference
More informationEECE.3220: Data Structures Spring 2017
EECE.3220: Data Structures Spring 2017 Lecture 14: Key Questions February 24, 2017 1. Describe the characteristics of an ADT to store a list. 2. What data members would be necessary for a static array-based
More informationSimple File I/O.
Simple File I/O from Chapter 6 http://www.cplusplus.com/reference/fstream/ifstream/ l / /f /if / http://www.cplusplus.com/reference/fstream/ofstream/ I/O Streams I/O refers to a program s input and output
More informationLab 8. Follow along with your TA as they demo GDB. Make sure you understand all of the commands, how and when to use them.
Lab 8 Each lab will begin with a recap of last lab and a brief demonstration by the TAs for the core concepts examined in this lab. As such, this document will not serve to tell you everything the TAs
More informationCOMP6771 Advanced C++ Programming
1. COMP6771 Advanced C++ Programming Week 4 Part One: (continued) and 2016 www.cse.unsw.edu.au/ cs6771 2. Inline Constructors, Accessors and Mutators Question (from 2015): In the week 3 examples, constructors
More informationPreview 8/28/2018. Review for COSC 120 (File Processing: Reading Data From a File)
Preview Relational operator If, if--if, nested if statement Logical operators Validating Inputs Compare two c-string Switch Statement Increment decrement operator While, Do-While, For Loop Break, Continue
More informationObject Oriented Programming COP3330 / CGS5409
Object Oriented Programming COP3330 / CGS5409 Multiple Inheritance Template Classes and Functions Inheritance is supported by most object oriented languages C++ allows a special kind of inheritance known
More informationScientific Computing
Scientific Computing Martin Lotz School of Mathematics The University of Manchester Lecture 1, September 22, 2014 Outline Course Overview Programming Basics The C++ Programming Language Outline Course
More informationCPSC 427: Object-Oriented Programming
CPSC 427: Object-Oriented Programming Michael J. Fischer Lecture 22 November 28, 2016 CPSC 427, Lecture 22 1/43 Exceptions (continued) Code Reuse Linear Containers Ordered Containers Multiple Inheritance
More informationLists. linking nodes. constructors. chasing pointers. MCS 360 Lecture 11 Introduction to Data Structures Jan Verschelde, 17 September 2010.
1 2 3 MCS 360 Lecture 11 Introduction to Data Structures Jan Verschelde, 17 September 2010 1 2 3 efficient updates with lists At http://www.sgi.com/tech/stl/ is the Standard Template Library Programmer
More informationC++ basics Getting started with, and Data Types.
C++ basics Getting started with, and Data Types pm_jat@daiict.ac.in Recap Last Lecture We talked about Variables - Variables, their binding to type, storage etc., Categorization based on storage binding
More informationDue Date: See Blackboard
Source File: ~/2315/28/lab28.cpp Input: under control of main function Output: under control of main function Value: 2 Write a function template that will process the elements of a vector and determine
More information