exercise4

exercise4 - #include # #include using...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
#include <iostream> #include <sstream> # using namespace std; bool is_number(char str) { if(str>='0' & str else return false; } int find_next_numb(int place, string exp, int *nbnext) { int numb; string strnumb; for(int i=1;i<exp.length();i++) { if(!is_number(exp[place+i+1])) { strnumb = exp.substr(place+1,i); numb = atoi(strnumb.c_str()); *nbnext = i; i = exp.length(); } } return numb; } int find_prev_numb(int place, string exp, int *nbprev) { int numb; string strnumb; for(int i=1;i<exp.length();i++) { if(!is_number(exp[place-i-1])) { strnumb = exp.substr(place-i,i); numb = atoi(strnumb.c_str()); *nbprev = i; i = exp.length(); } } return numb; } string do_multiplication(string exp) { int numb; int nbprev, nbnext; std::stringstream ss; string strnumb; if(exp[exp.find_first_of("*")]!=-1) { numb = find_prev_numb(exp.find("*"),exp, &nbprev) * find_next_numb(exp.find("*"),exp, &nbnext); ss << numb; strnumb = ss.str(); exp.replace(exp.find_first_of("*")-nbprev,1+nbprev+nbnext,strnumb); exp = do_multiplication(exp); } return exp; }
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/01/2009 for the course AV 244 taught by Professor Dub during the Spring '09 term at ECE.

Page1 / 3

exercise4 - #include # #include using...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online