Sale!

CSc 346 Assignment 5 solved

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

Download Details:

  • Name: Ahmed5-incfsg.zip
  • Type: zip
  • Size: 98.13 KB

Category:

Description

5/5 - (1 vote)

CSc 346 Assignment 5

Use Linux to create a user-defined Abstract Data Type (ADT) using a C++ class named Fraction along with an
appropriate set of C++ header/implementation files as discussed in class.
The Fraction 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 class 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
operator= assigns a passed in fraction to the invoking fraction a = b
handle self-assignment
operator+ adds a passed in fraction to the invoking fraction a + b
operator* multiplies the invoking fraction by a passed in fraction a * b
operator++ adds 1 to the invoking fraction ++a and a++
operator– negates the invoking fraction –a

operator int converts the passed in fraction to int int( a )
operator float converts the passed in fraction to float float( a )
operator bool converts the passed in fraction to bool bool( a )
Fraction class Non-Exportable Operations: (declared .h file and defined .cpp file)
reduce use where necessary at the end of operations 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
Fraction class non-member Friend Operations: (declared .h file and define .cpp file)
operator– subtracts a second passed in fraction from the first passed in fraction a – b
operator/ divides a second passed in fraction into the first passed in fraction a / b
operator– subtracts 1 from the passed in fraction –a and a–

operator! inverts the passed in fraction !a
Fraction class non-member Operations: (declare .h file and define .cpp file)
operator== true if both passed in fractions are equal a == b
false otherwise

operator< true if first passed in fraction is less than second passed in fraction a < b false otherwise operator> true if first passed in fraction is greater than the second passed in fraction a > b
false otherwise
operator<< replaces the view function from assignment 4 cout << a operator>> reads in the numerator and denominator values cin >> a
prompt for values externally

CSc 346 Assignment 5

Notes:

• Think of how the operators affect primitive data type values.
o E.g., is/are the value(s) applied to the operator modified by the operation?
§ a = b a is modified b is not modified
§ a + b a is not modified b is not modified

• Do not allow the denominator to become 0 – provide appropriate user feedback.
o Constructor uses defaults – 0/1
o Other operations – do not complete the operation – do not modify any instances
Required Output Format (operator<<) // do not apply endl after
// treat like any other value

0 0/1 // numerator 0 denominator 1 // cout << a << endl;
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

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

I will write a test program that will include your Fraction 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: Lastname5.zip or Lastname5.7z // I would use Gamradt5.zip

CSc 346 Assignment 5

Project Folder: Lastname5 // I would use Gamradt5
• Fraction.h Fraction class header file
• Fraction.cpp Fraction class implementation file
• main.cpp driver program file // I will use my own
• CMakeLists.txt // No C++ 11

o Project name: Lastname5 // 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 – a5 // I would use

Fraction/Friend ADT include sequence with multiple modules: // Never include .cpp files
main.cpp Fraction.h Fraction.cpp
Fraction ADT building with multiple modules: // Using cmake

1. Place all files in the project folder (see above) // I would use Gamradt5
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 5