Example #1
0
int main(void) {
  char *mode, *name, *value;

  mode = qValue("mode");
  name = qValue("cname");
  value = qValue("cvalue");

  if(mode == NULL) { /* View Cookie */
    int amount;
    qContentType("text/html");
    amount = qPrint();
    printf("<p>Total %d entries\n", amount);
  }
  else if(!strcmp(mode, "set")) { /* Set Cookie */
    if(name == NULL || value == NULL) qError("Query not found");
    if(!strcmp(name, "")) qError("Empty cookie name can not be stored.");

    qCookieSet(name, value, 0, NULL, NULL, NULL);
    qContentType("text/html");
    printf("Cookie('%s'='%s') entry is stored.<br>Click <a href='%s'>here</a> to view your cookies\n", name, value, qCGIname());
  }
  else if(!strcmp(mode, "remove")) { /* Remove Cookie */
    if(name == NULL) qError("Query not found");
    if(!strcmp(name, "")) qError("Empty cookie name can not be removed.");

    qCookieRemove(name, NULL, NULL, NULL);
    qContentType("text/html");
    printf("Cookie('%s') entry is removed.<br>Click <a href='%s'>here</a> to view your cookies\n", name, qCGIname());
  }
  else qError("Unknown mode.");

  qFree();
  return 0;
}
void QuaternionManipulator::qtest3()
{
	HEADER("TEST 3 : Yaw 180 = Roll 180 + Pitch 180")

	Vector axis_x = {1.0f, 0.0f, 0.0f, 1.0f};
	Vector axis_y = {0.0f, 1.0f, 0.0f, 1.0f};
	Vector axis_z = {0.0f, 0.0f, 1.0f, 1.0f};

	Quaternion qyaw180 = qFromAngleAxis(900.0f, axis_y); // but not 540.0!
	qPrint("  qyaw180", qyaw180);

	Quaternion qroll180 = qFromAngleAxis(180.0f, axis_x);
	qPrint(" qroll180", qroll180);

	Quaternion qpitch180 = qFromAngleAxis(180.0f, axis_z);
	qPrint("qpitch180", qpitch180);

	Quaternion qtest = qMultiply(qpitch180, qroll180);
	qPrint("    qtest", qtest);

	assert(qEqual(qyaw180, qtest));
}
void QuaternionManipulator::qtest1()
{
	HEADER("TEST 1 : Rotation of 90 degrees about the y-axis")

	Vector axis = {0.0f, 1.0f, 0.0f};
	Quaternion q = qFromAngleAxis(90.0f, axis);
	qPrint("   q", q);

	Quaternion vi = {0.0f, 7.0f, 0.0f, 0.0f};
	qPrint("  vi", vi);

	Quaternion ve = {0.0f, 0.0f, 0.0f, -7.0f};
	qPrint("  ve", ve);

	Quaternion qinv = qInverse(q);
	//qClean(qinv);
	qPrint("qinv", qinv);

	Quaternion vf = qMultiply(qMultiply(q,vi), qinv);
	qPrint("  vf", vf);

	assert(qEqual(vf, ve));
}
void QuaternionManipulator::qtest2()
{
	HEADER("TEST 2 : Rotation of 90 degrees about the y-axis with matrix")

	Vector axis = {0.0f, 1.0f, 0.0f, 1.0f};
	Quaternion q = qFromAngleAxis(90.0f, axis);
	qPrint(" q", q);

	Vector vi = {7.0f, 0.0f, 0.0f, 1.0f};
	vPrint("vi", vi);

	Vector ve = {0.0f, 0.0f, -7.0f, 1.0f};
	vPrint("ve", ve);

	Matrix m;
	qGLMatrix(q,m);

	Vector vf = mMultiply(m, vi);
	vPrint("vf", vf);

	assert(vEqual(vf, ve));
}
int main(int argc, char *argv[])
{
    // Define basic variables.
    int input;
    productList *products;
    Queue *q;
    
    // Allocate memory for pointers.
    products = newProductList();
    q = newQueue();
    
    // Load product-price data store and assert that it succeeded.
    if(loadProductList(products, "priceList.csv")!=0)
    {
                                wait();
                                exit(-1);
    }
    
    queueInit(q); // Initialize queue.

    setAppTitle("SUPER MARKET COUNTER");
    
    showSplash("splash.txt");
    
    getch();
    
    // Loops the menu till user chooses to exit.
    do
    {
        // Declare menu options.
        char mainMenu[][16]={"Arrive", "Process", "Print", "Front", "Rear", "Length", "Exit"};
        
        // Display menu and receive user input.
        input = showMenu("Main Menu", mainMenu, 7);
        
        // Choose a function based on user input.
        switch(input)
        {
                        case 1:
                             qArrive(q, products);
                             break;
                             
                        case 2:
                             qProcess(q);
                             break;
                             
                        case 3:
                             qPrint(q);
                             break;
                             
                        case 4:
                             qFront(q);
                             break;
                                  
                        case 5:
                             qRear(q);
                             break;
                                  
                        case 6:
                             qLength(q);
                             break;
                                  
                        case 7:
                                  qExit(q, products);
                                  break;
                                  
                        default: 
                                 printf("Invalid Menu Option. Try again!");
                                 wait();
                                 continue;
        };    
    }while(1);
    
    return 0;
}