#include<qstring.h>
void Calculator
::calculation(QString &operation,
QString &text_display
) {
QString a_string
= "", b_string
= "", result_string
= "";
double a, b, result;
int position = 0, i, j;
while(1)
{
if ( ( position = operation.find('*') ) == -1 ) break;
for( i = position; i = 0 ; i-- )
{
if( operation.at( i ) == '*' || operation.at( i ) == '/' || operation.at( i ) == '+' || operation.at( i ) == '-' )
break;
a_string += operation.at( i );
}
for( j = position; j < operation.length() ; j++ )
{
if( operation.at( j ) == '*' || operation.at( j ) == '/' || operation.at( j ) == '+' || operation.at( j ) == '-' )
break;
b_string += operation.at( j );
}
a = a_string.toDouble();
b = b_string.toDouble();
result = a*b;
result_string = result_string.setNum( result, 'f', 10 );
operation.replace( i, i + j + 1, result_string );
}
text_display = result_string;
ui.display->setText( text_display );
}
#include<qstring.h>
void Calculator::calculation(QString &operation, QString &text_display)
{
QString a_string = "", b_string = "", result_string = "";
double a, b, result;
int position = 0, i, j;
while(1)
{
if ( ( position = operation.find('*') ) == -1 ) break;
for( i = position; i = 0 ; i-- )
{
if( operation.at( i ) == '*' || operation.at( i ) == '/' || operation.at( i ) == '+' || operation.at( i ) == '-' )
break;
a_string += operation.at( i );
}
for( j = position; j < operation.length() ; j++ )
{
if( operation.at( j ) == '*' || operation.at( j ) == '/' || operation.at( j ) == '+' || operation.at( j ) == '-' )
break;
b_string += operation.at( j );
}
a = a_string.toDouble();
b = b_string.toDouble();
result = a*b;
result_string = result_string.setNum( result, 'f', 10 );
operation.replace( i, i + j + 1, result_string );
}
text_display = result_string;
ui.display->setText( text_display );
}
To copy to clipboard, switch view to plain text mode
Bookmarks