Jump to content

I know I'm way overthinking this probably and this is definitely the most complex program I've done so far but the assignment instructions are to:

Create a Program that uses functions Defined with Arguments that include Pass-By-Value and Pass-By-Reference

Use Prototypes Above the main() function

Define the functions used in main() below main() and match their signatures

Do the workshop with your Instructor in class on overloading the add function

Overload your own subtraction - multiplication - division - and power Functions for three different data types in one program for IP-03

 

Am I on the right track or naw?

// CS115-WK-03-WORKSHOP-TestOverload.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

// Declare Function Prototypes

// squares a (passed-by-value) integer and returns the squared int value
int square(int intToSquare);
int sum(int intToSum);
int difference(int differenceToSum);
int product(int productToSum);
int quotient(int quotientToSum);
int power(int powerToSum);

// squares a (passed-by-value) double and returns the squared double value
double square(double doubleToSquare);
double sum(double doubleToSum);
double difference(double doubleToDifference);
double product(double doubleToProduct);
double quotient(double doubleToQuotient);
double power(double doubleToPower)
void getInt(int &thisInt);
void getDbl(double &thisDbl);
void printResults(int thisInt, double thisDbl);
bool runAgain();

// Declare and Initialize Prompt CONSTANTS
const string   INT_PROMPT = "    Enter an Integer to Square: ";
const string   DBL_PROMPT = "      Enter a double to Square: ";
const string AGAIN_PROMPT = "Do you want to Run Again (y/n)? ";
const string  NUMA_PROMPT = "     Enter First Number to add: ";
const string  NUMB_PROMPT = "	 Enter Second Number to add: ";
void main()
{
	int		intNum = 0;
	double	dblNum = 0.0;
	bool	moreInput = false;

	do
	{
		getInt(intNum);

		getDbl(dblNum);

		printResults(intNum, dblNum);

		moreInput = runAgain();

	} while (moreInput);
}

void getInt(int &thisInt)
{
	cout << INT_PROMPT;
	cin >> thisInt;
	cout << endl;
}

void getDbl(double &thisDbl)
{
	cout << DBL_PROMPT;
	cin >> thisDbl;
	cout << endl;
}

void printResults(int thisInt, double thisDbl)
{
	cout << setw(12) << square(thisInt) << endl;
	cout << setw(15) << fixed << setprecision(2) << square(thisDbl) << endl;
	cout << endl;

}

int	square(int intToSquare)
{
	return intToSquare * intToSquare;
}

double square(double doubleToSquare)
{
	return doubleToSquare * doubleToSquare;
}

int sum(int a, int b)
{
	return a + b;
}

double sum(double a, double b)
{
	return a + b;
}

bool runAgain()
{
	string answer = "";

	cout << AGAIN_PROMPT;
	cin >> answer;
	cout << endl;

	return ((answer[0] != 'n') && (answer[0] != 'N'));
}

 

Link to comment
https://linustechtips.com/topic/608874-need-help-with-c-assignment/
Share on other sites

Link to post
Share on other sites

As far you have those:

Quote

 

Use Prototypes Above the main() function

Define the functions used in main() below main() and match their signatures

Do the workshop with your Instructor in class on overloading the add function

 

If all compiles and works, and you have no question about then, you still missing those:

Quote

Do the workshop with your Instructor in class on overloading the add function

Overload your own subtraction - multiplication - division - and power Functions for three different data types in one program for IP-0

 

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×