Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Creating and Using a Class, Overloading Operator Functions - 2004 | CSCI 152, Assignments of Computer Science

Material Type: Assignment; Class: Programming Fundamentals II; Subject: Computer Science - CSCI; University: Texas A & M University-Commerce; Term: Fall 2004;

Typology: Assignments

Pre 2010

Uploaded on 08/19/2009

koofers-user-3qn-1
koofers-user-3qn-1 🇺🇸

10 documents

1 / 2

Toggle sidebar

Related documents


Partial preview of the text

Download Creating and Using a Class, Overloading Operator Functions - 2004 | CSCI 152 and more Assignments Computer Science in PDF only on Docsity! CSCI 152.2 Program 6 Fall 2004 Due: Wed, 1 Dec Emphasis on: Creating and using a class, Overloading Operator Functions For program 6, you are to revisit program 2 to implement a set as a class. Your private variables will be an array of ints to represent a set and an int to store the number of values currently in the set. You should provide public operations of: 1) Create and initialize an empty set (a constructor which sets size to zero) 2) Reset an existing set to empty (reset size to zero) 3) Add one value to a set 4) Set union 5) Set intersection 6) Set difference 7) Output a set Removing duplicates, sorting, and searching could be implemented as private operations, since a client would probably not need to use those operations directly. However, you can make them public if you want to. Your client application program will read set values from a text file as before, and your output should be the same as it was for program 2. Program 6 Requirements: 1) You may not use the Standard Template set type or other predefined set functions. 2) You may assume that the data will be valid positive integers. 3) All sets should be maintained in ascending order with no duplicates. 4) Sets should be output as shown in the examples (values printed with a space or a comma between consecutive values and enclosed in curly braces). 5) The union, intersection, difference, and output functions in the class should be implemented as overloaded operator functions. If you want to implement the “Add one value to the set” operation as an operator function, overload operator+= (with return type of void) rather than operator+. Here’s a copy of the original Program 2 assignment (minus the program 2 requirements): CSCI 152.2 Program 2 Spring 2004 Due: Thursday, 19 Feb Emphasis on: One-Dimensional Arrays, Sorting, Searching, Input from a file In the mathematical theory of sets, a set is defined as a collection of distinct (no two alike) items of the same type. In some programming languages, sets are a built-in data type. C+ + does not have a built-in set type, though the Standard Template Library does provide a set type as an add-on to the language. We can simulate a set in any language using a one- dimensional array. There are several operations that can be performed on sets. We will consider only three of them: union, intersection, and difference. These are binary operations requiring two sets as operands.  The union of two sets A and B (A + B), is a set that contains elements that are in A or in B or in both.  The intersection of two sets A and B (A * B) is a set that contains elements common to both A and B.  The difference of two sets A and B (A - B) is a set that contains only the elements which are in A but not in B.
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved