Example #1
0
int main ()
{
	using std::cin;
	using std::cout;
	using std::endl;
	using std::strchr;
	
	Person * lolas[SIZE];
	int ct;
	
	for (ct = 0; ct < SIZE; ct++)
	{
		char choice;
		cout << "Enter the person category:\n"
		<< "g: Gunslinger p: PokerPlayer "
		<< "b: BadDude q: quit\n";
		cin >> choice;
		while (strchr("gpbq", choice) == NULL)
		{
			cout << "Please enter g, p, b, or q: ";
			cin >> choice;
		}
		if (choice == 'q')
		break;
		switch(choice)
		{
			case 'g': lolas[ct] = new Gunslinger;
			break;
			case 'p': lolas[ct] = new PokerPlayer;
			break;
			case 'b': lolas[ct] = new BadDude;
			break;
		}
		cin.get();
		lolas[ct]->Set();
	}
	
	cout << "\nHere is your staff:\n"; 
	int i;
	for (i = 0; i < ct; i++)
	{
		cout << endl;
		lolas[i]->Show() ;
	}
	
	for (i = 0; i < ct; i++)
		delete lolas[i];
	
	cout << "VVVVVVV" << endl;
	PokerPlayer::Init();
	Gunslinger g;
	PokerPlayer pp;
	BadDude	bd;
	cout << "Gunslinger: " << g.Draw() << endl;
	cout << "PokerPlayer: " << pp.Draw() << endl;
	cout << "BadDude: " << bd.Gdraw() << ", " << bd.Cdraw() << endl;
	
	cout << "Bye.\n";
	return 0;
}
Example #2
0
int main()
{
    using std::cin;
    using std::cout;
    using std::endl;
    using std::strchr;

    Worker * lolas[SIZE];

    int ct;

    for (ct = 0; ct < SIZE; ct++)
    {
        char choice;
        cout << "Enter the employee category:\n"
             << "w: waiter s: singer"
             << "t: singing waiter q: quit\n";
        cin >> choice;

        while (strchr("wstq", choice) == NULL)
        {
            cout << "Please enter a w, s, t, or q: ";
            cin >> choice;
        }

        if (choice == 'q')
            break;

        switch(choice)
        {
            case 'w':   lolas[ct] = new Waiter;
                        break;
            case 's':   lolas[ct] = new Singer;
                        break;
            case 't':   lolas[ct] = new SingingWaiter;
                        break;
        }

        cin.get();
        lolas[ct]->Set();
    }

    cout << "\nHere is your staff:\n";

    int i;

    for (i = 0; i < ct; i++)
    {
        cout << endl;
        lolas[i]->Show();
    }

    for (i = 0; i < ct; i++)
        delete lolas[i];

    cout << "Bye. \n";

    return 0;
}
int main()
{
	using std::cin;
	using std::cout;
	using std::endl;
	using std::strchr;
	QueueTp<Worker*> lolac(SIZE);
	int ct;
	for (ct = 0; ct < SIZE; ct++)
	{
		Worker *temp=nullptr;
		char choice;
		cout << "Enter the employee category:\n"
			<< "w:waiter    s:singer "
			<< "t:singing waiter  q:quit\n";
		cin >> choice;
		while (strchr("wstq", choice) == NULL)
		{
			cout << "Please enter a w ,s ,t, or q: ";
			cin >> choice;
		}
		if (choice == 'q')
			break;
		switch (choice)
		{
		case 'w':
			temp = new Waiter; 
			break;
		case 's':
			temp = new Singer; 
			break;
		case 't':
			temp = new SingingWaiter; 
			break;
		}
		cin.get();
		temp->Set();
		lolac.enqueue(temp);
		//注意这里不能显式地写delete temp,因为delete temp删除的是temp指向的内存,delete后,会导致前面的temp->set()赋值的东西全部被删除。
		//temp指针会在for语句块后被自动删除,而不会删除指向的内存块;temp指向的内存块的删除是靠的QueueTp的析构函数~QueueTp();
	}
	cout << "\nHere is your staff:\n";
	int i;
	for (i = 0; i < ct; i++)
	{
		Worker *temp=nullptr;
		cout << endl;
		lolac.dequeue(temp);
		temp->Show();
	}
	cout << "Bye.\n";
	return 0;
}
Example #4
0
int main()
{
   using std::cin;
   using std::cout;
   using std::endl;
   using std::strchr;

   QueueTP<Worker *> lolas(SIZE);
   

    int ct;
    Worker * pwk;
    for (ct = 0; ct < SIZE; ct++)
    {
        char choice;
        cout << "Enter the employee category:\n"
            << "w: waiter  s: singer  "
            << "t: singing waiter  q: quit\n";
        cin >> choice;
        while (strchr("wstq", choice) == NULL)
        {
            cout << "Please enter a w, s, t, or q: ";
            cin >> choice;
        }
        if (choice == 'q')
            break;
        switch(choice)
        {
            case 'w':   pwk = new Waiter;
                        break;
            case 's':   pwk = new Singer;
                        break;
            case 't':   pwk = new SingingWaiter;
                        break;
        }
        cin.get();
        pwk->Set();
        lolas.enqueue(*pwk);
        delete pwk;
    }

    cout << "\nHere is your staff:\n";
    while (!lolas.isempty())
    {
        cout << endl;
        lolas.dequeue(*pwk);
        pwk->Show();        
    }
    cout << "Total call of base constructor:" << Worker::num_of_constructors_ << endl;
    cout << "Bye.\n";
    return 0; 
}
int main()
{
    using std::cin;
    using std::cout;
    using std::endl;
    using std::strchr;

    Worker * lolas[SIZE];
    int ct;
    for (ct = 0; ct < SIZE; ct++)
    {
        char choice;
        cout << "Zadejte kategorii zamestnance:\n"
             << "c: cisnik p: pevec "
             << "t: zpivajici cisnik k: konec\n";
        cin >> choice;
        while (strchr("cptk", choice) == NULL)
        {
            cout << "Zadejte prosim c, p, t nebo k: ";
            cin >> choice;
        }
        if (choice == 'k')
            break;
        switch(choice)
        {
        case 'c':
            lolas[ct] = new Waiter;
            break;
        case 'p':
            lolas[ct] = new Singer;
            break;
        case 't':
            lolas[ct] = new SingingWaiter;
            break;
        }
        cin.get();
        lolas[ct]->Set();
    }

    cout << "\nZde je vas tym:\n";
    int i;
    for (i = 0; i < ct; i++)
    {
        cout << endl;
        lolas[i]->Show();
    }
    for (i = 0; i < ct; i++)
        delete lolas[i];
    cout << "Nashledanou.\n";
    return 0;
}
Example #6
0
void KeyBinder::ParseText(char *text, int len)
{
	char *ptr, *end;
	const char LF = '\n';
	
	ptr = text;
	
	// last (useful) line must end with LF
	while ((ptr - text) < len && (end = strchr(ptr, LF)) != 0) {
		*end = '\0';
		ParseLine(ptr);
		ptr = end + 1;
	}  
}
int main()
{
    using std::cin;
    using std::cout;
    using std::endl;
    using std::strchr;
    person * lolas[SIZE];
    int ct;
    for (ct = 0; ct < SIZE; ct++) {
        char choice;
        cout << "Enter the employee category:\n"
        << "g:Gunslinger p: PorkerPlayer "
        << "b: BadDude q: quit\n";
        cin >> choice;
        while (strchr("gpbq", choice) == NULL)
        {
            cout << "Please enter a g, p, b, or q: ";
            cin >> choice;
        }
        if (choice == 'q')
            break;
        switch(choice)
        {
            case 'g':
                lolas[ct]= new gunslinger;
                break;
            case 'p':
                lolas[ct]= new pokerplayer;
                break;
            case 'b':
                lolas[ct] = new baddude;
                break;
        }
        cin.get();
        
    }
    cout << "\nHere is your staff:\n";
    int i;
    for (i = 0; i < ct; i++) {
        person *temp=lolas[i];
        cout << endl;
        temp->show();
        
    }
    cout << "Bye.\n";
    return 0;
}
Example #8
0
/** Helper */
static gchar*
sp_object_get_unique_id(SPObject    *object,
                        gchar const *id)
{
    static unsigned long count = 0;

    g_assert(SP_IS_OBJECT(object));

    count++;

    //XML Tree being used here.
    gchar const *name = object->getRepr()->name();
    g_assert(name != NULL);

    gchar const *local = strchr(name, ':');
    if (local) {
        name = local + 1;
    }

    if (id != NULL) {
        if (object->document->getObjectById(id) == NULL) {
            return g_strdup(id);
        }
    }

    size_t const name_len = strlen(name);
    size_t const buflen = name_len + (sizeof(count) * 10 / 4) + 1;
    gchar *const buf = (gchar *) g_malloc(buflen);
    memcpy(buf, name, name_len);
    gchar *const count_buf = buf + name_len;
    size_t const count_buflen = buflen - name_len;
    do {
        ++count;
        g_snprintf(count_buf, count_buflen, "%lu", count);
    } while ( object->document->getObjectById(buf) != NULL );
    return buf;
}
Example #9
0
int main() {
    using std::cin;
    using std::cout;
    using std::endl;
    using std::strchr;
   
    Worker* in[SIZE]; // array of pointers to Worker based classes
    int ct;
	// get input from user and store in Worker*
    for (ct=0; ct<SIZE; ct++) { 
        char choice;
        cout<<"Enter the employee category:\n"<<"w: waiter s: singer "
             <<"t: singing waiter q: quit\n";
        cin>>choice;
        while(strchr("wstq", choice)==nullptr) {
            cout<<"Bad input! Please enter a w, s, t, or q choice: ";
            cin>>choice;
        }
		if(choice=='q')
			break;		//not to take through Set process
        switch(tolower(choice)) {
		case 'w':
            in[ct]=new Waiter;
            break;
        case 's':
            in[ct]=new Singer;
            break;
        case 't':
            in[ct]=new SingingWaiter;
            break;
        }
        cin.get();
        in[ct]->Set(); // get information about chosen worker
    }

    //Exam Simulation: uses pointers to workers : waiters, singers, and singingwaiters take mandatory exam
    // required for continued employment. Only 1 person can take exam at a time in manager's room.

    QueueTP<Worker*> exam(ct);
    Worker* out[SIZE];

    int total_exam_mins=0;
    int empl_exam_mins=1;
    int failed=0;
    int passed=0;
    int index=0;
    bool correct_answer=false;
	std::srand(time(0));
    // Time limit for exam = 10 mins, if employee can't provide correct answer within 10 mins, employee fails the exam.
	int timelimit = 10;

    while (!exam.isfull()) {
        exam.enqueue(in[index]);
        index++;
    }
	index=0; // reset array index to 0
	cout<<"\nThe number of employees taking exam: " <<exam.queuecount()
		<<", Exam time limit = "<< timelimit<<" minutes."<<endl;

    while (!exam.isempty()) {
        correct_answer = passedexam(10); // passedexam randomly generates a number and compares to answer(argument), true if equal
		if (correct_answer && (empl_exam_mins<timelimit) && !exam.isempty()) { 
            exam.dequeue(out[index]);	//remove from queue, and move on to next employee
            cout<<"\nPASSED! Employee ["<<out[index]->Worker::Name()<<", "<<
				out[index]->Worker::ID()<<"], exam time: "<<empl_exam_mins<<"minutes.";
            empl_exam_mins=1; // reset individual time of exam for the next employee
            index++;
            passed++; // increase Passed Employee count
        } else 
			if (!correct_answer && (empl_exam_mins>timelimit) && !exam.isempty()) { 
				exam.dequeue(out[index]);	//remove from queue and move on to the next employee
				cout<<"\nFAILED! Employee ["<< out[index]->Worker::Name()<<", "<<
					out[index]->Worker::ID()<<"], exam time: "<<empl_exam_mins<<" minutes.";
				empl_exam_mins=1;
				index++;
				failed++;
			} else
				if (!correct_answer && !exam.isempty()) // if correct answer is not generated and time is within the timelimit,
					empl_exam_mins++;       // move on to the next cycle (minute) and try again to generate an answer

        total_exam_mins++;
    }
    
    cout<<"\n\nTotal exam time: "<< total_exam_mins<<" minutes.";
    cout<<"\nPassed: "<<passed;
    cout<<"\nFailed: "<<failed;

    // Employee overview, doublechecking that Worker* array of pointers contains correct information and values
    cout<<"\n\nEmployee overview: \n\n";
    for(int i=0; i<ct; i++) {
        out[i]->Show();		// display info
        delete in[i];		// delete stored pointer objects
        cout<<endl;
    }

    cout << "\nBye.";
    return 0;
}
Example #10
0
void lilfes_flag::ParseOptions(machine *mach, int argc, const char **argv)
{
#ifdef DEBUG
	cout << "ParseOptions" << argc << endl;
#endif

	int warn = 0;

#ifdef DEBUG
	cout << "ParseOptions..." << argc << endl;
#endif

#ifdef DEBUG
	cout << "ParseOptions   " << argc << endl;
#endif

	for( int i=1; i<argc; i++ )
	{
#ifdef DEBUG
	cout << "ParseOptions " << i << "/" << argc << "  " << argv[i] << endl;
#endif
		if( argv[i][0] == '-' && argv[i][1] )
		{
			if( argv[i][1] == '-' )  /// オプションが "--なんとか"の場合
			{
				const char *p = strchr(argv[i]+2, '='); //最も末尾側に出現する'='へのポインタを取得
				if( p ) //'='があれば・・・
				{
					lilfes_flag *f = lilfes_flag::Search(string(argv[i]+2, p - (argv[i] + 2)));
					if( f == NULL )
					{
						RUNERR( "Unknown option: --" << argv[i]+2 );
					}
					else
					{
						f->SetFlagFromString(p+1);
					}
				}
				else
				{
					lilfes_flag *f = lilfes_flag::Search(argv[i]+2);

					if( f == NULL )
					{
						RUNERR( "Unknown option: --" << argv[i]+2 );
					}
					else if( strcmp( (argv[i]+2), "argv" ) == 0 )
					{
						//lilfes_arg_flag::SetFlagFromStringArray(argc, argv, i);
						//i += comargc - 1;
						lilfes_arg_flag::SetFlagFromStringArray(argc-i-1, argv+i+1);
						break;
					}
					else
					{
						bool ret = f->SetFlagFromString(argv[i+1]);
						if( ret )
						{
							i++;
						}
					}
				}
			}
			else  /// オプションが "-なんとか"の場合
			{
				lilfes_flag *f = lilfes_flag::GetFlagMap(argv[i][1]);
				if( f == NULL )
				{
					RUNERR( "Unknown option: -" << argv[i][1] );
				}
				else if( argv[i][1] == 'a' )
				{
					lilfes_arg_flag::SetFlagFromStringArray(argc-i-1, argv+i+1);
					break;
				}
				else if( argv[i][2] )
				{
					f->SetFlagFromString(argv[i]+2);
				}
				else
				{
					bool ret = f->SetFlagFromString(argv[i+1]);
					if( ret ) // 次のオプション文字列を消費した場合は、そいつの処理をとばしてその次へ。
					{
						i++;
					}
				}
			}
		}
		else
		{
			if( !warn )
			{
				RUNWARN( "obsolete commandline" );
				warn = 1;
			}
			lilfes_load_flag::pushNewModule( argv[ i ], module::NMT_INCLUDE );
		}
	}

#ifdef DEBUG
	cout << "ParseOptions q" << endl;
#endif
	for ( int i = lilfes_load_flag::getNumLoadModule() - 1; i >= 0; --i )
	{
		module::new_module(*mach, "command line",
						   lilfes_load_flag::getLoadModule( i ).c_str(),
						   lilfes_load_flag::getLoadModuleType( i ));
	}

#ifdef DEBUG
	cout << "ParseOptions r" << endl;
#endif
	if( ! lilfes_flag::Search("no_user_initialize")->GetIntVal() )
	{
		string path;

		const char *init = getenv("LILFESRC");
		if( init != NULL )
		{
			path = init;
		}
		else
		{
			const char *path_ptr = getenv(LOCAL_INITIALIZATION_PATH_ENV);
			if (path_ptr)
			{
				path = path_ptr;
				path += PATH_SEPARATOR;
			}

			path += LOCAL_INITIALIZATION_FILE;
		}
		module::new_module(*mach, "initialization phase", path, module::NMT_INITIALIZE, module::UserModule());
	}

#ifdef DEBUG
	cout << "ParseOptions s" << endl;
#endif
	if( ! lilfes_flag::Search("no_initialize")->GetIntVal() )
	{
		module::new_module(*mach, "initialization phase", GLOBAL_INITIALIZATION_FILE, module::NMT_INITIALIZE, module::UserModule());
	}

#ifdef DEBUG
	cout << "ParseOptions t" << endl;
#endif

#ifdef DEBUG
	cout << "ParseOptions x" << endl;
#endif
}
Example #11
0
int main(int nNumberofArgs, char* pszArgs[])
{
	//*  Variable Declaration
	const int SIZE = 5;
	const int qSIZE = 10;

	//*  Main Code
	
	Worker * lolas[SIZE];
	Worker * salol[SIZE];

    int ct;
    for (ct = 0; ct < SIZE; ct++)
    {
        char choice;
        cout << "Enter the employee category:\n"
            << "w: waiter  s: singer  "
            << "t: singing waiter  q: quit\n";
        cin >> choice;
        while (strchr("wstq", choice) == NULL)
        {
            cout << "Please enter a w, s, t, or q: ";
            cin >> choice;
        }
        if (choice == 'q')
            break;
        switch(choice)
        {
            case 'w':   lolas[ct] = new Waiter;
                        break;
            case 's':   lolas[ct] = new Singer;
                        break;
            case 't':   lolas[ct] = new SingingWaiter;
                        break;
        }
        cin.get();
        lolas[ct]->Set();
    }

    cout << "\nHere is your staff:\n";
    int i;
    for (i = 0; i < ct; i++)
    {
        cout << endl;
        lolas[i]->Show();
    }

	/*
    for (i = 0; i < ct; i++)
        delete lolas[i];
    cout << "Bye.\n";
	*/

	// Beginning of Queue Portion

	QueueTP<Worker *> Todd(qSIZE);
	
	cout << endl << endl;
	cout << "Queue Stuff: " << endl;

	for (int i=0;i<ct;i++)
	{
		Todd.enqueue(lolas[i]);
	}

	for (int i=0;i<ct;i++)
	{
		Todd.dequeue(salol[i]);
	}

	for (int i=0;i<ct;i++)
	{
		salol[i]->Show();
	}

	cout << endl << endl;
	
	//*  Program End
	//   - wait until user is ready before terminating program
	//   - to allow the user to see the program results

	cout << endl << endl;
	system("PAUSE");
	return 0;
}