CS 3005: Programming in C++
Difference
Introduction
The subtraction operation is also known as the difference between two numbers. When subtracting two numbers there are specific names for each of the numbers. For example, in this expression,
c = a - b
a
is the Minuend, b
is the SubMinuend, and c
is the difference.
Task
In this task, you will make a program that allows the user to input
two double
numbers and display the difference of the two numbers.
The program’s exit code will be 2 if the difference is positive,
1 if the difference is negative, and 0 if the difference is zero.
An few interactions with the program may look like this:
$ ./program-difference/difference
Minuend? 3.4
Subtrahend? 1.9
Difference 1.5
$ echo $?
2
$ ./program-difference/difference
Minuend? 73.2
Subtrahend? 100
Difference -26.8
$ echo $?
1
$ ./program-difference/difference
Minuend? 46.7
Subtrahend? 46.7
Difference 0
$ echo $?
0
Programming Requirements
Create library-commands/difference_aux.{h,cpp}
Functions:
int difference(ApplicationData& app_data);
Asks the user for the “Minuend? ” and “Subtrahend? “. Calculates the difference and displays it, as shown in the examples above. The return value from this function is 0 if the difference is zero, 1 if the difference is negative, and 2 if the difference is positive.
Update library-commands/Makefile
Add difference_aux.{h,cpp}
in the appropriate places to add them to the library and install the header file.
Create program-difference/difference.cpp
Functions:
int main();
Entry point to the difference program. Should create anApplicationData
and pass it to thedifference
function found indifference_aux
and return the result of that function call.
Create program-difference/Makefile
This file must contain rules such that any of the following commands will build the difference
program:
make
make all
make difference
Create program-difference/.gitignore
The file program-difference/.gitignore
needs to store one line of text:
difference
This will prevent the executable program from being committed to the repository. It is a derived file.
Update Makefile
- Update the project-level Makefile so that
make
andmake all
in the project directory will callmake
in theprogram-difference
directory. - If necessary, make sure the order of make commands is correct to build prerequisite libraries in the correct order.
Additional Documentation
- None
Grading Instructions
To receive credit for this assignment:
- your code must be pushed to your repository for this class on GitHub
- all unit tests must pass
- all acceptance tests must pass
- all programs must build, run, and execute as described in the assignment descriptions.
Last Updated 02/04/2025