C++ Class Code Review Request

its not working properly...kindly make it work perfectly and if u can

Page 1 of 1

4 Replies - 652 Views - Last Post: 20 April 2009 - 09:39 AM Rate Topic: -----

#1 umree786  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 16-April 09

C++ Class Code Review Request

Posted 17 April 2009 - 09:35 AM

#include < iostream.h>
#include < string.h>
#include < conio.h>

class Char {
      private:
	   char ch;
      public :
	 char peek() { return ch;}
	 char get() {
	    ch=getch();
	    return ch;
	 }
	 int isEnter() {
	    if(ch==13)
	       return 1;
	    else
	       return 0;
	 }
	int isEsc() {
	    if(ch==27)
		return 1;
	    else
		return 0;
	}
};
class String {
      char *p;
      public:
	  String(char *s) : p(s) {}
	  char operator[](int i){
	     return p[i];
	   }
	  int length() {
	    return strlen(p);
	  }
	  char *get() { return p;}
	  void set(char *s) { p=s;}
};
class Console {
     int good,bad;
     public :
	Console() : good(0),bad(0) {}
	void Print(String str,int r,int c) {
	    gotoxy(c,r);
	    cout << str.get();
	    gotoxy(c,r+1);
	    Char ch;
	    int i=0;
	    while(str[i]!='\0')
	     {
		 if(str[i]==ch.get())
		    {
		       cout << ch.peek();
		       gotoxy(++c,r+1);
		       i++;
		       good++;
		    }
		    else
		       bad++;
	     }
	}
       int getgood() { return good;}
       int getbad() { return bad;}
       void printresult() {
	   cout << "\n=========================\n";
	   cout << "\nTotal Hits : " << (good+bad);
	   cout << "\nCorrect : " << good;
	   cout << "\nIncorrect : "<< bad;
	   cout << "\n===========================";
       }

};
main(){
    Console c;
    clrscr();
    c.Print(String("Hello"),5,5);
    c.Print(String("Sample App"),7,5);
    c.printresult();
    return 0;
}


*** MOD EDIT: Added code tags. Please :code: ***

This post has been edited by girasquid: 17 April 2009 - 09:48 AM


Is This A Good Question/Topic? 0
  • +

Replies To: C++ Class Code Review Request

#2 girasquid  Icon User is offline

  • Barbarbar
  • member icon

Reputation: 108
  • View blog
  • Posts: 1,825
  • Joined: 03-October 06

Re: C++ Class Code Review Request

Posted 17 April 2009 - 09:47 AM

Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Post your code like this: :code:

Thanks.
Was This Post Helpful? 0
  • +
  • -

#3 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1638
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: C++ Class Code Review Request

Posted 17 April 2009 - 09:48 AM

Are you receiving any errors? Does this code not work that way you intended it? When asking for help there are a couple items that are vital in order for someone to properly help you:

  • Post the code you're having problems with (DONE)
  • Post the exact error you're receiving, if you are receiving one
  • If no error explain what the code is doing versus what you want it to do
  • Post your question in the body of your post, not the description field

Was This Post Helpful? 0
  • +
  • -

#4 umree786  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 16-April 09

Re: C++ Class Code Review Request

Posted 20 April 2009 - 09:01 AM

View Postgirasquid, on 17 Apr, 2009 - 08:47 AM, said:

Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Post your code like this: :code:

Thanks.

actually this code doesnt give any errors but its not working properly at the same time......when i run this program the follwoing thing displays
"Type hello"
thats it....then i type hello or type whatever it doesnt affect anything at all
Was This Post Helpful? 0
  • +
  • -

#5 AndyH1963  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 22
  • View blog
  • Posts: 201
  • Joined: 22-June 08

Re: C++ Class Code Review Request

Posted 20 April 2009 - 09:39 AM

Only a suggestion:

Why don't you put a breakpoint at the start of your int main() and see what your code does. It's your code it should perform in exactly the way you intend it to.

This post has been edited by AndyH1963: 20 April 2009 - 09:47 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1