Menu

Friday, 28 November 2014

Chapter 5,Problem 11:Object Oriented Programming by Robert Lafore in C++ Solution Manual

//27-11-2014
//Ahmad Furqan Attari
//p5.11
#include <iostream>
#include <conio.h>
using namespace std;
struct brit_money
{
int pound;
int shelling;
int pence;
};
brit_money take(void)
{
brit_money m;
char dummy;
cout << "Enter money in old Britin style (5.3.2): ";
cin >> m.pound >> dummy >> m.shelling >> dummy >> m.pence;
return m;
}
brit_money add(brit_money m1, brit_money m2)
{
brit_money m;
m.pence = m1.pence + m2.pence;
m.shelling = m1.shelling + m2.shelling+m.pence/12;
m.pence = m.pence % 12;
m.pound = m1.pound + m2.pound + m.shelling / 20;
m.shelling = m.shelling % 20;
return m;
}
void show(brit_money m3)
{
cout << "\x9c" << m3.pound << "." << m3.shelling << "." << m3.pence;
}
void main(void)
{
brit_money mon1, mon2, mon3;
mon1 = take();
mon2 = take();
mon3 = add(mon1, mon2);
cout << "Sum is ";
show(mon3);
_getch();
}

No comments:

Post a Comment