Sale!

CSc 346 Assignment 4 solved

Original price was: $35.00.Current price is: $30.00. $25.50

Category:

Description

5/5 - (1 vote)

CSc 346 Assignment 4

Use Linux to create a user-defined Abstract Data Type (ADT) using C++ classes named Fraction and Friend
along with an appropriate set of C++ header/implementation files as discussed in class.
• The Fraction class describes the current state of a Fraction class instance.
• The Friend class provides additional method support for the Fraction class instance.
• The Fraction and Friend classes define the FractionNS namespace.
o The Fraction and Friend classes do not use this namespace.

The Friend class provides additional method support for the Fraction class, but the Fraction class does not
need to see the Friend class.
The UML diagram does not show:
• access specifies: public, protected, private
• default values: arguments, attributes, …
• use of the const keyword

• function inlining implementations: explicit, implicit
• enumeration implementations: public, private
The Fraction/Friend ADT must define and implement the following data types and operations.
• Do not add to or modify the public interface (exportable components – public components).
• Do not add to or modify any attributes or data types (storage components).

Fraction Exportable Operations: (declared .h file and defined .cpp file)
Fraction default/parameterized constructor
• 0 is the default numerator value – int (signed)
• 1 is the default denominator value – int (unsigned)

• if an invalid fraction is defined then use the default values
Fraction copy constructor – creates an exact copy of an existing Fraction class instance
~Fraction destructor function – no dynamic memory used – does nothing (no message)
getters/setters each private attribute includes an appropriate standard method getter/setter pair
setters support default arguments
implemented using explicit function inlining

copy copies a passed in fraction to the invoking fraction (1) (2)
add adds a passed in fraction to the invoking fraction (1) (2)
multiply multiplies the invoking fraction by a passed in fraction (1) (2)
increment adds 1 to the invoking fraction (1)
negate negates the invoking fraction (1)

compare compares the invoking fraction to a passed in fraction (2)
returns: -1 less than 0 equal 1 greater than
toInt converts the invoking fraction to int
toFloat converts the invoking fraction to float
view displays the current state of the invoking fraction
Fraction Non-Exportable Operations: (declared .h file and defined .cpp file)

reduce use at the end of operations where necessary to maintain a reduced fraction
2 / 6 => 1 / 3 14 / 10 => 7 / 5 – 21 / 7 => – 3 / 1
gcd returns the greatest common divisor – use an iterative implementation
Friend Exportable Operations: (declared .h file and define .cpp file)
~Friend destructor function – no dynamic memory used – does nothing (no message)
subtract subtracts a second passed in fraction from the first passed in fraction (1) (2) (3)
divide divides a second passed in fraction into the first passed in fraction (1) (2) (3)
decrement subtracts 1 from the passed in fraction (1) (2) (3)

invert inverts the passed in fraction (1) (2) (3)
toBool converts the passed in fraction to bool (2) (3)
Friend Non-Exportable Operations: (declared .h file and defined .cpp file)
Friend default constructor – no attributes
Friend copy constructor – no attributes

CSc 346 Assignment 4

Notes:

1. Supports function chaining with Fraction class instances
o return invoking instance: Fraction class methods
o return first passed in instance: Friend class methods
2. Requires Fraction instance(s) be passed
o modified instance: Fraction &

§ first passed argument with binary operations
o unmodified instance: const Fraction &
3. class (static) methods NOT instance (non-static) methods
o Friend class is not instantiated

4. Do not allow the denominator to become 0 – provide appropriate user feedback
Required Output Format (view)
0 0/1 // numerator 0 denominator 1
0 1/3 // numerator 1 denominator 3
– 0 2/5 // numerator –2 denominator 5

1 0/1 // numerator 1 denominator 1
2 1/4 // numerator 9 denominator 4
– 1 2/5 // numerator –7 denominator 5
Fraction resource web site:
• http://www.helpwithfractions.com/

Only apply function inlining implementation techniques where stated.
• All other functions are declared and defined using standard techniques supporting implementation hiding.
Apply the const keyword “wherever” appropriate.
• functions, arguments, … // E.g. getter, view, … functions

Apply function reuse “everywhere” possible.
• Think of how each of the operations is related to the other operations and apple reuse
• E.g. increment can be implemented simply by using addition where the second value is 1
• E.g. subtract can be implemented simply by using negate and add with the second value
• Some reuse will require the instantiation of temporary Fraction class instances
Make sure that you completely document the header/implementation files.

• The header (.h) file tells the user exactly how to use your ADT
o General descriptions only – do not include implementation details
• The implementation file (.cpp) tells the implementer/programmer exactly how the ADT works
o Detailed descriptions – include implementation details

CSc 346 Assignment 4

Add appropriate guards and macros to prevent multiple inclusions of the individual ADT modules.
The Fraction/Friend ADT exists entirely within the FractionNS namespace.
• “Using Directive” to access the FractionNS namespace members – outside Fraction/Friend ADT only.
• “Using Declarations” to access the std namespace members: cin, cout, endl, etc… – apply to each scope.

I will write a test program that will include your Fraction/Friend ADT so all header/implementation files
tested must use common names. So you MUST use:
• the EXACT same names for each data type and function in the header/implementation files.
• the EXACT same function argument sequence in the header/implementation files.

Zip together and e-mail your Project Folder using the following naming convention.
• Do not e-mail your main/driver program used for testing purposes
o I will create my own main/driver program to test your ADT

Archieve Name: Lastname4.zip or Lastname4.7z // I would use Gamradt4.zip
Project Folder: Lastname4 // I would use Gamradt4
• Fraction.h Fraction class header file
• Fraction.cpp Fraction class implementation file

• Friend.h Friend class header file
• Friend.cpp Friend class implementation file
• main.cpp driver program file // I will use my own
• CMakeLists.txt // No C++ 11
o Project name: Lastname4 // I would use Gamradt4
o Executable name: math

List the class number, your Linux username, and assignment number as the e-mail message subject:
SUBJECT: csc346 – gamradtk – a4 // I would use
Fraction/Friend ADT include sequence with multiple modules: // Never include .cpp files
Fraction.h Fraction.cpp

main.cpp Friend.h Friend.cpp
Fraction/Friend ADT building with multiple modules: // Using cmake
1. Place all files in the project folder (see above) // I would use Gamradt4
2. cmake -G “Unix Makefiles” // Generate Makefile

3. cmake –build . // Build project – create executable
4. ./math // Run project
Note: when submitting remove all files and folders created by the build process
• See above for required files in the submitted project folder
CSc 346 Assignment 4