File tree 4 files changed +24
-3
lines changed
4 files changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,14 @@ class ostream {
13
13
ostream& operator <<(const int num);
14
14
};
15
15
16
+ class istream {
17
+ public:
18
+ istream& operator >>(char &c);
19
+ istream& operator >>(char *str);
20
+ istream& operator >>(int &num);
21
+ };
22
+
16
23
extern ostream cout;
24
+ extern istream cin;
17
25
18
26
} // namespace std end
Original file line number Diff line number Diff line change 1
1
#include < iostream.h>
2
2
#include < stdio.h>
3
+ #include < conio.h>
3
4
4
5
namespace std {
5
6
6
7
const char endl = ' \n ' ;
7
8
ostream cout;
9
+ istream cin;
8
10
9
11
ostream& ostream::operator <<(const char c) { putchar (c); return *this ; }
10
12
ostream& ostream::operator <<(const char *str) { puts (str); return *this ; }
11
13
ostream& ostream::operator <<(const int num) { printf (" %d" , num); return *this ; }
12
14
15
+ istream& istream::operator >>(char &c) { c = getch (); putchar (c); return *this ; }
16
+ istream& istream::operator >>(char *str) { gets (str); return *this ; }
17
+
13
18
} // namespace std end
Original file line number Diff line number Diff line change 1
1
// logo program
2
+ #include < iostream.h>
2
3
#include < stdio.h>
3
4
#include < conio.h>
4
5
#include < graphics.h>
@@ -46,7 +47,7 @@ int main(int argc,char *argv[]) {
46
47
std::graphics::initgraph (&gd, &gm, NULL );
47
48
int gerr = std::graphics::graphresult ();
48
49
if (gerr != 0 ) {
49
- std::printf ( " failed to open graphics mode, err: %d " , gerr) ;
50
+ std::cout << " failed to open graphics mode, err: " << gerr << std::endl ;
50
51
return 1 ;
51
52
}
52
53
logo ();
Original file line number Diff line number Diff line change 1
1
// Simple C++ program
2
-
3
2
#include < stdio.h>
4
3
#include < iostream.h>
5
4
@@ -50,12 +49,20 @@ void printShapeDetails(geometry::Shape *shape) {
50
49
std::cout << " - Name: " << shape->getName () << std::endl;
51
50
std::cout << " - Area: " << (int )shape->getArea () << std::endl;
52
51
}
53
-
52
+ # include < string.h >
54
53
int main (int argc, char *argv[]) {
54
+ // shapes
55
+
55
56
geometry::Rectangle r1 (" R1" , 10 , 20 );
56
57
geometry::Square s1 (" S1" , 50 );
57
58
58
59
printShapeDetails (&r1);
59
60
printShapeDetails (&s1);
61
+
62
+ // name
63
+ char name[1024 ];
64
+ std::cout << " Enter your name: " ;
65
+ std::cin >> name;
66
+ std::cout << " Your name is: " << name << std::endl;
60
67
return 0 ;
61
68
}
You can’t perform that action at this time.
0 commit comments