| | |
Anonymous Objects
Please support our C++ advertiser: Intel Parallel Studio Home
hi all .. this is intorduction to an anonymous classes,
An anonymous class is one that doesn't have a name. In the following example, both structures inside the TRectangle union are anonymous classes:
Here is an example of running the program:
You want to identify your rectangle by its location or its dimensions?
1 - Location
2 - Dimension
Enter your choice: 1
Enter the location of the rectangle on a Cartesian coordinate system
First point
X coordinate: -4
Y coordinate: 2
Second point
X coordinate: 5
Y coordinate: 1
The rectangle spans from A(-4, 2) to B(5, 1).
Press any key to continue...
An anonymous class is one that doesn't have a name. In the following example, both structures inside the TRectangle union are anonymous classes:
Here is an example of running the program:
You want to identify your rectangle by its location or its dimensions?
1 - Location
2 - Dimension
Enter your choice: 1
Enter the location of the rectangle on a Cartesian coordinate system
First point
X coordinate: -4
Y coordinate: 2
Second point
X coordinate: 5
Y coordinate: 1
The rectangle spans from A(-4, 2) to B(5, 1).
Press any key to continue...
//--------------------------------------------------------------------------- #include <iostream> #include <conio> using namespace std; #pragma hdrstop //--------------------------------------------------------------------------- #pragma argsused // This rectangle can be identified by EITHER its location OR its dimensions union TRectangle { struct // Location { int x1; int y1; int x2; int y2; }; struct // Dimensions { double Length; double Height; }; }; //--------------------------------------------------------------------------- int main(int argc, char* argv[]) { TRectangle Recto; char Choice; cout << "You want to identify your rectangle by " << "its location or its dimensions?"; cout << "\n1 - Location"; cout << "\n2 - Dimension"; cout << "\nEnter your choice: "; cin >> Choice; if( Choice == '1' ) { cout << "\nEnter the location of the rectangle on a " << "Cartesian coordinate system\n"; cout << "First point\n"; cout << "X coordinate: "; cin >> Recto.x1; cout << "Y coordinate: "; cin >> Recto.y1; cout << "Second point\n"; cout << "X coordinate: "; cin >> Recto.x2; cout << "Y coordinate: "; cin >> Recto.y2; cout << "\nThe rectangle spans from A(" << Recto.x1 << ", " << Recto.y1 << ") to B(" << Recto.x2 << ", " << Recto.y2 << ").\n"; } else if( Choice == '2' ) { cout << "Enter the dimensions of the rectangle\n"; cout << "Length: "; cin >> Recto.Length; cout << "Height: "; cin >> Recto.Height; cout << "\nDimensions of the rectangle"; cout << "\nLength: " << Recto.Length; cout << "\nHeight: " << Recto.Height << endl; } else cout << "\nInvalid Choice"; return 0; } //---------------------------------------------------------------------------
Similar Threads
- Anonymous methods (C#)
- anonymous functions? (C++)
- C++ anonymous emailer (C++)
- I am anonymous (Community Introductions)
- Anonymous Objects (C++)
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer display dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph homeworkhelp iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg simple sorting spoonfeeding string strings struct template templates text tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets



