Help Please, functions program

Here is the specification of the program:


CS 1410

Object Oriented Programming using C++
Summer Semester 2013

Assignment #2

Due 6/1/13


English Currency Conversion

Write a C++ program to input two currency values in the old English monetary system, add them together and output the sum.

In the heydey of the British empire, Great Britain used a monetary system based on pounds, shillings, and pence with the following conversions:

1 pound = 20 shillings

1 shilling = 12 pence

The program should prompt the user to enter two currency values represented in £PP.SS.CC format (2 digits for pounds, 2 digits for shillings, and 2 digits for pence). Each element within a currency value can be entered separately without decimal points if you wish. Store each currency value in a structure with the following format:

struct Currency

{

int Pounds;
int Shillings;
int Pence;

};

Convert each currency value (pounds, shillings, pence) to total pence (type long int), add the two pence totals together and convert that sum back to the pounds-shillings-pence format shown above and display the result.


The pence value should not exceed 11. The shillings value should not exceed 19. The pounds value will be limited such that its value should not exceed 99. If any of these values do exceed the maximum value, they must wrap around to 0, etc.











The program must use the seven functions defined below with the exact names and prototypes given (any deviation will result in severe point reduction). A description follows each function prototype:

(1) void Input_Cur(Currency&);
Inputs the first currency value (pounds, shillings, pence) and returns it using a reference parameter.

(2) Currency Input_Cur();
Inputs the second currency value and returns it using the return statement.

(3) int Validate_Cur(Currency);
Accepts a currency value and returns a code indicating valid or invalid data.

(4) void Display_Cur(Currency);
Accepts a currency value (pounds, shillings, pence) for printing and returns nothing

(5) long Cur_To_Pence(Currency);
Accepts pounds, shillings, pence and returns the total equivalent pence

(6) Currency Pence_To_Cur(long);
Accepts total pence and returns a currency value in pounds, shillings, and pence.

(7) void Print_Zero(int);
Prints leading zeros if necessary. Accepts a pounds, shillings, or pence value, and prints a zero only if the value < 10. If the value passed is ≥ 10, nothing is printed. Called from Display_Cur().

The input and output dialogue should appear as follows:

Case 1

Enter Currency 1: 19 15 11
Enter Currency 2: 7 9 5
Currency 1: £19.15.11
Currency 2: £07.09.05
Result: £27.05.04

Case 2

Enter Currency 1: 3 12 16
Enter Currency 2: 43 18 7
Currency 1: £03.12.16
Currency 2: £43.18.07
Result: Invalid currency was entered



Case 3

Enter Currency 1: 0 0 1
Enter Currency 2: 99 19 11

Currency 1: £00.00.01
Currency 2: £99.19.11
Result: £00.00.00


For each case, print the two input values and the resulting sum in £PP.SS.CC format. When displaying the result, some compilers use the hex character constant ‘\x9c’ (decimal 156) to generate the pound symbol £. Generating the pound symbol, however, is not required.


Each pound, shilling, and penny value should be printed as two-digit values with zero fill for all values less than 10. Do not use the setfill manipulator; use the Print_Zero function to zero fill. Use no global variables. The Validate_Cur function should validate the input values and return a zero if the data are valid and a -1 if the data are invalid. If the data are invalid, print the currency value (pounds, shillings, and pence with decimal points) and an appropriate error message and continue with the next case; do not calculate the sum. Output all currency values using Display_Cur invoked from the main function.

Use a looping mechanism of your choice to process an arbitrary number of cases of data. Your program must work for error cases as well as valid cases. Error cases may include negative values and values that exceed the maximums.


And this is my code so far:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#include <iostream>
#include <fstream>
#include <cmath>
#include <iomanip>
using namespace std;

////////////////////////////////////////////////////////////////////////////////
struct Currency                                    //Old English monetary system
 {
   int Pounds;
   int Shillings;
   int Pence;
 };
////////////////////////////////////////////////////////////////////////////////
void Input_Cur(Currency&);

Currency Input_Cur();

int Validate_Cur(Currency);

void Display_Cur(Currency);

long Cur_To_Pence(Currency);

Currency Pence_To_Cur(long);

void Print_Zero(int);

int main()
{
    Currency cur_1,
             cur_2;


    long poundsDif,
         pounds1,
         pounds2;

        cur_1.Pounds = 0;
        cur_1.Shillings = 0;
        cur_1.Pence = 0;
        cur_2.Pounds = 0;
        cur_2.Shillings = 0;
        cur_2.Pence = 0;

    Input_Cur(cur_1);
    cout << endl;

    cur_2 = Input_Cur();
    cout << endl;



    cout <<"Currency 1: \x9c";
    Display_Cur(cur_1);

    cout <<"Currency 2: \x9c";
    Display_Cur(cur_2);


}
//--------------------------------------------------------------------------------
//void Input_Cur(Currency&);
void Input_Cur(Currency& c1)
{
    cout << "Enter Currency 1: ";

    cin >> c1.Pounds
        >> c1.Shillings
        >> c1.Pence;

}
//---------------------------------------------------------------------------------
//Currency Input_Cur();
Currency Input_Cur()
{
    Currency c2;

    cout << "Enter Currency 2: ";

    cin >> c2.Pounds
        >> c2.Shillings
        >> c2.Pence;

    return c2;
}
//---------------------------------------------------------------------------------
//int Validate_Cur(Currency);
int Validate_Cur(Currency cc1, Currency cc2)
{
    int validateCur = 0;

    if (cc1.Pounds > 99 || cc2.Pounds >99)
    {
       validateCur = -1;
    }
    else if (cc1.Shillings > 19 || cc2.Shillings > 19)
    {
       validateCur = -1;
    }
    else if (cc1.Pence > 11 || cc2.Pence > 11)
    {
       validateCur = -1;
    }
    else if (cc1.Pounds < 0 || cc2.Pounds < 0)
    {
       validateCur = -1;
    }
    else if (cc1.Shillings < 0 || cc2.Shillings < 0)
    {
       validateCur = -1;
    }
    else if (cc1.Pence < 0 || cc2.Pence < 0)
    {
       validateCur = -1;
    }
    else if (cc1.Pounds <= 99 && cc1.Pounds >=0)
    {
       validateCur = 0;
    }
    else if (cc1.Shillings <= 19 && cc1.Shillings >= 0)
    {
       validateCur = 0;
    }
    else if (cc1.Pence <= 11 && cc1.Pence >= 0)
    {
       validateCur = 0;
    }
    else if (cc2.Pounds <= 99 && cc2.Pounds >= 0)
    {
       validateCur = 0;
    }
    else if (cc2.Shillings <= 19 && cc2.Shillings >= 0)
    {
       validateCur = 0;
    }
    else if (cc2.Pence <= 11 && cc2.Pence >= 0)
    {
       validateCur = 0;
    }

    return validateCur;

}
//---------------------------------------------------------------------------------
//void Display_Cur(Currency);
void Display_Cur(Currency c1, Currency c2)
{


    Print_Zero(c1.Pounds);
    cout <<"Result: ‘\x9c"<< c1.Pounds << ".";
    Print_Zero(c1.Shillings);
    cout << c1.Shillings << ".";
    Print_Zero(c1.Pence);
    cout << c1.Pence;

    Print_Zero(c2.Pounds);
    cout <<"Result: ‘\x9c"<< c2.Pounds << ".";
    Print_Zero(c2.Shillings);
    cout <<c2.Shillings << ".";
    Print_Zero(c2.Pence);
    cout <<c2.Pence;


}
//---------------------------------------------------------------------------------
//long Cur_To_Pence(Currency)
long Cur_To_Pence(Currency c1, Currency c2)
{
    long totalpence = 0;

    	totalpence = (c1.Pounds+c2.Pounds) * 20;
        totalpence += (c1.Shillings+c2.Shillings) * 12;
        totalpence += c1.Pence+c2.Pence;

    return totalpence;
}
//---------------------------------------------------------------------------------
//Currency Pence_To_Cur(long);
Currency Pence_To_Cur(long totalpence)
{
    Currency c1, c2;

    int netPound;
    int netShilling;
    int netPence;

    netPound= totalpence / 20;
    netShilling= (totalpence % 20)/12;
    netPence= totalpence-((netShilling *12)+(netPound *20));







}
//---------------------------------------------------------------------------------
//void Print_Zero(int)
void Print_Zero(int isUnderTen)
{
 if(isUnderTen < 10 && isUnderTen >= 0)
 {
  cout << "0";
 }
 if(isUnderTen < 0)
 {
  cout << "-0";
 }
}



When compile, get an error:

Undefined reference to `Display_Cur(Currency)



Any advice?

Ty.
Your prototype for DisplayCur doesn't match your implementation.

Prototype:

void DisplayCur( Currency )

Implementation:

void DisplayCur( Currency, Currency )

Also, you may just want to post the code/description relevant to your error next time, not the whole thing.
Last edited on
Topic archived. No new replies allowed.