find the mistake
Page 1 of 1
find the mistake
Well guys, I have a challenge for you.
I have typed this program from "Teach yourself c++" by Herbert Schildt. (page 26)
Though the code is "almost similar" when compared to book, I made a mistake/some mistakes here, for which, you can't compile it.
the challenge?
Find the mistake
(It took me a while to find the mistake ^_^! )
(AND IF YOU DO FIND THE MISTAKE, DON'T POST IT HERE. JUST SEND THE SOLUTION TO ME VIA PRIVATE MESSAGE )
Note: there is no error in the header files. In gcc, just remove the
I have typed this program from "Teach yourself c++" by Herbert Schildt. (page 26)
Though the code is "almost similar" when compared to book, I made a mistake/some mistakes here, for which, you can't compile it.
the challenge?
Find the mistake
(It took me a while to find the mistake ^_^! )
(AND IF YOU DO FIND THE MISTAKE, DON'T POST IT HERE. JUST SEND THE SOLUTION TO ME VIA PRIVATE MESSAGE )
- Code:
#include<iostream>
#include<conio>
using namespace std;
#define SIZE 10;
//declare a stack class for characters
class stack{
char stck[SIZE]; //holds the stack.
int tos; //index of top of stack;
public:
void init();//initialize stack
void push(char ch);//push character on stack;
char pop();
};
//initialize the stack
void stack::init(){
tos=0;
}
//push a character
void stack::push(char ch){
if(tos==SIZE){
cout<<"Stack is full";
return;
}
stck[tos] = ch;
tos++;
}
//pop a character.
char stack::pop(){
if(tos==0){
cout<<"Stack is empty";
return 0;//return null on empty stacl
}
tos--;
return stck[tos];
}
int main(){
stack s1, s2; //create two stacks;
int i;
//initialize two stacks;
s1.init();
s2.init();
s1.push('a');
s2.push('x');
s1.push('b');
s2.push('y');
s1.push('c');
s2.push('z');
for(i=0;i<3;i++) cout<<"pop s1: "<< s1.pop() <<".\n";
for(i=0;i<3;i++) cout<<"pop s2: "<< s2.pop() <<".\n";
getch();
return 0;
}
Note: there is no error in the header files. In gcc, just remove the
- Code:
#include<conio>
Similar topics
» find mistake
» Who can find out the error in this program???
» Find out best server for you to download repo applications
» Find your computer's Gender : Male or Female?
» Need help to find a solution of write protected problem of pendrive.
» Who can find out the error in this program???
» Find out best server for you to download repo applications
» Find your computer's Gender : Male or Female?
» Need help to find a solution of write protected problem of pendrive.
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|
Tue Sep 29, 2015 2:45 pm by Sophiawood
» Cisco EHWIC SFP/GE WAN Card
Mon Sep 07, 2015 11:08 am by Sophiawood
» Huawei S1700-28GFR-4P-AC Price
Thu Jun 25, 2015 2:31 pm by Sophiawood
» teach yourself C++ / Herbert Schildt Solutions
Wed Jun 03, 2015 1:52 pm by Abdullah Al Noman
» teach yourself c by herbert schildt pdf
Wed May 13, 2015 11:01 pm by Raquib Ridwan
» ASA 5506X With Firepower ASA5506-K9
Fri Apr 10, 2015 4:31 pm by Sophiawood
» New Trends in Deal Business
Tue Feb 03, 2015 9:38 pm by nersoa
» PoE Power Allocation for WS-C2960S-24PS-L
Wed Nov 05, 2014 11:12 am by Sophiawood
» How to cure back pain
Fri Oct 31, 2014 7:15 pm by Bergen Guildford