Esempio n. 1
0
int main()
{
   // Define and initialize several MyString objects.
   MyString object1("This"), object2("is");
   MyString object3("a test.");
   MyString object4 = object1;  
   MyString object5("is only a test.");
   // Define a C-string.
   char string1[] = "a test.";

   // Display the MyString objects.
   cout << "object1: " << object1 << endl;
   cout << "object2: " << object2 << endl;
   cout << "object3: " << object3 << endl;
   cout << "object4: " << object4 << endl;
   cout << "object5: " << object5 << endl;

   // Display the C-string.
   cout << "string1: " << string1 << endl;

   // Test the overloaded += operator.
   object1 += " ";
   object1 += object2;
   object1 += " ";
   object1 += object3;
   object1 += " ";
   object1 += object4;
   object1 += " ";
   object1 += object5;
   cout << "object1: " << object1 << endl;

   return 0;
}
Esempio n. 2
0
bool pair_test( )
{
  std::pair< int, char > object1( 1, 'H' );
  std::pair< int, char > object2( 0, 'H' );
  std::pair< int, char > object3( 1, 'G' );

  // Does std::make_pair do something reasonable?
  if( !( object1 == std::make_pair( 1, 'H' ) ) ) FAIL;

  // Verify std::pair's relational operators.
  if( !( object1 == object1 ) ) FAIL;
  if(  ( object1 == object2 ) ) FAIL;
  if(  ( object1 == object3 ) ) FAIL;
  if( !( object2 <  object1 ) ) FAIL;
  if( !( object3 <  object1 ) ) FAIL;
  if( !( object2 <  object3 ) ) FAIL;

  // Make sure the other relational operators can be instantiated properly.
  if( !( object1 != object2 ) ) FAIL;
  if( !( object1 >  object2 ) ) FAIL;
  if(  ( object1 <= object2 ) ) FAIL;
  if( !( object1 >= object2 ) ) FAIL;

  // This sort of thing comes up when map's value_type is used.
  std::pair< const int, int > object( std::make_pair( 1, 2 ) );
  if( !( object.first == 1 ) || !( object.second == 2 ) ) FAIL;

  return true;
}
int main()
{
	MyString object1("This"), object2("is");
	MyString object3("a test.");
	MyString object4 = object1;
	MyString object5("is only a test");
	char string1[] = "a test.";

	std::cout << "Object1: " << object1 << std::endl;
	std::cout << "Object2: " << object2 << std::endl;
	std::cout << "Object3: " << object3 << std::endl;
	std::cout << "Object4: " << object4 << std::endl;
	std::cout << "Object5: " << object5<< std::endl;
	std::cout << "String 1:" << string1 << std::endl;
	object1 += " ";
	object1 +=object2;
	object1 += " ";
	object1 += object3;
	object1 += " ";
	object1 += object4;
	object1 += " ";
	object1 += object5;
	object1 += " ";
	std::cout << "object1: " << object1 << std::endl;

   return 0;
}
Esempio n. 4
0
int main(int argc, const char* argv[])
{
    /* Get x translation from commandline */
    if (argc == 2) {
        user_x_translate = atoi( argv[1] );
    }

    dpoint          point1(100, 100, 100);
    dpoint          point2(50, 50, 50);
    simpleObject    object1("object_1", point1);
    simpleObject    object2("object_2", point2, 10, 10);

    /* Use the new function display_info() to output object information */
    object1.display_info( stdout );
    object2.display_info( stdout );

    printf("\nChecking if objects are equal...\n");

    /* check if these objects occupy the same location */
    printf("object1 & object2 %s occupy the same place...\n",
        (object1 == object2)?"DO":"DO NOT");
        
    printf("moving object2 by 50,50,50...\n");
    object2.translate( 50, 50, 50 );

    object2.display_info( stdout, "object2" );
    /* check if these objects occupy the same location */
    printf("object1 & object2 %s occupy the same place...\n",
        (object1 == object2)?"DO":"DO NOT");
    
    printf("\n");
    
    /* Test the new complexObject class */
    complexObject    object3( "object_3", 20, -10, 30, 15, 15, 8, 0.5 );
    object3.display_info( stdout );
    
    /* Attempt to move it out of range!!! */
    
    printf("Translating object3 by %d, 0, 0...\n", user_x_translate);
    if (!object3.translate( user_x_translate, 0, 0 )) {
        printf("Unable to move object3 by %d, 0, 0!\n", user_x_translate);
    }
    
    object3.display_info( stdout );
    
    return 0;        
}
Esempio n. 5
0
    void testSerialization ()
    {
        testcase ("serialization");

        unexpected (sfGeneric.isUseful (), "sfGeneric must not be useful");

        SField const& sfTestVL = SField::getField (STI_VL, 255);
        SField const& sfTestH256 = SField::getField (STI_HASH256, 255);
        SField const& sfTestU32 = SField::getField (STI_UINT32, 255);
        SField const& sfTestObject = SField::getField (STI_OBJECT, 255);

        SOTemplate elements;
        elements.push_back (SOElement (sfFlags, SOE_REQUIRED));
        elements.push_back (SOElement (sfTestVL, SOE_REQUIRED));
        elements.push_back (SOElement (sfTestH256, SOE_OPTIONAL));
        elements.push_back (SOElement (sfTestU32, SOE_REQUIRED));

        STObject object1 (elements, sfTestObject);
        STObject object2 (object1);

        unexpected (object1.getSerializer () != object2.getSerializer (),
            "STObject error 1");

        unexpected (object1.isFieldPresent (sfTestH256) ||
            !object1.isFieldPresent (sfTestVL), "STObject error");

        object1.makeFieldPresent (sfTestH256);

        unexpected (!object1.isFieldPresent (sfTestH256), "STObject Error 2");

        unexpected (object1.getFieldH256 (sfTestH256) != uint256 (),
            "STObject error 3");

        if (object1.getSerializer () == object2.getSerializer ())
        {
            WriteLog (lsINFO, STObject) << "O1: " << object1.getJson (0);
            WriteLog (lsINFO, STObject) << "O2: " << object2.getJson (0);
            fail ("STObject error 4");
        }
        else
        {
            pass ();
        }

        object1.makeFieldAbsent (sfTestH256);

        unexpected (object1.isFieldPresent (sfTestH256), "STObject error 5");

        unexpected (object1.getFlags () != 0, "STObject error 6");

        unexpected (object1.getSerializer () != object2.getSerializer (),
            "STObject error 7");

        STObject copy (object1);

        unexpected (object1.isFieldPresent (sfTestH256), "STObject error 8");

        unexpected (copy.isFieldPresent (sfTestH256), "STObject error 9");

        unexpected (object1.getSerializer () != copy.getSerializer (),
            "STObject error 10");

        copy.setFieldU32 (sfTestU32, 1);

        unexpected (object1.getSerializer () == copy.getSerializer (),
            "STObject error 11");

        for (int i = 0; i < 1000; i++)
        {
            Blob j (i, 2);

            object1.setFieldVL (sfTestVL, j);

            Serializer s;
            object1.add (s);
            SerialIter it (s.slice());

            STObject object3 (elements, it, sfTestObject);

            unexpected (object1.getFieldVL (sfTestVL) != j, "STObject error");

            unexpected (object3.getFieldVL (sfTestVL) != j, "STObject error");
        }
    }
void class13Driver(){
    
    int id;
    int price;
    string category;
    string brand;
    int quantity;
    string style;
    string color;
    string material;
    string country;
    string clothsize;
    string clothtype;
    
    cout<<"Enter product ID : ";
    cin>>id;
    cout<<"Enter product price : ";
    cin>>price;
    cin.ignore(1000,'\n');
    cout<<"Enter product category(Mens,Womens,Kids) : ";
    getline(cin,category);
    cout<<"Enter product brand name : ";
    getline(cin,brand);
    cout<<"Enter product quantity : ";
    cin>>quantity;
    
    cout<<endl;
    cout<<"-------------- Default output---------------\n";
    Product object1(id,price,category,brand,quantity);
    object1.print();

    cout<<endl;
    cout<<"-------------- Cloth ---------------\n";
    
    cout<<"Enter product ID : ";
    cin>>id;
    cout<<"Enter product price : ";
    cin>>price;
    cin.ignore(1000,'\n');
    cout<<"Enter product category(Mens,Womens,Kids) : ";
    getline(cin,category);
    cout<<"Enter product brand name : ";
    getline(cin,brand);
    cout<<"Enter product quantity : ";
    cin>>quantity;
    cin.ignore(1000,'\n');
    cout<<"Enter cloth size : ";
    getline(cin,clothsize);
    cout<<"Enter cloth maden country : ";
    getline(cin, country);
    cout<<"Enter cloth type : ";
    getline(cin,clothtype);
    
    cout<<endl;
    cout<<"-------------- Cloth output---------------\n";
    Cloths object2(id,price,category,brand,quantity,clothsize,country,clothtype);
    object2.showClothsList();
    
    cout<<endl;
    cout<<"-------------- Bag ---------------\n";
    
    cout<<"Enter product ID : ";
    cin>>id;
    cout<<"Enter product price : ";
    cin>>price;
    cin.ignore(1000,'\n');
    cout<<"Enter product category(Mens,Womens,Kids) : ";
    getline(cin,category);
    cout<<"Enter product brand name : ";
    getline(cin,brand);
    cout<<"Enter product quantity : ";
    cin>>quantity;
    cin.ignore(1000,'\n');
    cout<<"Enter bag style : ";
    getline(cin, style);
    cout<<"Enter bag color : ";
    getline(cin, color);
    cout<<"Enter bag material : ";
    getline(cin, material);
    
    cout<<endl;
    cout<<"-------------- Bag output---------------\n";
    
    Bag object3(id,price,category,brand,quantity,style,color,material);
    object3.showBag();
    
}