GIDForums  

Go Back   GIDForums > Computer Programming Forums > CPP / C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 06-May-2008, 13:18
zatora zatora is offline
New Member
 
Join Date: May 2008
Posts: 25
zatora is on a distinguished road

RomanTypr class


CPP / C++ / C Code:
#include<iostream>
#include<string>
#include "romantype.h"

using namespace std;

int main()
{
	
	romantype rom;// create an object rom from roman type class
	rom.header();//display student names
	rom.getRoman();//access the member getRoman
	rom.convertRoman();//access the member convertRoman
	rom.printRoman();//access the menber printRoman
	
	return 0;
}
CPP / C++ / C Code:
#include<iostream>
using namespace std;
class romantype// class roman type
{
public :
	void header();
	void getRoman(); //public members in here
	void convertRoman();
	void printRoman();
private:		// private variabls in here
	string str_roman;
	int sum;
	
};
CPP / C++ / C Code:
#include<iostream>
#include<string>
#include "romantype.h"
using namespace std;

void romantype::header() 
{
cout<<"****************Team Project by*********************"<<endl;
cout<<endl;
cout<<"	Heikel Khaldi and Zong Vang"<<endl;
cout<<endl;
cout<<"****************************************************"<<endl<<endl;
}

void romantype::getRoman()
{
	cout<<endl;
	cout<<"Please enter you Roman Number ? "<<endl<<endl;
	cin >> str_roman;// get the value of str_roman
	cout<<endl;
}

void romantype::convertRoman()
{
int val,val1;// two local variables to compare the 1st position from the right and the 2nd position from the right
	val1=0;val=0;sum=0;// initializinghe variables  
	for(int i=str_roman.length()-1;i>=0;i--)// loop to select the characters positions and compares the associated 
		//varibles as described above
	{val1=val;
		switch(str_roman[i])
		{
		case 'i':
		case'I':
			val=1;
			break;
		case 'v':
			case'V':
			val=5;
			break;
		case 'x':
			case'X':
			val=10;
			break;
		case 'l':
			case'L':
			val=50;
			break;
		case'c':
			case'C':
			val=100;
			break;
		case'd':
			case'D':
			val=500;
			break;
		case'm':
			case'M':
			val=1000;
			break;
		default:
			val=0;
		}
		if (val1<=val)// roman conversion algorithm
			sum=sum+val;// we add when the 2nd number from right is >= to the first number from right
		else
		sum=sum-val;// we substract when the 2nd number from right is < to the first number from right
	}
}

void romantype::printRoman()
{
	int i;
	cout<<endl;
	cout<<"Select 1 for Roman Number. "<<endl<<endl;
	cout<<endl;
	cout<<"Select 2 for Decimal Number. "<<endl<<endl;
	cin>>i;
	 if (i==1)
	{
		cout<<endl<<"Roman Number You entered is : "<<str_roman<<endl<<endl;// if user input 1 than the Roman number entered is the output
	}
	else if(i==2)
	{
		cout <<endl<<"Decimal Number You entered is : "<<sum<<endl<<endl;// if user input 2 than the Decimal number entered is the output		
	}
	 else if(i!=1 || i!=2)
	{
		cout<<endl<<"your entry is invalid please try again"<<endl<<endl;// other entry the
		cin>>i;
	}

	
}
 
 

Recent GIDBlogNARMY by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Returning a Struct to a separate class usmsci CPP / C++ Forum 9 07-Feb-2007 08:34
Hard drive/CPU Diagnoses Issues binarybug Computer Hardware Forum 1 22-Jan-2007 19:23
Box Class, need help again :( TransformedBG CPP / C++ Forum 7 13-Nov-2006 15:11
C++ class -- Please help vnca_1 CPP / C++ Forum 3 14-Jun-2006 12:31
a tester class and then some. postage Java Forum 1 06-May-2006 15:48

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 04:37.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.