Wednesday, 9 October 2013

reverse() and copy constructor

Reverse:

void Stack::reverse(){
Stack tmp=*this;
_top=(Node*)0;
while(!tmp.isEmpty()){
push(tmp._top->_data);
tmp.pop();
}
  }

Copy Constructor

Stack::Stack(const Stack& S){
_top=(Node*)0;
_top=S._top;
  }


Saturday, 5 October 2013

Assignment #1 cio_tester, test 4.2 vs 4.17

I'm having problem with test 4.2 vs 4.17; Test 4.2 and 4.17 are exactly the same but their return key. When I get 4.2, 4.17 won't work because it returns the 'RETURN' key and my test fails. On the other hand, if i change this code to return '0', my test 4.2 will fail. the screenshot of these two tests shows there is no difference except the return key.
Test 4.2

Test 4.17


 does anyone have an idea about this? your comments on this would be great.
Thanks,

Saturday, 21 September 2013

Basic Math

It was good exercise because I did not know how to use command line arguments using visual studio. Anyway, here is my code and feel free to ask question or leave comments.
#include <iostream>
using namespace std;

#define left atoi(arg[1])
#define right atoi(arg[3])
#define OPERAND arg[2]

int main(int argc, char* arg[]){
int setOperand = 0;
int res=0;

if(!strcmp(OPERAND,"+")){
setOperand=1;
}
else if(!strcmp(OPERAND,"-")){
setOperand=2;
}
else if(!strcmp(OPERAND,"*")){
setOperand=3;
}
else if(!strcmp(OPERAND,"/")){
setOperand=4;
}

switch(setOperand){
case 1:
res=left + right;
cout<<res<<endl;
break;
case 2:
res=left - right;
cout<<res<<endl;
break;
case 3:
res=left * right;
cout<<res<<endl;
break;
case 4:
res=left / right;
cout<<res<<endl;
break;

default:
cout<<"<number> <+-x/> <number>"<<endl;
}

}

Tuesday, 17 September 2013

Hello everyone, and welcome to my blog.
Exercise1 was pretty straight forward and just took me a few minutes to do it. You can see my codes at my github account. If any question about Exercise1, feel free to ask.
Good Luck