Armenian Knowledge Base  

Go Back   Armenian Knowledge Base > Technical sections > Languages, Compilers, Interpreters
Register

Reply
 
LinkBack Thread Tools
Old 11.06.2002, 19:50   #1
Младенец
 
Join Date: 11 2001
Location: Armenia
Posts: 11
Downloads: 0
Uploads: 0
Reputation: 0 | 0
Post For everyone who loves tests

void main()
{
A a;
while(a)
{
printf("%d\n",(int)a);
}
}
Write class A to make the output of above program as follows.
1
2
3
4
5
6
Reply With Quote
Old 11.06.2002, 20:41   #2
»
 
z0mbie's Avatar
 
Join Date: 01 2002
Posts: 777
Downloads: 1
Uploads: 0
Reputation: 0 | 0
Post

Code:
class A{
 public:
   A():i(1){}
   operator int(){
	i+=0.5;
	return (i>7)?0:i-0.5;
   };
 private:
   float i;
};
Reply With Quote
Old 11.06.2002, 23:31   #3
Младенец
 
Join Date: 01 2002
Location: Undefined
Posts: 10
Downloads: 0
Uploads: 0
Reputation: 0 | 0
Post

2 Taurus
eto bil vopros na kotoriy ti ne znal otvet, ili ti portso testiroval?
Reply With Quote
Old 12.06.2002, 22:58   #4
The Reloaded
 
Aram Hambardzumyan's Avatar
 
Join Date: 01 2002
Location: behind the flesh and gelatinе of soft dull eyes
Posts: 3,387
Downloads: 4
Uploads: 0
Reputation: 146 | 4
Post

Quote:
Originally posted by Taurus:
void main()
{
A a;
while(a)
{
printf("%d\n",(int)a);
}
}
Write class A to make the output of above program as follows.
1
2
3
4
5
6
ах ты поизвращаться вздумал? ну тогда получай:
Code:
class A
{
public:
	operator int() { for(int i = 0; i < 6; cout << ++i << endl); exit(0); return 0; }
};
или:

Code:
class A
{
public:
	operator int() { return 0; }

	A() { for(int i = 0; i < 6; cout << ++i << endl); }  //  или перенсети это в деструктор!
};
try this! :

Code:
class A
{
#define A  for(int i = 0; i < 6; cout << ++i << endl)
#define a 0
};
правда, директивы препроцессора не назовешь оределением класса
Reply With Quote
Old 12.06.2002, 23:45   #5
Младенец
 
Join Date: 03 2002
Location: Yerevan, RA
Posts: 18
Downloads: 0
Uploads: 0
Reputation: 0 | 0
Post

Code:
class A
{
public: 
	operator int()
	{
		return 1;
	};

	void printf(const char* s, int i)
	{
		::printf(&quot;%d\n%d\n%d\n%d\n%d\n%d\n&quot;, 1, 2, 3, 4, 5, 6);

		exit(0);
	};

#define printf	a.printf
};
My best regards
Reply With Quote
Old 13.06.2002, 00:49   #6
Школьник
 
Join Date: 04 2002
Location: Vanadzor
Posts: 227
Downloads: 0
Uploads: 0
Reputation: 0 | 0
Post

Quote:
Originally posted by Barilus:
Code:
class A
{
public: 
	operator int()
	{
		return 1;
	};

	void printf(const char* s, int i)
	{
		::printf(&quot;%d\n%d\n%d\n%d\n%d\n%d\n&quot;, 1, 2, 3, 4, 5, 6);

		exit(0);
	};

#define printf	a.printf
};
My best regards
class A
{
public:
operator int()
{
return 1;
};

void printf(const char* s, int i)
{
:rintf("1\n2\n3\n4\n5\n6\n");
exit(0);
};

#define printf a.printf

lol
Reply With Quote
Old 13.06.2002, 20:55   #7
Младенец
 
Join Date: 03 2002
Location: Yerevan, RA
Posts: 18
Downloads: 0
Uploads: 0
Reputation: 0 | 0
Thumbs up

To strax.

Reply With Quote
Sponsored Links
Reply

Thread Tools


На правах рекламы:
реклама

All times are GMT. The time now is 05:10.


Powered by vBulletin® Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.