Example #1
0
void processPurchase() {
	//read the customer name, type of purchase, and amount purchased
	String name;
	readString(name);
	String type;
	readString(type);
	int amount;
	readNum(amount);

	Customer* ben = &database[name];
	//if customer purchased 0 of everything, delete his record
	if (*selectInventItem("Bottles", *ben) == 0 && *selectInventItem("Diapers", *ben) == 0 && *selectInventItem("Rattles", *ben) == 0 && amount == 0) {
		database.length -= 1;				//decrement number of customers by 1
		return;
	}
	//valid customer or a valid purchase, so process purchase
	if (*selectInventItem(type) < amount){	//if amount purchase exceeded inventory amount, print error message
		printf("Sorry %s, We only have %d %s\n", name.c_str(), *selectInventItem(type), type.c_str());
		if (*selectInventItem("Bottles", *ben) == 0 && *selectInventItem("Diapers", *ben) == 0 && *selectInventItem("Rattles", *ben) == 0){
			database.length -= 1;
			return;
		}
	}
	else{	//amount was purchaseable, 
		*selectInventItem(type) -= amount;
		*selectInventItem(type, *ben) += amount;
	}
}
Example #2
0
void processPurchase() {
	String customer_name;
	String object;
	int quantity;
	int customer_present = 0;

	readString(&customer_name);
	readString(&object);
	readNum(&quantity);

	for (int k = 0; k < num_customers; k += 1) {	//check every existing customer
		if (StringIsEqualTo(&(customers[k].name), &customer_name)) {
			customer_present = 1;
			processCustomerRequest(&customer_name, &object, quantity, k);
		}
	}
		//non existing customers here
	if (!customer_present && num_customers < MAX_CUSTOMERS) {
		if(!processCustomerRequest(&customer_name, &object, quantity, num_customers) && quantity > 0){
			//enough inventory to purchase, add customer to database
			customers[num_customers].name = StringDup(&customer_name);
			num_customers += 1;
		}
	}

		//destroy strings used for error messages

	StringDestroy(&customer_name);
	StringDestroy(&object);
	
}
Example #3
0
void processInventory() {
	String type;								//read inventory type
	readString(type);
	int amount;								//read amount of inventory to add
	readNum(amount);
	*selectInventItem(type) += amount;		//add selected amount of inventory to the correct global type
}
Example #4
0
Doctor::Doctor(int drid) : Person(drid)
{
    this->id = drid;
    this->setAddress(readString("Address"));
    this->setPhone(readNum("Phone",1000000,99999999));
    this->prescribed = new List(FIFO);
}
Example #5
0
void processInventory() {
	String item;
	int amount_added;
	readString (item);
	readNum (amount_added);

	int* amount_current = selectInventItem (item);
	*amount_current += amount_added;
}
Example #6
0
void processPurchase () {
	String name;
	String item;
	int amount_requested;
	readString (name);
	readString (item);
	readNum (amount_requested);

	int* amount_available = selectInventItem (item);
	if (amount_requested > *amount_available) {
		printf ("Sorry %s, we only have %d %s\n", name.c_str (), *amount_available, item.c_str ());
		return;
	}

	else {
		int* customer_amount = selectInventItem (item, database[name]);	//finds customer if present, adds customer if not
		*customer_amount += amount_requested;
		*amount_available -= amount_requested;
	}
}
Example #7
0
Tools::RPoint NSParser::readFixedPoint(Symbol* symbol)
{
	Tools::RPoint point;
	bool xOk = false;
	bool yOk = false;
	if (symbol->type == NON_TERMINAL)
	{
		NonTerminal* nt = static_cast<NonTerminal*>(symbol);
		for(Symbol* child: nt->children)
		{
			switch(child->symbolIndex)
			{
				case SYM_NUM:
				case SYM_FIXED_ANGLE:
				{
					double value = readNum(child);
					if (!xOk)
					{
						point.setX(value);
						xOk = true;
					}
					else if (!yOk)
					{
						point.setY(value);
						yOk = true;
					}
					else
					{
						double angle = readFixedAngleInRadian(child);
						point.setTheta(angle);
					}
					break;
				}
			}
		}
	}

	return point;
}
Example #8
0
double NSParser::readFixedAngleInRadian(Symbol* symbol)
{
	double value = 0.0;
	if (symbol->type == NON_TERMINAL)
	{
		NonTerminal* nt = static_cast<NonTerminal*>(symbol);
		Symbol* numSymbol = searchChild(symbol, SYM_NUM);
		if (numSymbol)
			value = readNum(numSymbol);

		switch(nt->ruleIndex)
		{
			case PROD_FIXED_ANGLE_RAD:
				break;
			case PROD_FIXED_ANGLE_DEG:
			case PROD_FIXED_ANGLE:
			default:
				value = Tools::degreeToRadian(value);
				break;
		}
	}

	return value;
}
Example #9
0
void processInventory() {
	String object;
	int quantity;
	String Bottles = StringCreate("Bottles");
	String Diapers = StringCreate("Diapers");
	String Rattles = StringCreate("Rattles");

	readString(&object);
	readNum(&quantity);

	if (StringIsEqualTo(&object, &Bottles)) {
		store_inv.bottles += quantity;
	}
	else if (StringIsEqualTo(&object, &Diapers)) {
		store_inv.diapers += quantity;
	}
	else if (StringIsEqualTo(&object, &Rattles)) {
		store_inv.rattles += quantity;
	}
	StringDestroy(&object);
	StringDestroy(&Bottles);
	StringDestroy(&Diapers);
	StringDestroy(&Rattles);
}
Example #10
0
QRectF NSParser::readFixedRect(Symbol* symbol, VariableList& variables)
{
	QRectF r(0,0,1,1);
	Tools::RPoint center;
	bool definedByCenter = false;
	double radius = 0;
	int nbParamRead = 0;
	if (symbol->type == NON_TERMINAL)
	{
		NonTerminal* nt = static_cast<NonTerminal*>(symbol);
		for(Symbol* child: nt->children)
		{
			switch(child->symbolIndex)
			{
				case SYM_NUM:
				{
					double value = readNum(child);
					if (definedByCenter)
						radius = value;
					else if (nbParamRead == 0)
						r.setX(value);
					else if (nbParamRead == 1)
						r.setY(value);
					else if (nbParamRead == 2)
						r.setWidth(value);
					else
						r.setHeight(value);
					++nbParamRead;
					break;
				}
				case SYM_POINT:
				case SYM_FIXED_POINT:
				{
					definedByCenter = true;
					center = readPoint(child);
					break;
				}
				case SYM_VAR:
				{
					QString name = readVar(child);
					if (variables.contains(name))
					{
						DeclaredVariable& var = variables[name];
						if (var.isPoint())
						{
							center = var.toPoint();
							definedByCenter = true;
						}
						else
							addError(NSParsingError::invalidVariableTypeError(name, "point", child));
					}
					else
						addError(NSParsingError::undeclaredVariableError(name, child));


					break;
				}
			}
		}
	}

	if (definedByCenter)
	{
		r.setWidth(radius * 2.0);
		r.setHeight(radius * 2.0);
		r.moveCenter(center.toQPointF());
	}

	return r;
}
Example #11
0
/**
* @brief Function reads config file 
*
* @details Function reads config file and record to pcb table
*
* @pre char* fileName contains the name of config file
*
* @pre struct* pcb contains the pcb table
*
* @post if the config file doesn't exist, end the program
*
* @post all pcb information recorded in pcb table
*
* @return None
*
*/
   void readConfig( char* fileName, struct pcb_table* pcb )
      {
       FILE* filePtr;   // file pointer
       char line[60];   // string holds each line of file
       char temp[15];   // temp string

       // open file and read
       filePtr = fopen( fileName, "r" );

       // if the file doesn't exist
       if( filePtr == NULL )
          {
           printf( "CONFIGURATION FILE NOT FOUND!\n" );
           exit( 1 );
          }

       // otherwise
       else
          {
           // loop to each line
           while( fgets( line, sizeof(line), filePtr ) )
              {
               // ingore these lines
               if( strncmp( line, "Start Simulator Configuration File", 15 ) == 0
                || strncmp( line, "Version/Phase: ", 10 ) == 0
                || strncmp( line, "End Simulator Configuration File", 15 ) == 0 )
                  continue;

               // read and record meta file name
               if( strncmp( line, "File Path: ", 10 ) == 0 )
                  readString( pcb -> dataFile, line );

               // read and record scheduling mode
               if( strncmp( line, "CPU Scheduling Code: ", 10 ) == 0 )
                  {
                   readString( pcb-> scheduling, line);

                   // check if the scheduling mode supported
                   if( strcmp( pcb-> scheduling, "FIFO-P") == 0 )
                      continue;
                   else
                      {
                       printf("Scheduling Mode Does Not Support!\n");
                       exit( 1 );
                      }
                  }

               if( strncmp( line, "Quantum Time (cycles): ", 10 ) == 0 )
                  readNum( &( pcb -> quantumTime ), line );

               // read and record processor cycle time
               if( strncmp( line, "Processor cycle time (msec): ", 10 ) == 0 )
                  readNum( &( pcb -> processorCycleTime ), line );

               // read and record monitor cycle time
               if( strncmp( line, "Monitor display time (msec): ", 10 ) == 0 )
                  readNum( &( pcb -> monitorCycleTime ), line );

               // read and record hard drive cycle time
               if( strncmp( line, "Hard drive cycle time (msec): ", 10 ) == 0 )
                  readNum( &( pcb -> hardDriveCycleTime ), line );

               // read and record printer cycle time
               if( strncmp( line, "Printer cycle time (msec): ", 10 ) == 0 )
                  readNum( &( pcb -> printerCycleTime ), line );

               // read and record keyboard cycle time
               if( strncmp( line, "Keyboard cycle time (msec): ", 10 ) == 0 )
                  readNum( &( pcb -> keyboardCycleTime ), line );

               // read and record log mode
               if( strncmp( line, "Log: ", 4 ) == 0 )
                  {
                   readString( temp, line );

                   if( strncmp( temp, "Log to Both", 11 ) == 0 )
                      pcb -> logMode = 1;
                   if( strncmp( temp, "Log to Monitor", 14 ) == 0 )
                      pcb -> logMode = 2;
                   if( strncmp( temp, "Log to File", 11 ) == 0 )
                      pcb -> logMode = 3;
                  }

               // read and record output file name
               if( strncmp( line, "Log File Path: ", 10 ) == 0 )
                   readString( pcb -> outputFile, line );
              }   // end of loop
          }

      // close file
      fclose(filePtr);
      }   // end of func
Example #12
0
int readFilePGM(FILE *file, PGM *image)
{
    PGM tempImg;
    int i;
	char c;
	int temp;
	/*first line*/
	c = fgetc(file);
	if(c!='P')
		return -1;	/*File Format Error*/
	c = fgetc(file);
	if(c!='2')
		return -1;	/*File Format Error*/
	
	/*clear line one space and read to next line*/
	do
	{
		c=fgetc(file);
		if(c=='\n')
			break;
		if(c==EOF||!isspace(c))		/*if some EOF or non-space char in line 1*/
			return -1;
	}while(1);

	/*if comment, ignore until LF*/
	c=fgetc(file);
	if(c==EOF)
		return -1;
	if(c=='#')
	{
		do
		{
			c=fgetc(file);
			if(c=='\n')
				break;
			if(c==EOF)		/*if EOF in the comment line*/
				return -1;
		}while(1);
	}
	else
		ungetc(c, file);	/*put back the character*/

	
	/*width and height and greyMax*/
	tempImg.width = readNum(file);
	tempImg.height = readNum(file);
	tempImg.greyMax = readNum(file);
	if(tempImg.width<0 || tempImg.height<0 || tempImg.greyMax<=0)
		return -1;
	if(tempImg.width>300 || tempImg.height>300 || tempImg.greyMax>255)
		return -1;

	/*read pixel*/
	for (i=0; i< tempImg.width * tempImg.height; i++)
	{
        temp = readNum(file);
		if(temp<0)
			return -1;
		tempImg.pixelData[i] = temp;
	}
	
	/*store the correct image into program*/
	reset(image);
    memcpy(image, &tempImg, sizeof(PGM));
	return 0;
}
Example #13
0
Token::Type CssTokenizer::readNextToken(){
  if (in == NULL) {
    currentToken.type = Token::EOS;
    return Token::EOS;
  }

  currentToken.clear();
  switch (lastRead) {
  case '@':
    currentToken.type = Token::ATKEYWORD;
    currentToken.add(lastRead);
    readChar();
    if (!readIdent()) {
      currentToken.type = Token::OTHER;
    }
    break;
    
  case '#':
    currentToken.type = Token::HASH;
    currentToken.add(lastRead);
    readChar();
    if (!readName()) {
      throw new ParseException(&lastRead,
                               "name following '#'");
    }
    break;
    
  case '-':
    currentToken.add(lastRead);
    readChar();
    if (readNum(true)) {
      currentToken.type = Token::NUMBER;
      readNumSuffix();
    } else if (readIdent()) {
      currentToken.type = Token::IDENTIFIER;
    } else
      currentToken.type = Token::OTHER;
    break;
    
  case '~':
    currentToken.add(lastRead);
    readChar();
    if (lastRead == '=') {
      currentToken.add(lastRead);
      readChar();
      currentToken.type = Token::INCLUDES;
    } else
      currentToken.type = Token::OTHER;
    break;
    
  case '|':
    currentToken.add(lastRead);
    readChar();
    if (lastRead == '=') {
      currentToken.add(lastRead);
      readChar();
      currentToken.type = Token::DASHMATCH;
    } else
      currentToken.type = Token::OTHER;
    break;
    
  case '/':
    currentToken.add(lastRead);
    readChar();
    if (readComment()) 
      currentToken.type = Token::COMMENT;
    else
      currentToken.type = Token::OTHER;
    break;
    
  case ';':
    currentToken.type = Token::DELIMITER;
    currentToken.add(lastRead);
    readChar();
    break;
  case ':':
    currentToken.type = Token::COLON;
    currentToken.add(lastRead);
    readChar();
    break;
  case '{':
    currentToken.type = Token::BRACKET_OPEN;
    currentToken.add(lastRead);
    readChar();
    break;
  case '}':
    currentToken.type = Token::BRACKET_CLOSED;
    currentToken.add(lastRead);
    readChar();
    break;
  case '(':
    currentToken.type = Token::PAREN_OPEN;
    currentToken.add(lastRead);
    readChar();
    break;
  case ')':
    currentToken.type = Token::PAREN_CLOSED;
    currentToken.add(lastRead);
    readChar();
    break;
  case '[':
    currentToken.type = Token::BRACE_OPEN;
    currentToken.add(lastRead);
    readChar();
    break;
  case ']':
    currentToken.type = Token::BRACE_CLOSED;
    currentToken.add(lastRead);
    readChar();
    break;
    
  case '.':
    currentToken.add(lastRead);
    readChar();
    if (readNum(false)) {
      currentToken.type = Token::NUMBER;
      readNumSuffix();
    } 
    break;

  default:
    if (readString()) 
      currentToken.type = Token::STRING;
    else if (readNum(true)) {
      currentToken.type = Token::NUMBER;
      readNumSuffix();

    } else if (readIdent()) {
      currentToken.type = Token::IDENTIFIER;

      if (currentToken.str == "url" && readUrl())
        currentToken.type = Token::URL;
      else if (currentToken.str == "u" && lastReadEq('+')) {
        currentToken.add(lastRead);
        readChar();
        currentToken.type = Token::UNICODE_RANGE;
        readUnicodeRange();
      }
    } else if (readWhitespace()) {
      currentToken.type = Token::WHITESPACE;
      while (readWhitespace()) {};
    } else {
      currentToken.add(lastRead);
      readChar();
    }
    break;
  }

  return currentToken.type;
}