示例#1
0
int main(int argc, char* argv[])
{
  double strike = 50.0;
  double expiry = 90;
  std::unique_ptr<PayOff> payOffUnique( new PayOffCall(strike) );
  std::shared_ptr<PayOff> payOffShared( new PayOffCall(strike) );

  double spot = 60;
  OptionUnique option1( std::move(payOffUnique), expiry );
  std::cout << option1(spot) << std::endl;

  // Can't reuse unique_ptr - seg faults at run time if we try
  // since payOffUnique now just contains NULL
  // OptionUnique option2( std::move(payOffUnique), expiry );
  auto option2 = std::move(option1); // Can move option
  std::cout << option2(spot) << std::endl;
  // Now option1 is invalid and seg faults if used.
  // std::cout << option1(spot) << std::endl;
  
  // Can reuse shared_ptr
  OptionShared option3( payOffShared, expiry );
  std::cout << option3(spot) << std::endl;
  
  OptionShared option4( payOffShared, expiry );
  std::cout << option4(spot) << std::endl;

  auto option5 = option4;
  std::cout << option5(spot) << std::endl;

  return 0;
}
示例#2
0
文件: includeTest.c 项目: 1587/ltp
static int test_ioctl(struct inode *ino, struct file *f, unsigned int cmd,
		      unsigned long l)
{

	int rc = 0;		//return code
	int arg;

	printk("Entered the ioctl call.\n");

	if (copy_from_user(&arg, (void *)l, sizeof(int))) {
		//bad address
		return (-EFAULT);
	}

	switch (cmd) {

	case OPTION1:
		option1();
		break;
	default:
		printk("Mismatching ioctl command\n");
		break;
	}

	//0 by default
	return rc;
}
END_TEST

START_TEST (test_conversion_options_constructor)
{
  ConversionOption option1("key", "test", "");
  fail_unless(option1.getValue() == "test");
  fail_unless(option1.getType() == CNV_TYPE_STRING);

  ConversionOption option2("key", 1.1, "");
  fail_unless(option2.getDoubleValue() == 1.1);
  fail_unless(option2.getType() == CNV_TYPE_DOUBLE);

  ConversionOption option3("key", 1.1f, "");
  fail_unless(option3.getFloatValue() == 1.1f);
  fail_unless(option3.getType() == CNV_TYPE_SINGLE);

  ConversionOption option4("key", 10, "");
  fail_unless(option4.getIntValue() == 10);
  fail_unless(option4.getType() == CNV_TYPE_INT);

  ConversionOption option5("key", false, "");
  fail_unless(option5.getBoolValue() == false);
  fail_unless(option5.getType() == CNV_TYPE_BOOL);

}
示例#4
0
SimpleJoint* SimulatedWorld::AddJoint()
{
	SimpleJoint* createdJoint;
	wxArrayString options; wxString option1("Prismatic"); wxString option2("rotational");
	options.Add(option1); options.Add(option2);
	wxArrayString AxisOptions; wxString AxisOption1("X_AXIS"); wxString AxisOption2("Y_AXIS");wxString AxisOption3("Z_AXIS");
	AxisOptions.Add(AxisOption1);AxisOptions.Add(AxisOption2);AxisOptions.Add(AxisOption3);
	bool prismatic=false; int axis=0;double vmin=-PI; double vmax=PI;
	wxString Type;
	wxSingleChoiceDialog myDialog(NULL,wxString("Select joint type"),wxString("Options"),options);
	if (myDialog.ShowModal()==wxID_OK )
	{
		if(myDialog.GetStringSelection()==wxString("Prismatic")) prismatic=true;
			else prismatic=false;
	}
	wxTextEntryDialog myDialogVmax(NULL,wxString("Introduce Vmax"),wxGetTextFromUserPromptStr,wxEmptyString,wxTextEntryDialogStyle,wxDefaultPosition);
	if (myDialogVmax.ShowModal()==wxID_OK )
	{
		wxString value=myDialogVmax.GetValue();
		value.ToDouble(&vmax);
	}
	wxTextEntryDialog myDialogVmin(NULL,wxString("Introduce Vmin"),wxGetTextFromUserPromptStr,wxEmptyString,wxTextEntryDialogStyle,wxDefaultPosition);
	if (myDialogVmin.ShowModal()==wxID_OK )
	{
			wxString value=myDialogVmin.GetValue();
			value.ToDouble(&vmin);
			if(vmin>=vmax)
			{
				wxMessageDialog errorDialog(NULL, wxString("Wrong Value-SimpleJoint will be created with default values") ,wxMessageBoxCaptionStr,wxOK|wxCENTRE,wxDefaultPosition);
				errorDialog.ShowModal();
				vmin=-PI;
				vmax=PI;
			}
	}
	wxSingleChoiceDialog myDialog2(NULL,wxString("Select Axis"),wxString("Options"),AxisOptions);
	if (myDialog2.ShowModal()==wxID_OK )
	{
		if(myDialog2.GetStringSelection()==wxString("X_AXIS")) axis=1;
		if(myDialog2.GetStringSelection()==wxString("Y_AXIS")) axis=2;
		else axis=3;
	}

	if (axis==1) createdJoint=new SimpleJoint(vmax,vmin,true,0,X_AXIS,prismatic);
	else if(axis==2) createdJoint=new SimpleJoint(vmax,vmin,true,0,Y_AXIS,prismatic);
	else createdJoint=new SimpleJoint(vmax,vmin,true,0,Z_AXIS,prismatic);

	return createdJoint;
}
示例#5
0
int		main(int argc, char **argv)
{
  if (argc < 3)
    {
      printf("Usage: ./104systemes and requiered arguments.\n");
      exit(EXIT_FAILURE);
    }
  else
    {
      if (argv[1][0] == '1')
	option1(argv);
      if (argv[1][0] == '2')
	option2(argv);
      if (argv[1][0] == '3')
	option3(argv);
      if (argv[1][0] == '4')
	option4(argv);
    }
  return (0);
}
示例#6
0
int 	main(int ac, char **av)
{
	if (ac == 9)
	{
	  if (debuter(av) != 1)
		{		printf("argument  non valide\n");
			exit(-1);
		}
		if (atoi(av[1]) == 1)
			option1(atoi(av[2]),atoi(av[3]),atoi(av[4]),atoi(av[5]),atoi(av[6]),atoi(av[7]),atoi(av[8]));

		if (atoi(av[1]) == 2)
			option2(atoi(av[2]),atoi(av[3]),atoi(av[4]),atoi(av[5]),atoi(av[6]),atoi(av[7]),atoi(av[8]));
		if (atoi(av[1]) == 3)
			option3(atoi(av[2]),atoi(av[3]),atoi(av[4]),atoi(av[5]),atoi(av[6]),atoi(av[7]),atoi(av[8]));
	}
	else
	{
		printf("Arguments invalides \n");
	}
	return(0);

}
示例#7
0
文件: lab52_menu.c 项目: DANGBI/labs
int main()
{
    int i = get_option();  
    while (i < 1 || i > 5)
    {
        printf("You have entered an invalid input character.  Please try again.\n\n");
        i = get_option();
    } 
     
    if (i == 1)
        option1();
    else if (i == 2)
        option2(); 
    else if (i == 3)
        option3();
    else if (i == 4)
        option4();
    else if (i == 5)
        exit(1);
           
//system("pause");
return 0;
}
示例#8
0
    void Display::_displayResults(const QString& word)
    {
        _checkThesaurus();

        QString title;
        vector<QString> words;

        int meaning, prev_meaning = -1;
        for(const char* r = d_thesaurus.next(meaning); r[0]; r = d_thesaurus.next(meaning))
        {
            if (meaning != prev_meaning)
            {
                if (prev_meaning != -1)
                {
                    _createMeaning(title, words);
                    words.clear();
                }

                prev_meaning = meaning;

                QString option1(r);
                QString option2(d_thesaurus.next(meaning));
                title = (option1.lower() != word.lower()) ? (option1) : (option2);

                r = d_thesaurus.next(meaning);
                _checkThesaurus();
            }

            words.push_back(r);
        }

        _createMeaning(title, words);

        d_layout_ptr->addStretch();
        d_layout_ptr->activate();
    }
示例#9
0
void CMDInterpreter::interpret(char* inputToken, int& menuoption, Coordinate& coord, int){
	////////////////// Parse input //////////////////
	
	int collected = 0;
	int length = strlen(inputToken);
	
	if (length == 4) {
		if (inputToken[0] == option0() || inputToken[0] == option1() || inputToken[0] == option2()) {
			collected += 2;
			menuoption = (int)(inputToken[0]) - 48;
		} else {
			throw CMDInterpreter::GeneralException("Invalid menu option. Try again punk.\n");
		}
	}
	
	if (length == 2) {
		int tempX = (int)(tolower(inputToken[0])) - 97;
		int tempY = (int)(inputToken[1]) - 48;
		
		if (tempX < coordXa() || tempX > coordXi()) {
			throw CMDInterpreter::GeneralException("Invalid X coordinate: out of bounds. "
												   "Try again punk.\n");
		} else {
			if (tempY < coordY0() || tempY > coordY8()) {
				throw CMDInterpreter::GeneralException("Invalid Y coordinate: out of bounds. "
													   "Try again punk.\n");
			} else {
				collected += 2;
				coord.setX(tempX);
				coord.setY(tempY);
			}
		}
	}
	//remove preceeding chars in input, do interpret again
	strcpy(inputToken, &(inputToken[collected]));
}
示例#10
0
bool gol::RendererSFML::menu()
{
    m_seedChoice = 0;

    float fontSize = 20.f;
    sf::Vector2f textPosition = sf::Vector2f(20.f, 20.f);

    sf::Text title("CONWAY'S GAME OF LIFE", m_golbalFont, fontSize + 30.f);
    title.setColor(sf::Color::Green);
    title.setPosition(sf::Vector2f(textPosition.x, textPosition.y));

    sf::Text options("SELECT YOUR CHOICE :-", m_golbalFont, fontSize + 10.f);
    options.setColor(sf::Color::Red);
    options.setPosition(sf::Vector2f(textPosition.x, textPosition.y + 70.f));

    sf::Text option1("1.   Blinker Seed", m_golbalFont, fontSize);
    option1.setColor(sf::Color::White);
    option1.setPosition(sf::Vector2f(textPosition.x, textPosition.y + 120.f));

    sf::Text option2("2.   Toad Seed", m_golbalFont, fontSize);
    option2.setColor(sf::Color::White);
    option2.setPosition(sf::Vector2f(textPosition.x, textPosition.y + 145.f));

    sf::Text option3("3.   Beacon Seed", m_golbalFont, fontSize);
    option3.setColor(sf::Color::White);
    option3.setPosition(sf::Vector2f(textPosition.x, textPosition.y + 170.f));

    sf::Text option4("4.   Pulsar Seed", m_golbalFont, fontSize);
    option4.setColor(sf::Color::White);
    option4.setPosition(sf::Vector2f(textPosition.x, textPosition.y + 195.f));

    sf::Text option5("5.   Glider Seed", m_golbalFont, fontSize);
    option5.setColor(sf::Color::White);
    option5.setPosition(sf::Vector2f(textPosition.x, textPosition.y + 220.f));

    sf::Text option6("6.   Lightweight spaceship (LWSS) Seed", m_golbalFont, fontSize);
    option6.setColor(sf::Color::White);
    option6.setPosition(sf::Vector2f(textPosition.x, textPosition.y + 245.f));

    sf::Text option7("7.   Gosper Glider Gun Seed", m_golbalFont, fontSize);
    option7.setColor(sf::Color::White);
    option7.setPosition(sf::Vector2f(textPosition.x, textPosition.y + 270.f));

    sf::Text option8("8.   R-pentomino Seed", m_golbalFont, fontSize);
    option8.setColor(sf::Color::White);
    option8.setPosition(sf::Vector2f(textPosition.x, textPosition.y + 295.f));

    sf::Text option9("9.   Diehard Seed", m_golbalFont, fontSize);
    option9.setColor(sf::Color::White);
    option9.setPosition(sf::Vector2f(textPosition.x, textPosition.y + 325.f));

    sf::Text option10("10. Acorn Seed", m_golbalFont, fontSize);
    option10.setColor(sf::Color::White);
    option10.setPosition(sf::Vector2f(textPosition.x, textPosition.y + 350.f));

    sf::Text option11("11. SPECIFY YOUR OWN SEED", m_golbalFont, fontSize);
    option11.setColor(sf::Color::White);
    option11.setPosition(sf::Vector2f(textPosition.x, textPosition.y + 375.f));

    sf::Text option12("12. EXIT", m_golbalFont, fontSize);
    option12.setColor(sf::Color::White);
    option12.setPosition(sf::Vector2f(textPosition.x, textPosition.y + 400.f));

    sf::Text choiceLabel("YOUR CHOICE : ", m_golbalFont, fontSize);
    choiceLabel.setColor(sf::Color::White);
    choiceLabel.setPosition(sf::Vector2f(textPosition.x, textPosition.y + 455.f));

    sf::Text choiceText("", m_golbalFont, fontSize);
    choiceText.setColor(sf::Color::Cyan);
    choiceText.setPosition(sf::Vector2f(textPosition.x + 170.f, textPosition.y + 455.f));
    sf::String choiceString;

    sf::Text userSeedLabel("ENTER THE SEED FILE NAME : ", m_golbalFont, fontSize);
    userSeedLabel.setColor(sf::Color::Green);
    userSeedLabel.setPosition(sf::Vector2f(textPosition.x, textPosition.y + 500.f));

    sf::Text userSeedText("", m_golbalFont, fontSize);
    userSeedText.setColor(sf::Color::Cyan);
    userSeedText.setPosition(sf::Vector2f(textPosition.x + 320.f, textPosition.y + 500.f));

    sf::String userSeedString;
    std::string customSeedFile;

    bool isInMainMenu = true;

    while(m_window.isOpen())
    {
        sf::Event event;

        while(m_window.pollEvent(event))
        {
            if(event.type == sf::Event::Closed)
            {
                m_window.close();
                return false;
            }

            if(event.type ==  sf::Event::KeyPressed && event.key.code == sf::Keyboard::Return)
            {
                if(m_seedChoice != 0)
                {
                    if(m_seedChoice == 12)
                        return false;

                    else if(m_seedChoice == 11)
                        isInMainMenu = false;

                    else if(m_seedChoice < 11)
                        return true;
                }
            }

            if(event.type == sf::Event::TextEntered && isInMainMenu)
            {
                if(event.text.unicode >= 48 && event.text.unicode <= 57)
                    choiceString += (char)event.text.unicode;
                else if(event.text.unicode == 8 && choiceString.getSize() > 0)
                    choiceString.erase(choiceString.getSize() - 1, choiceString.getSize());

                choiceText.setString(choiceString);
                std::string str = choiceString.toAnsiString();
                m_seedChoice = std::atoi(str.c_str());
            }

            if(m_seedChoice == 11 && !isInMainMenu)
            {
                if(event.type == sf::Event::TextEntered)
                {
                    if((event.text.unicode >= 32  && event.text.unicode <= 57)
                            || (event.text.unicode >= 64  && event.text.unicode <= 126))

                        userSeedString += (char)event.text.unicode;

                    else if(event.text.unicode == 8 && userSeedString.getSize() > 0)
                        userSeedString.erase(userSeedString.getSize() - 1, userSeedString.getSize());

                    userSeedText.setString(userSeedString);
                }

                if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Return && !userSeedString.isEmpty())
                {
                    customSeedFile = userSeedString.toAnsiString();
                    setSeedFileName(customSeedFile);

                    return true;
                }
            }
        }

        m_window.clear(sf::Color::Black);

        m_window.draw(title);
        m_window.draw(options);
        m_window.draw(option1);
        m_window.draw(option2);
        m_window.draw(option3);
        m_window.draw(option4);
        m_window.draw(option5);
        m_window.draw(option6);
        m_window.draw(option7);
        m_window.draw(option8);
        m_window.draw(option9);
        m_window.draw(option10);
        m_window.draw(option11);
        m_window.draw(option12);
        m_window.draw(choiceLabel);
        m_window.draw(choiceText);

        if(!isInMainMenu)
        {
            m_window.draw(userSeedLabel);
            m_window.draw(userSeedText);
        }

        m_window.display();
    }
}
示例#11
0
文件: WDGMF.c 项目: mdilshad/DSA
int main()
{
	struct graph *G;
	int opt1,opt2,w;
	char name,s,e;
	G=(struct graph *)create_graph(G);
	FILE *fp;
	fp=fopen("graph","r");
	for(fscanf(fp,"%c",&s);s!='$';fscanf(fp,"%c",&s))
		insert_vertex(G,s);
	for(fscanf(fp,"%c%c%d",&s,&e,&w);s!='$';fscanf(fp,"%c%c%d",&s,&e,&w))
		insert_edge(G,s,e,w);
	fclose(fp);
	do
	{
		printf("\n\n\tEnter the option : \n\t1. for Insert Vertex\n\t2. for Delete Vertex\n\t3. for insert Edge\n\t");
		printf("4. for Delete Edge\n\t5. for Fix the Graph\n\t6. for Exit\n\t\t\t: "); 
		scanf("%d",&opt1);
		switch(opt1)
		{
			case 1:
				printf("\n\tEnter the name : ");
				getchar();
				scanf("%c",&name);
				if(!find_vertex(G,name))
				{
					insert_vertex(G,name);
					printf("\tVertex Inserted Successfully\n\n");
				}
				else
					printf("\tVertex is already Exist\n\n");
				break;
			case 2:	
				printf("Enter the vertex for Delete :\t");
				getchar();
				scanf("%c",&name);
				if(find_vertex(G,name))
				{
					vertex_delete(G,name);
					printf("\tVertex Deleted Successfully\n\n");
				}
				else
					printf("\tVertex not Exist\n\n");
				break;
			case 3:	
				printf("\n\tEnter the start point of edge :\t");
				getchar();
				scanf("%c",&s);
				printf("\n\tEnter the end point of edge :\t");
				getchar();
				scanf("%c",&e);
				printf("\n\tEnter the Weight of Edge :\t");
				scanf("%d",&w);
				if(!find_edge(G,s,e))
				{
					if(insert_edge(G,s,e,w))
						printf("\tEdge Inserted Successfully\n\n");
					else
						printf("\tSuch Vertices not Exist\n\n");
				}
				else
					printf("\tEdge is already Exist\n\n");
				break;
			case 4:	
				printf("\n\tEnter the start point of edge :\t");
				getchar();
				scanf("%c",&s);
				printf("\n\tEnter the end point of edge :\t");
				getchar();
				scanf("%c",&e);
				if(find_edge(G,s,e))
				{
					edge_delete(G,s,e);
					printf("\tEdge Deleted Successfully\n\n"); 
				}
				else
					printf("\tEdge Not Exist\n\n"); 
				break;
			case 5:
				if(G->count>0)
				{
					do
					{
						printf("\n\n\n\tEnter the option for DIRECTED GRAPH : \n\t1. for Matrix Representation\n\t2. for List Representation\n\t3. for Topological Sort Order\n\t4. for Bellman Ford Algorithm for shortest path\n\t5. for Dijkestra Algorithm for shortest path \n\t6. for Vertex Details \n\t7. for Edit Graph\n\t8. for Exit\n\t\t\t: "); 
						scanf("%d",&opt2);
						option1(G,opt2);
					}while(opt2-7);
				}
				else
					printf("\n\tNo vertex exist\n\n");
				break;
			case 6:	
				free_graph(G);
				break;
			default:printf(" wrong input \n");
		}
	}while(opt1-6);	
}