Due Date: See Blackboard

Size: px
Start display at page:

Download "Due Date: See Blackboard"

Transcription

1 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. The number of bits in a word determines the range of integers representable. For example, a 16-bit word allows integers in the range from through Doubling the word size to 32 bits increases the range from through In this latter case, results that are representable within ten digits are possible. It is desirable to be able to represent integral results that are larger (in absolute value) than this. In this assignment you are to develop a class for representing large integers. The large integer will be implemented as a list of chars. Each node in the list will contain a digit of the large integer. The large integer is to be stored such that the least significant digit is contained in the first node, the next-to-least significant digit in the second node, and so on. No leading zeroes should be stored with the large integer. The number zero (0) should be stored as a single digit of zero (0). For this assignment, you are to create several constructors and overloaded operators that can be used for comparing large integers. A header file is shown in Figure 1, a sample main function for testing your implementation is shown in Figure 2, and a sample execution sequence is shown in Figure 3. To use the Makefile as distributed in class, add a target of lab45 to targets2srcfiles. For the constructor that takes a string parameter, if the fsaforint function returns false, the number should be stored as zero. 1 #ifndef LAB45_H 2 #define LAB45_H 3 4 #include <iostream> 5 #include <string> 6 #include <list> 7 8 using namespace std; 9 10 typedef enum {NEGATIVE, ZERO, POSITIVE} Sign; int fsaforint(string s); class BigInt 15 { 16 friend ostream& operator<<( ostream& output, const BigInt& ); 17 friend istream& operator>>( istream& input, BigInt& ); 18 public: 19 BigInt(); // constructor; digits = 0 20 BigInt( int num ); // constructor; digits = num 21 BigInt( const string str ); // constructor; digits = str 22 BigInt( const BigInt& other ); // copy constructor bool operator==( const BigInt& rhs ) const; // Equality 25 bool operator< ( const BigInt& rhs ) const; // Less Than 26 Figure 1. /usr/local/2315/include/lab45.h (Part 1 of 2) CS 2315 Data Structures and Algorithms Page 1

2 27 private: 28 Sign sign; // Sign of # 29 list<char> digits; // List of digits of # 30 }; #endif Figure 1. /usr/local/2315/include/lab45.h (Part 2 of 2) 1 #include <lab45.h> 2 #include <cstdlib> 3 #include <iomanip> 4 5 using namespace std; 6 7 void comparezeroes(const BigInt& a, const BigInt& b, const BigInt& c, 8 const BigInt& d, const BigInt& e, const BigInt& f, 9 string v1, string v2, string v3, 10 string v4, string v5, string v6); int main() 13 { 14 BigInt a, b(-507), c("abc"), d("275"), 15 e(" "); 16 BigInt f(e), g(" 0 "), h(" -0 "); 17 BigInt i(" +0 "), j(+0), k(-0); cout << boolalpha; 20 cout << "a = " << a << endl; 21 cout << "g = " << g << endl; 22 cout << "h = " << h << endl; 23 cout << "i = " << i << endl; 24 cout << "j = " << j << endl; 25 cout << "k = " << k << endl; comparezeroes(a, g, h, i, j, k, "a", "g", "h", "i", "j", "k"); 28 comparezeroes(g, h, i, j, k, a, "g", "h", "i", "j", "k", "a"); 29 comparezeroes(h, i, j, k, a, g, "h", "i", "j", "k", "a", "g"); 30 comparezeroes(i, j, k, a, g, h, "i", "j", "k", "a", "g", "h"); 31 comparezeroes(j, k, a, g, h, i, "j", "k", "a", "g", "h", "i"); 32 comparezeroes(k, a, g, h, i, j, "k", "a", "g", "h", "i", "j"); 33 Figure 2. /usr/local/2315/src/lab45main.c (Part 1 of 3) Page 2 CS 2315 Data Structures and Algorithms

3 34 cout << "a = " << a << endl << "b = " << b << endl; 35 cout << "c = " << c << endl << "d = " << d << endl; 36 cout << "e = " << e << endl << "f = " << f << endl; 37 c = a = b; 38 cout << "a = " << a << endl << "b = " << b << endl; 39 cout << "c = " << c << endl; 40 cout << "a == b = " << (a == b) << endl; 41 cout << "c == b = " << (c == b) << endl; while (cin >> a >> b) 44 { 45 cout << "a = " << a << " b = " << b << endl; 46 cout << a << " == " << b << " = " << (a == b) << endl; 47 cout << a << " < " << b << " = " << (a < b) << endl; 48 } return EXIT_SUCCESS; 51 } void comparezeroes(const BigInt& a, const BigInt& b, const BigInt& c, 54 const BigInt& d, const BigInt& e, const BigInt& f, 55 string v1, string v2, string v3, 56 string v4, string v5, string v6) 57 { 58 cout << v1 << " == " << v1 << " = " << (a == a) << endl; 59 cout << v1 << " == " << v2 << " = " << (a == b) << endl; 60 cout << v1 << " == " << v3 << " = " << (a == c) << endl; 61 cout << v1 << " == " << v4 << " = " << (a == d) << endl; 62 cout << v1 << " == " << v5 << " = " << (a == e) << endl; 63 cout << v1 << " == " << v6 << " = " << (a == f) << endl; 64 } int fsaforint(string s) 67 { 68 int state = 0; 69 string::iterator itr; for (itr = s.begin(); itr < s.end(); ++itr) 72 switch (state) 73 { 74 case 0: if (isspace(*itr)) 75 state = 0; 76 else if (*itr == + *itr == - ) 77 state = 1; 78 else if (isdigit(*itr)) 79 state = 2; 80 else 81 state = 4; 82 break; Figure 2. /usr/local/2315/src/lab45main.c (Part 2 of 3) CS 2315 Data Structures and Algorithms Page 3

4 83 case 1: if (isdigit(*itr)) 84 state = 2; 85 else 86 state = 4; 87 break; 88 case 2: if (isdigit(*itr)) 89 state = 2; 90 else if (isspace(*itr)) 91 state = 3; 92 else 93 state = 4; 94 break; 95 case 3: if (isspace(*itr)) 96 state = 3; 97 else 98 state = 4; 99 break; 100 case 4: ; 101 } return state == 2 state == 3; 104 } istream& operator>>(istream& input, BigInt& num) 107 { 108 string s; input >> s; 111 num = BigInt(s); return input; 114 } ostream& operator<<(ostream& output, const BigInt& num) 117 { 118 list<char>::const_reverse_iterator itr; if (num.sign == NEGATIVE) 121 output << - ; for (itr = num.digits.crbegin(); itr!= num.digits.crend(); ++itr) 124 output << *itr; return output; 127 } Figure 2. /usr/local/2315/src/lab45main.c (Part 3 of 3) Page 4 CS 2315 Data Structures and Algorithms

5 1 ~> cd newuser@csunix ~/2315>./getlab.ksh 45 3 * Checking to see if a folder exists for Lab 45...No 4 * Creating a folder for Lab 45 5 * Checking to see if Lab 45 has sample input and output files...yes 6 * Copying input and output files for Lab 45 7 from folder /usr/local/2315/data/45 to folder./45 8 * Checking to see if /usr/local/2315/src/lab45main.c exists...yes 9 * Copying file /usr/local/2315/src/lab45main.c to folder./45 10 * Checking to see if /usr/local/2315/include/lab45.h exists...yes 11 * Copying file /usr/local/2315/include/lab45.h to folder./45 12 * Copying file /usr/local/2315/src/makefile to folder./45 13 * Adding a target of lab45 to targets2srcfiles 14 * Touching file./45/lab45.cpp 15 * Edit file./45/lab45.cpp in Notepad++ 16 newuser@csunix ~/2315> cd newuser@csunix ~/2315/45> ls dat 01.out Makefile lab45.cpp lab45.h lab45main.c 19 newuser@csunix ~/2315/45> make lab45 20 g++ -g -Wall -std=c++11 -c lab45main.c -I/usr/local/2315/include -I. 21 g++ -g -Wall -std=c++11 -c lab45.cpp -I/usr/local/2315/include -I. 22 g++ -o lab45 lab45main.o lab45.o -L/usr/local/2315/lib -lm -lbits 23 newuser@csunix ~/2315/45> cat 01.dat newuser@csunix ~/2315/45> cat 01.dat./lab45 53 a = 0 54 g = 0 55 h = 0 56 i = 0 57 j = 0 58 k = 0 59 a == a = true 60 a == g = true 61 a == h = true 62 a == i = true 63 a == j = true 64 a == k = true 65 g == g = true 66 g == h = true 67 g == i = true 68 g == j = true 69 g == k = true 70 g == a = true 71 h == h = true 72 h == i = true 73 h == j = true 74 h == k = true 75 h == a = true 76 h == g = true 77 i == i = true Figure 3. Commands to Compile, Link, & Run Lab 45 (Part 1 of 3) CS 2315 Data Structures and Algorithms Page 5

6 Page 6 CS 2315 Data Structures and Algorithms 78 i == j = true 79 i == k = true 80 i == a = true 81 i == g = true 82 i == h = true 83 j == j = true 84 j == k = true 85 j == a = true 86 j == g = true 87 j == h = true 88 j == i = true 89 k == k = true 90 k == a = true 91 k == g = true 92 k == h = true 93 k == i = true 94 k == j = true 95 a = 0 96 b = c = 0 98 d = e = f = a = b = c = a == b = true 105 c == b = true 106 a = b = == 0 = false < 0 = true 109 a = -1 b = == 1 = false < 1 = true 112 a = 0 b = == = false < = false 115 a = 0 b = == = false < = true 118 a = b = == = false < = false 121 a = b = == 0 = false < 0 = false 124 a = 0 b = == 0 = true < 0 = false 127 a = b = == = false < = true 130 a = b = == = false < = true 133 a = b = == = false < = false 136 a = b = == = false < = true 139 a = b = == = false < = false 142 a = b = == = true < = false 145 a = b = == = false < = false 148 a = b = == = false < = true 151 a = b = == = false < = true 154 a = b = == = false < = false 157 a = b = 1234 Figure 3. Commands to Compile, Link, & Run Lab 45 (Part 2 of 3) Lab 45

7 == 1234 = false < 1234 = false 160 a = 1234 b = == = false < = true 163 a = 0 b = == 0 = true < 0 = false 166 a = 0 b = == 0 = true < 0 = false 169 a = 0 b = == 0 = true < 0 = false 172 a = 0 b = == 0 = true < 0 = false 175 a = 0 b = == 0 = true < 0 = false 178 a = 0 b = == 0 = true < 0 = false 181 a = 0 b = == 0 = true < 0 = false 184 a = 0 b = == 0 = true < 0 = false 187 a = 0 b = == 0 = true < 0 = false 190 newuser@csunix ~/2315/45> cat 01.dat./lab45 > my.out 191 newuser@csunix ~/2315/45> diff 01.out my.out 192 newuser@csunix ~/2315/45> Figure 3. Commands to Compile, Link, & Run Lab 45 (Part 3 of 3) CS 2315 Data Structures and Algorithms Page 7

Due Date: See Blackboard

Due 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 information

Due Date: See Blackboard

Due 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 information

Due Date: See Blackboard

Due 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 information

CS 1337 Computer Science II Page 1

CS 1337 Computer Science II Page 1 Source File: ~/1337/65/lab65.(C CPP cpp c++ cc cxx cp) Input: Under control of main function Output: Under control of main function Value: 3 The purpose of this assignment is to add to the implementation

More information

Due Date: See Blackboard. {a n+1 b 2n n 0}

Due Date: See Blackboard. {a n+1 b 2n n 0} Source File: ~/4301/06/lab06.(C CPP cpp c++ cc cxx cp) Input: Under control of main function Output: Under control of main function Value: 1 For Σ = {a,b}, construct a pushdown automata that accepts the

More information

CS 4301 Algorithmic Languages and Compilers Page 1

CS 4301 Algorithmic Languages and Compilers Page 1 Source File: ~/4301/08/lab08.(C CPP cpp c++ cc cxx cp) Input: Under control of main function Output: Under control of main function Value: 1 For Σ = {a,b}, construct a pushdown transducer that accepts

More information

Due Date: See Blackboard

Due Date: See Blackboard Source File: ~/2336/43/lab43.(C CPP cpp c++ cc cxx cp) Input: under control of main function Output: under control of main function Value: 2 The purpose of this assignment is to modify Lab 38. Instead

More information

Due Date: See Blackboard

Due Date: See Blackboard Source File: ~/2315/38/lab38.(C CPP cpp c++ cc cxx cp) Input: under control of main function Output: under control of main function Value: 3 A bucket sort begins with a one-dimensional array of positive

More information

Due Date: See Blackboard

Due 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

Due Date: See Blackboard

Due 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 information

Due Date: See Blackboard

Due Date: See Blackboard Source File: ~/2315/33/lab33.cpp Input: under control of main function Output: under control of main function Value: 3 The Shell sort, named after its inventor Donald Shell, provides a simple and efficient

More information

Due Date: See Blackboard

Due Date: See Blackboard Source File: ~/2305/lab27.C Input: under control of main function Output: under control of main function Value: 2 The purpose of this assignment is to perform some vector processing. Two different versions

More information

Due Date: See Blackboard

Due Date: See Blackboard Source File: ~/2305/lab33.C Input: under control of main function Output: under control of main function Value: 3 The Shell sort, named after its inventor Donald Shell, provides a simple and efficient

More information

Lab 6 Due Date: Wednesday, April 5, /usr/local/3302/include/direct linking loader.h Driver File:

Lab 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 information

Lab 2: ADT Design & Implementation

Lab 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 information

Circle all of the following which would make sense as the function prototype.

Circle all of the following which would make sense as the function prototype. Student ID: Lab Section: This test is closed book, closed notes. Points for each question are shown inside [ ] brackets at the beginning of each question. You should assume that, for all quoted program

More information

Overloading Operators in C++

Overloading Operators in C++ Overloading Operators in C++ C++ allows the programmer to redefine the function of most built-in operators on a class-by-class basis the operator keyword is used to declare a function that specifies what

More information

Abstract Data Types (ADTs) 1. Legal Values. Client Code for Rational ADT. ADT Design. CS 247: Software Engineering Principles

Abstract Data Types (ADTs) 1. Legal Values. Client Code for Rational ADT. ADT Design. CS 247: Software Engineering Principles Abstract Data Types (ADTs) CS 247: Software Engineering Principles ADT Design An abstract data type (ADT) is a user-defined type that bundles together: the range of values that variables of that type can

More information

CS 247: Software Engineering Principles. ADT Design

CS 247: Software Engineering Principles. ADT Design CS 247: Software Engineering Principles ADT Design Readings: Eckel, Vol. 1 Ch. 7 Function Overloading & Default Arguments Ch. 12 Operator Overloading U Waterloo CS247 (Spring 2017) p.1/17 Abstract Data

More information

Set Implementation Version 1

Set Implementation Version 1 Introduction to System Programming 234122 Set Implementation Version 1 Masha Nikolski, CS Department, Technion 1 // Version 1.0 2 // Header file for set class. 3 // In this implementation set is a container

More information

Reference Parameters A reference parameter is an alias for its corresponding argument in the function call. Use the ampersand (&) to indicate that

Reference Parameters A reference parameter is an alias for its corresponding argument in the function call. Use the ampersand (&) to indicate that Reference Parameters There are two ways to pass arguments to functions: pass-by-value and pass-by-reference. pass-by-value A copy of the argument s value is made and passed to the called function. Changes

More information

Object oriented programming

Object oriented programming Exercises 7 Version 1.0, 11 April, 2017 Table of Contents 1. Inheritance.................................................................. 1 1.1. Tennis Player...........................................................

More information

Lecture 7. Log into Linux New documents posted to course webpage

Lecture 7. Log into Linux New documents posted to course webpage Lecture 7 Log into Linux New documents posted to course webpage Coding style guideline; part of project grade is following this Homework 4, due on Monday; this is a written assignment Project 1, due next

More information

CS 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, 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 information

Programming Assignment 3

Programming Assignment 3 CISC2000/2010, CS2, Fall 2018 1 Programming Assignment 3 You can choose one of two options for this assignment: 1. Write a program to practice working with arrays of chars terminated using special char

More information

1- Write a single C++ statement that: A. Calculates the sum of the two integrates 11 and 12 and outputs the sum to the consol.

1- Write a single C++ statement that: A. Calculates the sum of the two integrates 11 and 12 and outputs the sum to the consol. 1- Write a single C++ statement that: A. Calculates the sum of the two integrates 11 and 12 and outputs the sum to the consol. B. Outputs to the console a floating point number f1 in scientific format

More information

Review: C++ Basic Concepts. Dr. Yingwu Zhu

Review: 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 information

More Advanced Class Concepts

More Advanced Class Concepts More Advanced Class Concepts Operator overloading Inheritance Templates PH (RH) (Roger.Henriksson@cs.lth.se) C++ Programming 2016/17 146 / 281 Operator Overloading In most programming languages some operators

More information

Ch 6. Functions. Example: function calls function

Ch 6. Functions. Example: function calls function Ch 6. Functions Part 2 CS 1428 Fall 2011 Jill Seaman Lecture 21 1 Example: function calls function void deeper() { cout

More information

CSI33 Data Structures

CSI33 Data Structures Outline Department of Mathematics and Computer Science Bronx Community College November 9, 2016 Outline Outline 1 Chapter 9: C++ Classes Outline Chapter 9: C++ Classes 1 Chapter 9: C++ Classes Class Syntax

More information

The American University in Cairo Department of Computer Science & Engineering CSCI &09 Dr. KHALIL Exam-I Fall 2011

The American University in Cairo Department of Computer Science & Engineering CSCI &09 Dr. KHALIL Exam-I Fall 2011 The American University in Cairo Department of Computer Science & Engineering CSCI 106-07&09 Dr. KHALIL Exam-I Fall 2011 Last Name :... ID:... First Name:... Form I Section No.: EXAMINATION INSTRUCTIONS

More information

G52CPP C++ Programming Lecture 17

G52CPP 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 information

The American University in Cairo Computer Science & Engineering Department CSCE Dr. KHALIL Exam II Spring 2010

The American University in Cairo Computer Science & Engineering Department CSCE Dr. KHALIL Exam II Spring 2010 The American University in Cairo Computer Science & Engineering Department CSCE 106-08 Dr. KHALIL Exam II Spring 2010 Last Name :... ID:... First Name:... Form - I EXAMINATION INSTRUCTIONS * Do not turn

More information

CSCE 110 PROGRAMMING FUNDAMENTALS

CSCE 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 information

EINDHOVEN UNIVERSITY OF TECHNOLOGY Department of Mathematics and Computer Science

EINDHOVEN UNIVERSITY OF TECHNOLOGY Department of Mathematics and Computer Science EINDHOVEN UNIVERSITY OF TECHNOLOGY Department of Mathematics and Computer Science Written examination Homologation C++ and Computer Organization (2DMW00) Part I: C++ - on Tuesday, November 1st 2016, 9:00h-12:00h.

More information

Introduction to C++ (Extensions to C)

Introduction to C++ (Extensions to C) Introduction to C++ (Extensions to C) C is purely procedural, with no objects, classes or inheritance. C++ is a hybrid of C with OOP! The most significant extensions to C are: much stronger type checking.

More information

THE INTEGER DATA TYPES. Laura Marik Spring 2012 C++ Course Notes (Provided by Jason Minski)

THE INTEGER DATA TYPES. Laura Marik Spring 2012 C++ Course Notes (Provided by Jason Minski) THE INTEGER DATA TYPES STORAGE OF INTEGER TYPES IN MEMORY All data types are stored in binary in memory. The type that you give a value indicates to the machine what encoding to use to store the data in

More information

Operator Overloading

Operator Overloading Steven Zeil November 4, 2013 Contents 1 Operators 2 1.1 Operators are Functions.... 2 2 I/O Operators 4 3 Comparison Operators 6 3.1 Equality Operators....... 11 3.2 Less-Than Operators...... 13 1 1 Operators

More information

Chapter 18 - C++ Operator Overloading

Chapter 18 - C++ Operator Overloading Chapter 18 - C++ Operator Overloading Outline 18.1 Introduction 18.2 Fundamentals of Operator Overloading 18.3 Restrictions on Operator Overloading 18.4 Operator Functions as Class Members vs. as friend

More information

Note 11/13/2014. They are like those i s, j s, and temp s that appear and disappear when the function starts and finishes...

Note 11/13/2014. They are like those i s, j s, and temp s that appear and disappear when the function starts and finishes... CISC 2000 Computer Science II Fall, 2014 Note 11/13/2014 1 Review of operator overloading (a) Lab class: take-away ############################ # Pass-by-value parameters # ############################

More information

III. Classes (Chap. 3)

III. Classes (Chap. 3) III. Classes III-1 III. Classes (Chap. 3) As we have seen, C++ data types can be classified as: Fundamental (or simple or scalar): A data object of one of these types is a single object. int, double, char,

More information

CSS 342 Data Structures, Algorithms, and Discrete Mathematics I. Lecture 2. Yusuf Pisan

CSS 342 Data Structures, Algorithms, and Discrete Mathematics I. Lecture 2. Yusuf Pisan CSS 342 Data Structures, Algorithms, and Discrete Mathematics I Lecture 2 Yusuf Pisan Compiled helloworld yet? Overview C++ fundamentals Assignment-1 CSS Linux Cluster - submitting assignment Call by Value,

More information

Agenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures

Agenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures The main body and cout Agenda 1 Fundamental data types Declarations and definitions Control structures References, pass-by-value vs pass-by-references The main body and cout 2 C++ IS AN OO EXTENSION OF

More information

Linked List using a Sentinel

Linked 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 information

Use the dot operator to access a member of a specific object.

Use the dot operator to access a member of a specific object. Lab 16 Class A class is a data type that can contain several parts, which are called members. There are two types of members, data member and functions. An object is an instance of a class, and each object

More information

CS3157: Advanced Programming. Outline

CS3157: Advanced Programming. Outline CS3157: Advanced Programming Lecture #12 Apr 3 Shlomo Hershkop shlomo@cs.columbia.edu 1 Outline Intro CPP Boring stuff: Language basics: identifiers, data types, operators, type conversions, branching

More information

Total 100. The American University in Cairo Computer Science & Engineering Department CSCE 106. Dr. Khalil Exam II Fall 2011

Total 100. The American University in Cairo Computer Science & Engineering Department CSCE 106. Dr. Khalil Exam II Fall 2011 The American University in Cairo Computer Science & Engineering Department CSCE 106 Dr. Khalil Exam II Fall 2011 Last Name :... ID:... First Name:... Form I Section No.: ( ) EXAMINATION INSTRUCTIONS *

More information

for (int i = 1; i <= 3; i++) { do { cout << "Enter a positive integer: "; cin >> n;

for (int i = 1; i <= 3; i++) { do { cout << Enter a positive integer: ; cin >> n; // Workshop 1 #include using namespace std; int main () int n, k; int sumdigits; for (int i = 1; i n; cin.clear (); cin.ignore (100,

More information

CMSC 202 Midterm Exam 1 Fall 2015

CMSC 202 Midterm Exam 1 Fall 2015 1. (15 points) There are six logic or syntax errors in the following program; find five of them. Circle each of the five errors you find and write the line number and correction in the space provided below.

More information

CSE 333. Lecture 9 - intro to C++ Hal Perkins Department of Computer Science & Engineering University of Washington

CSE 333. Lecture 9 - intro to C++ Hal Perkins Department of Computer Science & Engineering University of Washington CSE 333 Lecture 9 - intro to C++ Hal Perkins Department of Computer Science & Engineering University of Washington Administrivia New exercise posted yesterday afternoon, due Monday morning - Read a directory

More information

Object oriented programming

Object oriented programming Exercises 12 Version 1.0, 9 May, 2017 Table of Contents 1. Virtual destructor and example problems...................................... 1 1.1. Virtual destructor.......................................................

More information

#include <iostream> #include <algorithm> #include <cmath> using namespace std; int f1(int x, int y) { return (double)(x/y); }

#include <iostream> #include <algorithm> #include <cmath> using namespace std; int f1(int x, int y) { return (double)(x/y); } 1. (9 pts) Show what will be output by the cout s in this program. As in normal program execution, any update to a variable should affect the next statement. (Note: boolalpha simply causes Booleans to

More information

struct Buffer { Buffer(int s) { buf = new char[s]; } ~Buffer() { delete [] buf; } char *buf; };

struct Buffer { Buffer(int s) { buf = new char[s]; } ~Buffer() { delete [] buf; } char *buf; }; struct Buffer { Buffer(int s) { buf = new char[s]; ~Buffer() { delete [] buf; char *buf; ; struct FBuffer : public Buffer { FBuffer(int s) : Buffer(s) { f = fopen("file", "w"); ~FBuffer() { fclose(f);

More information

A <Basic> C++ Course

A <Basic> C++ Course A C++ Course 5 Constructors / destructors operator overloading Julien Deantoni adapted from Jean-Paul Rigault courses This Week A little reminder Constructor / destructor Operator overloading Programmation

More information

A <Basic> C++ Course

A <Basic> C++ Course A C++ Course 5 Constructors / destructors operator overloading Julien DeAntoni adapted from Jean-Paul Rigault courses 1 2 This Week A little reminder Constructor / destructor Operator overloading

More information

Midterm Practice Exam

Midterm Practice Exam Name: CS 410 Introduction to Software Engineering Fall 2016 Instructor: Marc Pomplun Midterm Practice Exam Duration: 75 minutes No books, no notes, and no calculators are allowed. Question 1: out of points

More information

Distributed Real-Time Control Systems. Lecture 17 C++ Programming Intro to C++ Objects and Classes

Distributed Real-Time Control Systems. Lecture 17 C++ Programming Intro to C++ Objects and Classes Distributed Real-Time Control Systems Lecture 17 C++ Programming Intro to C++ Objects and Classes 1 Bibliography Classical References Covers C++ 11 2 What is C++? A computer language with object oriented

More information

Non-numeric types, boolean types, arithmetic. operators. Comp Sci 1570 Introduction to C++ Non-numeric types. const. Reserved words.

Non-numeric types, boolean types, arithmetic. operators. Comp Sci 1570 Introduction to C++ Non-numeric types. const. Reserved words. , ean, arithmetic s s on acters Comp Sci 1570 Introduction to C++ Outline s s on acters 1 2 3 4 s s on acters Outline s s on acters 1 2 3 4 s s on acters ASCII s s on acters ASCII s s on acters Type: acter

More information

Chapter 1 INTRODUCTION

Chapter 1 INTRODUCTION Chapter 1 INTRODUCTION A digital computer system consists of hardware and software: The hardware consists of the physical components of the system. The software is the collection of programs that a computer

More information

Ch 2 ADTs and C++ Classes

Ch 2 ADTs and C++ Classes Ch 2 ADTs and C++ Classes Object Oriented Programming & Design Constructing Objects Hiding the Implementation Objects as Arguments and Return Values Operator Overloading 1 Object-Oriented Programming &

More information

Makefiles Makefiles should begin with a comment section of the following form and with the following information filled in:

Makefiles Makefiles should begin with a comment section of the following form and with the following information filled in: CS 215 Fundamentals of Programming II C++ Programming Style Guideline Most of a programmer's efforts are aimed at the development of correct and efficient programs. But the readability of programs is also

More information

Strings and Stream I/O

Strings 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 information

Total 100. The American University in Cairo Computer Science & Engineering Department CSCE 106. Instructor: Final Exam Fall Section No.

Total 100. The American University in Cairo Computer Science & Engineering Department CSCE 106. Instructor: Final Exam Fall Section No. The American University in Cairo Computer Science & Engineering Department CSCE 106 Instructor: Final Exam Fall 2010 Last Name :... ID:... First Name:... Section No.: EXAMINATION INSTRUCTIONS * Do not

More information

Homework 5. Yuji Shimojo CMSC 330. Instructor: Prof. Reginald Y. Haseltine

Homework 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

Vectors of Pointers to Objects. Vectors of Objects. Vectors of unique ptrs C++11. Arrays of Objects

Vectors of Pointers to Objects. Vectors of Objects. Vectors of unique ptrs C++11. Arrays of Objects Vectors of Objects As we have mentioned earlier, you should almost always use vectors instead of arrays. If you need to keep track of persons (objects of class Person), you must decide what to store in

More information

Short Notes of CS201

Short Notes of CS201 #includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system

More information

Unit Testing. Contents. Steven Zeil. July 22, Types of Testing 2. 2 Unit Testing Scaffolding Drivers Stubs...

Unit Testing. Contents. Steven Zeil. July 22, Types of Testing 2. 2 Unit Testing Scaffolding Drivers Stubs... Steven Zeil July 22, 2013 Contents 1 Types of Testing 2 2 6 2.1 Scaffolding................. 7 2.1.1 Drivers............... 7 2.1.2 Stubs................ 13 3 Integration Testing 17 1 1 Types of Testing

More information

CS201 - Introduction to Programming Glossary By

CS201 - Introduction to Programming Glossary By CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with

More information

System Design and Programming II

System Design and Programming II System Design and Programming II CSCI 194 Section 01 CRN: 20220 Spring 2016 David L. Sylvester, Sr., Assistant Professor Chapter 15 Inheritance, Polymorphism, And Virtual Functions What is Inheritance?

More information

EECE.3220: Data Structures Spring 2017

EECE.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 information

Unit Testing. Steven Zeil. July 22, Types of Testing 2. 2 Unit Testing Scaffolding Drivers Stubs...

Unit Testing. Steven Zeil. July 22, Types of Testing 2. 2 Unit Testing Scaffolding Drivers Stubs... Steven Zeil July 22, 2013 Contents 1 Types of Testing 2 2 Unit Testing 4 2.1 Scaffolding............ 4 2.1.1 Drivers.......... 4 2.1.2 Stubs........... 9 3 Integration Testing 12 1 1 Types of Testing Testing

More information

Object-oriented Programming for Automation & Robotics Carsten Gutwenger LS 11 Algorithm Engineering

Object-oriented Programming for Automation & Robotics Carsten Gutwenger LS 11 Algorithm Engineering Object-oriented Programming for Automation & Robotics Carsten Gutwenger LS 11 Algorithm Engineering Lecture 3 Winter 2011/12 Oct 25 Visual C++: Problems and Solutions New section on web page (scroll down)

More information

Searching Algorithms. Chapter 11

Searching Algorithms. Chapter 11 Data Structures Dr Ahmed Rafat Abas Computer Science Dept, Faculty of Computer and Information, Zagazig University arabas@zu.edu.eg http://www.arsaliem.faculty.zu.edu.eg/ Searching Algorithms Chapter 11

More information

CSCE 110 PROGRAMMING FUNDAMENTALS

CSCE 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 information

UEE1303(1070) S12: Object-Oriented Programming Constant Pointer and Class

UEE1303(1070) S12: Object-Oriented Programming Constant Pointer and Class UEE1303(1070) S12: Object-Oriented Programming Constant Pointer and Class What you will learn from Lab 4 In this laboratory, you will learn how to use const to identify constant pointer and the basic of

More information

Object-Oriented Programming in C++

Object-Oriented Programming in C++ Object-Oriented Programming in C++ Pre-Lecture 9: Advanced topics Prof Niels Walet (Niels.Walet@manchester.ac.uk) Room 7.07, Schuster Building March 24, 2015 Prelecture 9 Outline This prelecture largely

More information

CSE 333 Midterm Exam July 24, Name UW ID#

CSE 333 Midterm Exam July 24, Name UW ID# Name UW ID# There are 6 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,

More information

Jordan University of Science & Technology Department of Computer Science CS 211 Exam #1 (23/10/2010) -- Form A

Jordan University of Science & Technology Department of Computer Science CS 211 Exam #1 (23/10/2010) -- Form A Jordan University of Science & Technology Department of Computer Science CS 211 Exam #1 (23/10/2010) -- Form A Name: ID#: Section #: Day & Time: Instructor: Answer all questions as indicated. Closed book/closed

More information

CS2141 Software Development using C/C++ C++ Basics

CS2141 Software Development using C/C++ C++ Basics CS2141 Software Development using C/C++ C++ Basics Integers Basic Types Can be short, long, or just plain int C++ does not define the size of them other than short

More information

Object oriented programming

Object oriented programming Exercises 6 Version 1.0, 21 March, 2017 Table of Contents 1. Operators overloading....................................................... 1 1.1. Example 1..............................................................

More information

Variables. Data Types.

Variables. Data Types. Variables. Data Types. The usefulness of the "Hello World" programs shown in the previous section is quite questionable. We had to write several lines of code, compile them, and then execute the resulting

More information

The American University in Cairo Computer Science & Engineering Department CSCE 106 Fundamentals of Computer Science. Instructor: Final Exam Fall 2011

The American University in Cairo Computer Science & Engineering Department CSCE 106 Fundamentals of Computer Science. Instructor: Final Exam Fall 2011 The American University in Cairo Computer Science & Engineering Department CSCE 106 Fundamentals of Computer Science Instructor: Final Exam Fall 2011 Last Name :... ID:... First Name:... Section No.: EXAMINATION

More information

Review. What is const member data? By what mechanism is const enforced? How do we initialize it? How do we initialize it?

Review. What is const member data? By what mechanism is const enforced? How do we initialize it? How do we initialize it? Review Describe pass-by-value and pass-by-reference Why do we use pass-by-reference? What does the term calling object refer to? What is a const member function? What is a const object? How do we initialize

More information

Appendix M: Introduction to Microsoft Visual C Express Edition

Appendix 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 information

CSC 306 LEXICAL ANALYSIS PROJECT SPRING 2017

CSC 306 LEXICAL ANALYSIS PROJECT SPRING 2017 CSC 306 LEXICAL ANALYSIS PROJECT SPRING 2017 PROF. GODFREY C. MUGANDA DEPARTMENT OF COMPUTER SCIENCE In this assignment, we take the first step in writing a compiler for the NINC programming language,

More information

Study Guide for Test 2

Study Guide for Test 2 Study Guide for Test 2 Topics: decisions, loops, arrays, c-strings, linux Material Selected from: Chapters 4, 5, 6, 7, 10.1, 10.2, 10.3, 10.4 Examples 14 33 Assignments 4 8 Any syntax errors are unintentional

More information

Module 9. Templates & STL

Module 9. Templates & STL Module 9 Templates & STL Objectives In this module Learn about templates Construct function templates and class templates STL 2 Introduction Templates: enable you to write generic code for related functions

More information

Lab 2: Pointers. //declare a pointer variable ptr1 pointing to x. //change the value of x to 10 through ptr1

Lab 2: Pointers. //declare a pointer variable ptr1 pointing to x. //change the value of x to 10 through ptr1 Lab 2: Pointers 1. Goals Further understanding of pointer variables Passing parameters to functions by address (pointers) and by references Creating and using dynamic arrays Combing pointers, structures

More information

CS 247: Software Engineering Principles. Modules

CS 247: Software Engineering Principles. Modules CS 247: Software Engineering Principles Modules Readings: Eckel, Vol. 1 Ch. 2 Making and Using Objects: The Process of Language Translation Ch. 3 The C in C++: Make: Managing separate compilation Ch. 10

More information

Outline. 1 Function calls and parameter passing. 2 Pointers, arrays, and references. 5 Declarations, scope, and lifetimes 6 I/O

Outline. 1 Function calls and parameter passing. 2 Pointers, arrays, and references. 5 Declarations, scope, and lifetimes 6 I/O Outline EDAF30 Programming in C++ 2. Introduction. More on function calls and types. Sven Gestegård Robertz Computer Science, LTH 2018 1 Function calls and parameter passing 2 Pointers, arrays, and references

More information

Chapter 7: Stacks. Exercises 7.2

Chapter 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 information

UEE1303(1070) S 12 Object-Oriented Programming in C++

UEE1303(1070) S 12 Object-Oriented Programming in C++ Computational Intelligence on Automation Lab @ NCTU Learning Objectives UEE1303(1070) S 12 Object-Oriented Programming in C++ Lecture 06: Streams and File Input/Output I/O stream istream and ostream member

More information

Introduction to C++ Systems Programming

Introduction to C++ Systems Programming Introduction to C++ Systems Programming Introduction to C++ Syntax differences between C and C++ A Simple C++ Example C++ Input/Output C++ Libraries C++ Header Files Another Simple C++ Example Inline Functions

More information

IV. 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. 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 information

Module Operator Overloading and Type Conversion. Table of Contents

Module Operator Overloading and Type Conversion. Table of Contents 1 Module - 33 Operator Overloading and Type Conversion Table of Contents 1. Introduction 2. Operator Overloading 3. this pointer 4. Overloading Unary Operators 5. Overloading Binary Operators 6. Overloading

More information

CISC 2200 Data Structure Fall, C++ Review:3/3. 1 From last lecture:

CISC 2200 Data Structure Fall, C++ Review:3/3. 1 From last lecture: CISC 2200 Data Structure Fall, 2016 C++ Review:3/3 1 From last lecture: pointer type and pointer variable (stores memory addresses of a variable (of any type, local or global, automatic/static/dynamic)

More information

Introduction to Programming

Introduction to Programming Introduction to Programming session 6 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Spring 2011 These slides are created using Deitel s slides Sharif University of Technology Outlines

More information

G52CPP C++ Programming Lecture 14. Dr Jason Atkin

G52CPP C++ Programming Lecture 14. Dr Jason Atkin G52CPP C++ Programming Lecture 14 Dr Jason Atkin 1 Last Lecture Automatically created methods: A default constructor so that objects can be created without defining a constructor A copy constructor used

More information

PIC 10A. Lecture 17: Classes III, overloading

PIC 10A. Lecture 17: Classes III, overloading PIC 10A Lecture 17: Classes III, overloading Function overloading Having multiple constructors with same name is example of something called function overloading. You are allowed to have functions with

More information

Operator Overloading in C++ Systems Programming

Operator Overloading in C++ Systems Programming Operator Overloading in C++ Systems Programming Operator Overloading Fundamentals of Operator Overloading Restrictions on Operator Overloading Operator Functions as Class Members vs. Global Functions Overloading

More information