how to convert a program written in turbo c 3.0 into codeblock

how to convert a program written in turbo c 3.0 into codeblock


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include<conio.h>
#include<string.h>
#include<iostream.h>
class String
{
private:
	char str[40];

public:
      void menu()
      {
      gotoxy(30,12);
	cout<<"Menu";
	gotoxy(30,14);
	cout<<"1.Comparing Strings";
	gotoxy(30,16);
	cout<<"2.Add to Strings";

      }
       void getdata()
	{
	    cin.getline(str,40);
	}
	int operator ==(String i)
	{
	if(strlen(str)==strlen(i.str))
       return 1;
       else
       return 0;
	}

       void showdata()
       {
       cout<<str;
       }

String operator+(String ob)
	      {
			    String t;
			    strcpy(t.str,str);
			   strcat(t.str,ob.str);
			    return(t);
	      }
};
void main()
{
 String a,b,c;
 char ch;
 clrscr();
a.menu();
 ch=getch();
 clrscr();
 gotoxy(30,12);
 cout<<"Enter first string";
 a.getdata();
 gotoxy(30,14);
 cout<<"Enter second string ";
 b.getdata();
 clrscr();
 switch(ch){
	case'1':
       if(a==b)
       {
       gotoxy(30,14);
	cout<<"string are equal";
	}
	 else
	 {
	 gotoxy(30,14);
	 cout<<"string are not equal";
	 }
	 break;
	case'2':
       c=a+b;
       c.showdata();
       break;

 }
	 getch();
}
Removes this
#include<conio.h>


Change these
1
2
#include<string.h>
#include<iostream.h> 


to
1
2
#include<cstring>
#include<iostream> 


Add this
1
2
3
4
5
6
7
8
#include<windows.h>
COORD coord = {0,0};
void gotoxy(int x,int y)
{
    coord.X=x;
    coord.Y=y;
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
}



replace this
clrscr();

with this
system("cls");

Although it is recommended not to use system command, but I'm too lazy to having to put up with io stuff they annoy me!
You can use conio.h too if you want
Thank you Akshit!

I'm sorry, you have to use conio.h here. I missed that there was a getch()somewhere in the code. I advised against it because it isn't a C++ standard although it is supported by gcc and MSVC, to name a few.
Last edited on
compiler might give warning to use _getch(); instead of getch();
As an aside, if you write your programs in standard, modern C++ you will be able to use any modern C++ compiler.
_ main must return int
_ The headers are
1
2
#include <cstring>
#include <iostream> 

conio.h is not standard.
_ Now you have namespaces. So it is std::cout (you may use using)

About style
_ There is a bool type.
By instance
1
2
3
bool String::operator ==(const String &i) const{
   return strlen(str) == strlen(i.str);
}

_ ¿Why is menu() a method?
_ ¿why bother so much with the user interface if you only want to write in the line below?
Last edited on
Topic archived. No new replies allowed.