comp.lang.ada
 help / color / mirror / Atom feed
* Translating C++ class types into Ada tagged types?
@ 2007-07-10  1:39 markus034
  2007-07-10  2:12 ` jimmaureenrogers
  2007-07-10  9:19 ` Patrick
  0 siblings, 2 replies; 14+ messages in thread
From: markus034 @ 2007-07-10  1:39 UTC (permalink / raw)


Does ada fully support the object-orientedness? If so, how do i write
(or translate) the following C++ object-oriented code into Ada object-
oriented code?
Without constractors:
1:   // Demonstrates declaration of a class and
2:   // definition of class methods,
3:
4:   #include <iostream.h>      // for cout
5:
6:   class Cat                   // begin declaration of the class
7:   {
8:     public:                   // begin public section
9:       int GetAge();           // accessor function
10:      void SetAge (int age);  // accessor function
11:      void Meow();            // general function
12:    private:                  // begin private section
13:      int itsAge;             // member variable
14:  };
15:
16:  // GetAge, Public accessor function
17:  // returns value of itsAge member
18:  int Cat::GetAge()
19:  {
20:     return itsAge;
21:  }
22:
23:  // definition of SetAge, public
24:  // accessor function
25:  // returns sets itsAge member
26:  void Cat::SetAge(int age)
27:  {
28:     // set member variable its age to
29:     // value passed in by parameter age
30:     itsAge = age;
31:  }
32:
33:  // definition of Meow method
34:  // returns: void
35:  // parameters: None
36:  // action: Prints "meow" to screen
37:  void Cat::Meow()
38:  {
39:     cout << "Meow.\n";
40:  }
41:
42:  // create a cat, set its age, have it
43:  // meow, tell us its age, then meow again.
44:  int main()
45:  {
46:     Cat Frisky;
47:     Frisky.SetAge(5);
48:     Frisky.Meow();
49:     cout << "Frisky is a cat who is " ;
50:     cout << Frisky.GetAge() << " years old.\n";
51:     Frisky.Meow();
52;      return 0;
53: }
Also the same code with constractors:
1:   // Demonstrates declaration of a constructors and
2:   // destructor for the Cat class
3:
4:   #include <iostream.h>      // for cout
5:
6:   class Cat                   // begin declaration of the class
7:   {
8:    public:                    // begin public section
9:      Cat(int initialAge);     // constructor
10:     ~Cat();                  // destructor
11:     int GetAge();            // accessor function
12:     void SetAge(int age);    // accessor function
13:     void Meow();
14:   private:                   // begin private section
15:     int itsAge;              // member variable
16:  };
17:
18:  // constructor of Cat,
19:  Cat::Cat(int initialAge)
20:  {
21:     itsAge = initialAge;
22:  }
23:
24:  Cat::~Cat()                 // destructor, takes no action
25:  {
26:  }
27:
28:  // GetAge, Public accessor function
29:  // returns value of itsAge member
30:  int Cat::GetAge()
31:  {
32:     return itsAge;
33:  }
34:
35:  // Definition of SetAge, public
36:  // accessor function
37:
38:  void Cat::SetAge(int age)
39:  {
40:     // set member variable its age to
41:     // value passed in by parameter age
42:     itsAge = age;
43:  }
44:
45:  // definition of Meow method
46:  // returns: void
47:  // parameters: None
48:  // action: Prints "meow" to screen
49:  void Cat::Meow()
50:  {
51:     cout << "Meow.\n";
52:  }
53:
54:  // create a cat, set its age, have it
55   // meow, tell us its age, then meow again.
56:  int main()
57:  {
58:    Cat Frisky(5);
59:    Frisky.Meow();
60:    cout << "Frisky is a cat who is " ;
61:    cout << Frisky.GetAge() << " years old.\n";
62:    Frisky.Meow();
63:    Frisky.SetAge(7);
64:    cout << "Now Frisky is " ;
65:    cout << Frisky.GetAge() << " years old.\n";
66;     return 0;
67: }




^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2007-07-18 11:58 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-07-10  1:39 Translating C++ class types into Ada tagged types? markus034
2007-07-10  2:12 ` jimmaureenrogers
2007-07-10  3:26   ` markus034
2007-07-10  6:27     ` tmoran
2007-07-18 10:27       ` Gerd
2007-07-18 11:58         ` Georg Bauhaus
2007-07-10  8:07   ` Georg Bauhaus
2007-07-16  5:47     ` markus034
2007-07-16  7:30       ` Georg Bauhaus
2007-07-16 17:35         ` markus034
2007-07-10  9:19 ` Patrick
2007-07-11 20:09   ` markus034
2007-07-11 23:15     ` Jeffrey Creem
2007-07-12  5:46   ` vgodunko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox