C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old February 23rd, 2014, 12:26 PM
hellzhobo hellzhobo is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2014
Posts: 2 hellzhobo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 m 8 sec
Reputation Power: 0
General - My first go at OOD -_-

Ok. I just started Object-Oriented Design and I'm also an idiot. So help here would be appreciated. I'm trying to write a program that converts roman numerals into decimal format. Can somebody just look over this and let me know what I have wrong? Here is what I have so far.

Source Code:



//************************************************** *****
// Programmer: enter name here
// Date Completed: 2/22/2014
// Chapter 1 Homework Page 57 Number 1
//************************************************** *****

#include <iostream>
#include <string>
#include "roman.h" // required header file

using namespace std;


int main()
{

cout << "Chapter 1 Homework Page 57 Number 1";
cout << "\n\nEnter Name Here.\n\n";

romanType roman;

char romanString[7] = {'M', 'D', 'C', 'L', 'X', 'V', 'I'};

cout << "Enter a roman number: ";
cin >> romanString;
cout << endl;

roman.setRoman;

cout << "The equivalent of the Roman numeral " << romanString << " is ";

roman.printDecimal();
cout << endl;
cout << "\n\n\n\n";
system("pause");
return 0;
}// end of main

// following are class members
void romanType::printDecimal() const
{
cout << decimalNum;
}

void romanType::printRoman() const
{
cout << romanNum;
}
//
void romanType::setRoman(string rString)
{
romanNum = rString;
romanToDecimal();
}

void romanType::romanToDecimal()
{
int sum = 0;
int length = romanNum.length();
int i;

int previous = 1000;

for (i = 0; i < length; i++)
{
switch (romanNum[i])
{
case 'M':
sum += 1000;
if (previous < 1000)
sum -= 2 * previous;
previous = 1000;
break;
case 'D':
sum += 500;
if (previous < 500)
sum -= 2 * previous;
previous = 500;
break;
case 'C':
sum += 100;
if (previous < 100)
sum -= 2 * previous;
previous = 100;
break;
case 'L':
sum += 50;
if (previous < 50)
sum -= 2 * previous;
previous = 50;
break;
case 'X':
sum += 10;
if (previous < 10)
sum -= 2 * previous;
previous = 10;
break;;
case 'V':
sum += 5;
if (previous < 5)
sum -= 2 * previous;
previous = 5;
break;
case 'I':
sum += 1;
previous = 1;
}
}

decimalNum = sum;
}

romanType::romanType()
{
romanNum = 'I';
decimalNum = 1;
}

romanType::romanType(string rString)
{
romanNum = rString;
romanToDecimal();
}





and Header


//************************************************** *****
// Programmer: enter name here
// Date Completed: 2/22/2014
// Chapter 1 Homework Page 57 Number 1
//************************************************** *****
//
// THIS IS THE "Roman.h" HEADER FILE
//
//#include <string>
using namespace std;

class romanType
{
public:

void setRoman{string};
void romanToDecimal();
void printDecimal() const;
void printRoman() const;
romanType();
romanType(string);

private:
string romanNum;
int decimalNum;
};






any help is appreciated :)

Reply With Quote
  #2  
Old February 23rd, 2014, 10:38 PM
hellzhobo hellzhobo is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2014
Posts: 2 hellzhobo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 m 8 sec
Reputation Power: 0
nevermind. I figured it out

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > General - My first go at OOD -_-


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap