Input several fractions

So for an assignment in my CS2 class where I have to input a string of several fractions and the operation you want to perform (like: 3/4+12/18). I don't know how to take a string and divide it like that. I have the rest of the code in a two class structure where I can't do inheritance. Help please? This is what I have, but that's because I didn't know what to do

void fraction::setDenomNumer(string a)
{
int charOne, charTwo;
for(int i = 0;i < a.length()-1;)
{
if(isdigit(a[i])) // it is a number, so do some code
{
i++;
}
else // it is not a number, do something else
{
if(a[i] = '/')
{
charOne=a[i];
}
}
}
}
Example:
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
#include <iostream>
#include <string>
#include <sstream>
using namespace std;

int main()
{
	string input = "3/4+12/18";
	char temp;
	char operation;
	stringstream tempStream;
	int fracOneNum = 0, fracOneDenom = 0;
	int fracTwoNum = 0, fracTwoDenom = 0;

	tempStream << input;

	tempStream >> fracOneNum;
	tempStream >> temp;
	tempStream >> fracOneDenom;
	tempStream >> operation;
	tempStream >> fracTwoNum;
	tempStream >> temp;
	tempStream >> fracTwoDenom;

	cout << fracOneNum << " / " << fracOneDenom << " " << operation << " " << fracTwoNum << " / " << fracOneDenom;

	cin.ignore();
	return 0;
}
Topic archived. No new replies allowed.