void compHistogram_rms(const TH1* histogram, double xRef, int firstBin, int lastBin,  double& rms, double& rmsErr)
{
  //std::cout << "<makeGraph_response_asymmetric>:" << std::endl;
  
  rms = 0.;
  rmsErr = 0.;
  
  const TAxis* xAxis = histogram->GetXaxis();

  double dx2Sum = 0.;
  double dx4Sum = 0.;
  double N_effective = 0.;

  for ( int iBin = firstBin; iBin < lastBin; ++iBin ) {
    double binContent = histogram->GetBinContent(iBin);
    double binError = histogram->GetBinError(iBin);
    if ( !(binError > 0.) ) continue;
    
    double binCenter = xAxis->GetBinCenter(iBin);

    double n_effective = square(binContent/binError);

    dx2Sum += n_effective*square(binCenter - xRef);
    dx4Sum += n_effective*fourth(binCenter - xRef);

    N_effective += n_effective;
  }

  if ( N_effective > 0. ) {
    rms = TMath::Sqrt(dx2Sum/N_effective);
    rmsErr = (1./(4.*square(rms)*N_effective))*(dx4Sum/N_effective - fourth(rms));
  }
}
Example #2
0
int main ()
{
  //using the connstructors in order 
  //iterating through the lists
  std::list<int> first;                                // empty list of ints
  std::list<int> second (4,100);                       // (4,50) 4, four ints with value 50
  std::list<int> third (second.begin(),second.end());  // iterating through second
  std::list<int> fourth (third);                       // fourth int is a copy of third

  // the iterator constructors:
  int myints[] = {16,20,40,19};
  int *it;// declaring algorithm
  std::list<int> fifth (myints, myints + sizeof(myints) / sizeof(int) );

  std::cout << "The contents of fifth are: ";
  for (std::list<int>::iterator it = fifth.begin(); it != fifth.end(); it++)
    std::cout << *it << ' ';

  std::cout << '\n';
  
  //using algorithm find
  
  it = std::find (myints, myints+6, 20);
  if (it != myints+6)
    std::cout << "Element found in myints: " << *it << '\n';
  else
    std::cout << "Element not found in myints\n";

  return 0;
}
Example #3
0
void instrn()
{
 s=18;sp=6;
 w9=w8=w4=w6=w5=w2=w3=w7=w0=wk=we=wf=wj=wl=wp=wr=ws=s/2;//1/2
 w1=wi=s/4;
 wg=wc=wh=wn=wb=wu=wt=wv=wx=wy=2*s/3;//2/3
 ww=wm=wa=wd=wo=wq=wz=3*s/4;//3/4
 h=s;//1

 xnxt=-190;ynxt=320;
 how();
////////////////

 s=18;sp=6;
 w9=w8=w4=w6=w5=w2=w3=w7=w0=wk=we=wf=wj=wl=wp=wr=ws=s/2;//1/2
 w1=wi=s/4;
 wg=wc=wh=wn=wb=wu=wt=wv=wx=wy=2*s/3;//2/3
 ww=wm=wa=wd=wo=wq=wz=3*s/4;//3/4
 h=s;//1
 
 xnxt=-190;ynxt-=4*s;
 first();

 xnxt=-190;ynxt-=2*s;
 second();

 xnxt=-190;ynxt-=2*s;
 third();

 xnxt=-190;ynxt-=2*s;
 fourth();

}
Example #4
0
int main ()
{
  std::set<int> first;                           // empty set of ints

  int myints[]= {10,20,30,40,50};
  std::set<int> second (myints,myints+5);        // range
  //find and delete
  std::set<int>::iterator it;
  it = second.find (50);
  second.erase (it);
  
  //insert
  second.insert(1);
  

  std::set<int> third (second);                  // a copy of second

  std::set<int> fourth (second.begin(), second.end());  // iterator ctor.

  bool(*fn_pt)(int,int) = fncomp;
  std::set<int,bool(*)(int,int)> sixth (fn_pt);  // function pointer as Compare
	  
  std::set<int,classcomp> fifth(myints,myints+5);                 // class as Compare
  std::set<int,classcomp>::iterator iter = fifth.begin();
  while(iter != fifth.end())
  {
	  std::cout<<*iter<<std::endl;
	  iter++;
  }

  return 0;
}
Example #5
0
// (config <id> <value> <persist>
Item *config(List *expression)
{
    Item *value_item = third(expression);
    if (value_item) {
	    uint8_t item = eval_as_uint8(second(expression));
        uint8_t value = eval_as_uint8(value_item);
		uint8_t permanent = eval_as_uint8(fourth(expression));
		
		if (item < NUM_BOOLCONFIG) { // bool
			set_bool_value(&bit_config, item, value);
	    	if (permanent) {
	        	uint8_t stored_config = eeprom_read_byte(CONFIG_START_ADDR);
	       	 	set_bool_value(&stored_config, item, value);
	        	eeprom_update_byte(CONFIG_START_ADDR, stored_config);
	    	}
		} else {
			item -= NUM_BOOLCONFIG;
			if (item < NUM_BYTECONFIG) { // byte
				byte_config[item] = value;
				if (permanent) {
		        	eeprom_update_byte(BYTE_CONFIG_START_ADDR, value);
				}
			}
		}
    }
    return 0;
}
    void ListExample::ExampleConstructor(void)
    {
        // constructors used in the same order as described above:
        list<int> first;                                // empty list of ints
                                                        // khởi tạo một danh sách trống
        cout << "The contents of first are: ";
        PrintListInt(first);

        list<int> second (4,100);                       // four ints with value 100
                                                        // khởi tạo 4 số int với giá trị 100
        cout << "The contents of second are: ";
        PrintListInt(second);

        list<int> third (second.begin(),second.end());  // iterating through second
                                                        // khởi tạo từ một danh sách khác
        cout << "The contents of third are: ";
        PrintListInt(third);

        list<int> fourth (third);                       // a copy of third
                                                        // sao chép danh sách thứ 3
        cout << "The contents of fourth are: ";
        PrintListInt(fourth);

        // the iterator constructor can also be used to construct from arrays:
        // sử dụng con trỏ khởi tạo từ một mảng có sẵn
        int myints[] = {16,2,77,29};
        list<int> fifth (myints, myints + sizeof(myints) / sizeof(int) );
        cout << "The contents of fifth are: ";
        PrintListInt(fifth);
    }
Example #7
0
int main ()
{
  //!NOTE: should work perfectly now.
  ExampleOfUsingClassComp();

  // empty set that can contain ints
  std::set<int> first;

  int myints[]= {40,50,10,30,20};
  std::set<int> second (myints,myints+5);
  // This should be printed in order; set has an internal
  // comparator that 'looks' and 'works' like those given above.
  //!NOTE: We replace the for loop below with 'PrintSetContents'
  // for(std::set<int>::const_iterator cit = second.begin();
  //     cit != second.end(); cit++)
  //   std::cout << (*cit) << " ";
  // std::cout << std::endl;
  PrintSetContents(second.begin(), second.end());

  // a copy of second
  std::set<int> third (second);

  // Constructor that takes iterators
  std::set<int> fourth (second.begin(), second.end());

  // class/struct as Compare object
  std::set<int,classcomp<int> > fifth;

  // function pointer as Compare method
  bool(*fn_pt)(int,int) = fncomp;
  std::set<int,bool(*)(int,int)> sixth (second.begin(),
                                        second.end(), fn_pt);
  // Should print elements reversed
  for(std::set<int,bool(*)(int,int)>::iterator it = sixth.begin();
      it != sixth.end(); it++)
    std::cout << (*it)  << " ";
  std::cout << std::endl;

  char str[] = "For... He's a Jolly Good Fellow!.."
               "For He's a Jolly Good Fellow!..."
               "And so say all of us, and so say all of us."
               "I WISH TO WISH THE WISH YOU WISH TO WISH,"
               "BUT IF YOU WISH THE WISH THE WITCH WISHES, "
               "I WON'T WISH THE WISH YOU WISH TO WISH."
               "@#^&@)*(^%$#!$#&(*#!@$#!~~`1;/.,''`)";
  std::set<char> chara(str, str + strlen(str));
  //!NOTE: We replace the for loop below with 'PrintSetContents'
  // for(std::set<char>::const_iterator cch = chara.begin();
  //     cch != chara.end(); cch++)
  //   std::cout << (*cch);
  // std::cout << std::endl;
  //!TODO: comment out the line below, compile & run. Note what
  //       happens.
  PrintSetContents(chara.begin(), chara.end());
  return 0;
}
Example #8
0
// (pin_mode <pinid> IN|HIGH|OUT|PWM|ADC [value])
Item *lio_pinmode(List *expression)
{
    const uint8_t pinid = eval_as_uint8(second(expression));
    pin_mode(pinid, eval_as_string(third(expression)));
    Item *value = fourth(expression);
    if (value) {
        set_pin_value(pinid, eval_as_uint16(value));
    }
    return 0;
}
void third(std::vector< std::vector<int> > &square){
    x =(x+((L*2)-1))%L;
    y =(y+1)%L;   

    if(square[x][y] != 0){
        fourth(square);
        return;
    }
    std::cout<<"3. O próximo número é colocado deslocando uma posição para cima \ne  uma posição para direita. Caso seja alcançada uma das \nbordas do quadrado, a posição é invertida."<<std::endl;
    square[x][y] = actualValue++;
    printSquare(square);
}
Example #10
0
TEST(AffineTransform, ScaleFloatSize)
{
    WebCore::AffineTransform test(6.0, 5.0, 4.0, 3.0, 2.0, 1.0);

    testValueConstruction(test);

    WebCore::FloatSize first(1.0f, 2.0f);

    test.scale(first);

    EXPECT_DOUBLE_EQ(6.0, test.a());
    EXPECT_DOUBLE_EQ(5.0, test.b());
    EXPECT_DOUBLE_EQ(8.0, test.c());
    EXPECT_DOUBLE_EQ(6.0, test.d());
    EXPECT_DOUBLE_EQ(2.0, test.e());
    EXPECT_DOUBLE_EQ(1.0, test.f());

    WebCore::FloatSize second(1.0f, 0.5f);

    test.scale(second);

    testValueConstruction(test);

    WebCore::FloatSize third(2.0f, 1.0f);

    test.scale(third);

    EXPECT_DOUBLE_EQ(12.0, test.a());
    EXPECT_DOUBLE_EQ(10.0, test.b());
    EXPECT_DOUBLE_EQ(4.0, test.c());
    EXPECT_DOUBLE_EQ(3.0, test.d());
    EXPECT_DOUBLE_EQ(2.0, test.e());
    EXPECT_DOUBLE_EQ(1.0, test.f());

    WebCore::FloatSize fourth(0.5f, 1.0f);

    test.scale(fourth);

    testValueConstruction(test);

    WebCore::FloatSize fifth(0.5f, 2.0f);

    test.scale(fifth);

    EXPECT_DOUBLE_EQ(3.0, test.a());
    EXPECT_DOUBLE_EQ(2.5, test.b());
    EXPECT_DOUBLE_EQ(8.0, test.c());
    EXPECT_DOUBLE_EQ(6.0, test.d());
    EXPECT_DOUBLE_EQ(2.0, test.e());
    EXPECT_DOUBLE_EQ(1.0, test.f());
}
//Menu algoritmos de repetiçao
void load_alg_loop_while (void)
{
	do
	{
		printf("\n\t../Loop Algorithms - While \n");
		printf("\nPlease choose one of the following options:\n");

		printf("_____________________________________________________\n\n");
		printf("1......................................................\n");
		printf("2......................................................\n");
		printf("3......................................................\n");
		printf("4......................................................\n");
		printf("5......................................................\n");
		printf("6......................................................\n");
		printf("7......................................................\n");
		printf("8.Return\n");
		printf("9.Exit\n");

		printf("_____________________________________________________\n\n");
		printf("\t\tEnter Choice: ");
		scanf("%u", &choice);

		system("clear");

		switch (choice)
		{
			case 1: first();
				break;
			case 2: second();
				break;
			case 3: third();
				break;
			case 4: fourth();
				break;
			case 5: fifth();
				break;
			case 6: sixth();
				break;
			case 7: seventh();
				break;
			case 8:load_alg_loop();
				break;
			case 9: printf("\nQuitting program!\n");
				exit(FLAG);
				break;
			default: printf("\nInvalid choice!\n");
				break;
		}
	} while (choice != 9);
}
void Stack_Practice::Test_Constructor()
{
    std::deque<int> mydeque (3,100);          // deque with 3 elements
    std::vector<int> myvector (2,200);        // vector with 2 elements

    std::stack<int> first;                    // empty stack
    std::stack<int> second (mydeque);         // stack initialized to copy of deque

    std::stack<int,std::vector<int> > third;  // empty stack using vector
    std::stack<int,std::vector<int> > fourth (myvector);

    std::cout << "size of first: " << first.size() << '\n';
    std::cout << "size of second: " << second.size() << '\n';
    std::cout << "size of third: " << third.size() << '\n';
    std::cout << "size of fourth: " << fourth.size() << '\n';
}
//Menu algoritmos sequenciais
void load_vectors (void)
{
	do
	{
		printf("\n\t../Vectors \n");
		printf("\nPlease choose one of the following options:\n");
		printf("_____________________________________________________\n\n");

		printf("1.-----------------------------------------------------\n");
		printf("2.-----------------------------------------------------\n");
		printf("3.-----------------------------------------------------\n");
		printf("4.-----------------------------------------------------\n");
		printf("5.-----------------------------------------------------\n");
		printf("6. Return\n");
		printf("7. Exit\n");

		printf("_____________________________________________________\n\n");
		printf("\t\tEnter Choice: ");
		scanf("%u", &choice);

		system("clear");

		 switch(choice)
		{
			case 1: first();
				break;
			case 2: second();
				break;
			case 3: third();
				break;
			case 4: fourth();
				break;
			case 5: fifth();
				break;
			case 6: load_menu();
				break;
			case 7: printf("\nQuitting program!\n");
				exit(FLAG);
				break;
			default: printf("\nInvalid choice!\n");
				break;
		}
	} while (choice != 11);
}
Example #14
0
int set_main ()
{
  std::set<int> first;                           // empty set of ints

  int myints[]= {10,20,30,40,50};
  std::set<int> second (myints,myints+5);        // range

  std::set<int> third (second);                  // a copy of second

  std::set<int> fourth (second.begin(), second.end());  // iterator ctor.

  std::set<int,classcomp> fifth;                 // class as Compare

  bool(*fn_pt)(int,int) = fncomp;
  std::set<int,bool(*)(int,int)> sixth (fn_pt);  // function pointer as Compare

  std::cout << "done";
  return 0;
}
Example #15
0
int main ()
{
  // constructors used in the same order as described above:
  std::vector<int> first;                                // empty vector of ints
  std::vector<int> second (4,100);                       // four ints with value 100
  std::vector<int> third (second.begin(),second.end());  // iterating through second
  std::vector<int> fourth (third);                       // a copy of third

  // the iterator constructor can also be used to construct from arrays:
  int myints[] = {16,2,77,29};
  std::vector<int> fifth (myints, myints + sizeof(myints) / sizeof(int) );

  std::cout << "The contents of fifth are:";
  for (std::vector<int>::iterator it = fifth.begin(); it != fifth.end(); ++it)
    std::cout << ' ' << *it;
  std::cout << '\n';

  return 0;
}
Example #16
0
int main ()
{
  // constructors used in the same order as described above:

  forward_list<int> first;                      // default: empty
  forward_list<int> second (3,77);              // fill: 3 seventy-sevens
  forward_list<int> third (second.begin(), second.end()); // range initialization
  forward_list<int> fourth (third);            // copy constructor
  forward_list<int> fifth (std::move(fourth));  // move ctor. (fourth wasted)
  forward_list<int> sixth = {3, 52, 25, 90};    // initializer_list constructor

  std::cout << "first:" ; for (int& x: first)  std::cout << " " << x; std::cout << '\n';
  std::cout << "second:"; for (int& x: second) std::cout << " " << x; std::cout << '\n';
  std::cout << "third:";  for (int& x: third)  std::cout << " " << x; std::cout << '\n';
  std::cout << "fourth:"; for (int& x: fourth) std::cout << " " << x; std::cout << '\n';
  std::cout << "fifth:";  for (int& x: fifth)  std::cout << " " << x; std::cout << '\n';
  std::cout << "sixth:";  for (int& x: sixth)  std::cout << " " << x; std::cout << '\n';

  return 0;
}
Example #17
0
void
AuxCalphadEnergy::computeBarrier()
{
  Real first(0);
  Real second(0);
  Real third(0);
  Real fourth(0);
  Real fifth(0);

  Real sixth;
  if(_n_OP_vars == 1)
    sixth = 0;
  else
    sixth = 1;

  for (unsigned int i=0; i<_n_OP_vars; i++)
  {
    first += std::pow((*_OP[i])[_qp], 2);
    second += std::pow((*_OP[i])[_qp], 3);
    third += std::pow((*_OP[i])[_qp], 4);

    Real square_sum(0);
    Real quad_sum(0);
    for (unsigned int j=0; j < _n_OP_vars; j++)
    {
      if (j > i)
        square_sum += std::pow((*_OP[j])[_qp], 2);

      if (j != i)
        quad_sum += std::pow((*_OP[j])[_qp], 4);
    }

    fourth +=  ( std::pow((*_OP[i])[_qp], 2) )*square_sum;
    fifth += ( std::pow((*_OP[i])[_qp], 2) )*quad_sum;

    sixth *= std::pow((*_OP[i])[_qp], 2);
  }

  _g = first - 2*second + third + fourth + fifth + sixth;
}
Example #18
0
int main ()
{
  std::map<char,int> first;

  first['a']=10;
  first['b']=30;
  first['c']=50;
  first['d']=70;

  std::map<char,int> second (first.begin(),first.end());

  std::map<char,int> third (second);

  // class as Compare
  std::map<char,int,classcomp> fourth(first.begin(),first.end());  

  //delete in for
  std::map<char,int,classcomp>::iterator iter = fourth.begin();
  while(iter != fourth.end())
  {
	if(iter->second < 50)
	{
		fourth.erase(iter++);
	}
	else
	{
		iter++;
	}
  }
  
  iter = fourth.begin();
  while(iter != fourth.end())
  {
	std::cout<<iter->first<<"\t"<<iter->second<<std::endl;
	iter++;
  }
  return 0;
}
Example #19
0
void leaf_node::initialization()
{
 vector<char> data;
 data.push_back('H');
 data.push_back('L');
 std::pair<vector<char>, std::string> first(data,"test");
 data[0]='K';
 data[1]='R';
 std::pair<vector<char>, std::string> second(data, "a");
 data[0]='L';
 data[1]='L';
 std::pair<vector<char>, std::string> third(data, "bmo");
 data[0]='M';
 data[1]='G';
 data.push_back('T');
 std::pair<vector<char>, std::string> fourth(data, "deloitte");
 this->l.push_back(first);
 this->l.push_back(second);
 this->l.push_back(third);
 this->l.push_back(fourth);
 this->next = 5;
 sort(this->l.begin(), this->l.end(), leaf_node::compare);
}
Example #20
0
/*
 *
 * Summary: 
      1. string can be consider a descendant of vectors 
         1.1 every single oper you can do with vectors you can do with strings
         1.2 important string extras, e.g.  "+" ,  c_str, find, substr, compare
 *
 *
 */
int main()
{

     // constructors used in the same order as described above:
  std::vector<int> first;                                // empty vector of ints
  std::vector<int> second (4,100);                       // four ints with value 100
  std::vector<int> third (second.begin(),second.end());  // iterating through second
  std::vector<int> fourth (third);                       // a copy of third

  // the iterator constructor can also be used to construct from arrays:
  int myints[] = {16,2,77,29};
  std::vector<int> fifth (myints, myints + sizeof(myints) / sizeof(int) );
    
    vector<int> vec = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};  // C++11
    vec.erase(vec.begin() + 3); // erase 4th element
    vec.erase(vec.begin(), vec.begin() + 3); 
    // erase from begin() to begin() + 2 but not begin()+3 
    // easier to understand thinking of vec.erase(vec.begin(), vec.end()); 
    
    for(int i = 0; i < vec.size(); i++) cout << vec[i] << " "; 
    cout << endl; 
    
    return 0; 
}
Example #21
0
extern "C" void * haloThread(void * id){
	char * HaloID = (char *)id;
	cout << "Analyzing halo with ID " << HaloID << endl;
	int numberOfParticles, nCols;
	double ** positionsArray;
	Particle ** particlesArray;
	FILE * output;
	double radius = 0;
	double u;

	FILE * positionFile = getPositionFile(HaloID);		//make the file path
	if (positionFile == NULL)
		printf("POSITION FILE NULL\n");
	numberOfParticles = getNumberOfRows(positionFile);	//count number of particles in file
	nCols = getNumberOfColumns(positionFile);			//get number of columns in file (3)
	particlesArray = new ParticleArray[numberOfParticles];	//make an array of particles
	for (int i = 0; i < numberOfParticles; i++){
		particlesArray[i] = new Particle();					//each location in the array is a particle (with positions)
	}
	positionsArray = assembleArray(positionFile,numberOfParticles,nCols);
	for (int i = 0; i<numberOfParticles;i++){
		particlesArray[i]->position.x = positionsArray[i][0];
		particlesArray[i]->position.y = positionsArray[i][1];
		particlesArray[i]->position.z = positionsArray[i][2];
		free(positionsArray[i]);
	}
	delete positionsArray;
       
	for(int i = 0; i < numberOfParticles; i++){

		for(int j = 0; j < numberOfParticles; j++){
				radius = sqrt(sq((particlesArray[i]->position.x)-(particlesArray[j]->position.x))+sq((particlesArray[i]->position.y)-(particlesArray[j]->position.y))+sq((particlesArray[i]->position.z)-(particlesArray[j]->position.z)));
				u = radius/EPSILON;
				if(u<0.5){
					particlesArray[i]->directPotential += GRAVITATIONAL_CONSTANT*PARTICLE_MASS*MASS_MULTIPLIER/EPSILON*(16.0/3.0*sq(u)-48.0/5.0*fourth(u)+32.0/5.0*fifth(u)-14.0/5.0);
				}
				else if(u<1){
					particlesArray[i]->directPotential += GRAVITATIONAL_CONSTANT*PARTICLE_MASS*MASS_MULTIPLIER/EPSILON*(1.0/(15.0*u)+32.0/3.0*sq(u)-16.0*third(u)+48.0/5.0*fourth(u)-32.0/15.0*fifth(u)-16.0/5.0);
				}
				else{
					particlesArray[i]->directPotential += GRAVITATIONAL_CONSTANT*PARTICLE_MASS*MASS_MULTIPLIER/EPSILON*(-1.0/u);
				}

		}
		if(i%100000==0){cout <<HaloID <<" - " <<i <<"th particle's potential calculated" <<endl;}
	}

	output = makeOutputFileName(HaloID);		//make output file

	//print output
	for(int i = 0; i<numberOfParticles; i++){
		fprintf(output,"%f%c\n",particlesArray[i]->directPotential,delimeter);
	}

	//free memory
	for (int i = 0; i < numberOfParticles; i++){
		delete particlesArray[i]; 
	}
	delete particlesArray;

	//close files
	fclose(positionFile);
	fclose(output);

		// Reduce our active threads count.
	pthread_mutex_lock(numberOfThreadsMutex);
	numberOfThreads--;
	pthread_mutex_unlock(numberOfThreadsMutex);
	pthread_cond_signal(threadAvailable);			// Signal to wake up main.

	cout <<"Halo " << HaloID <<" done." <<endl;

}
Example #22
0
EXPORT_SYM void third( unsigned long arg )
{
    printf( "third: 0x%x\n", arg );
    
    fourth( 0xbeeffeed );
}
Example #23
0
metacont_closure_t *mcps(OBJECT_PTR exp)
{
  if(is_atom(exp) || is_quoted_expression(exp))
  {
    metacont_closure_t *mcls = (metacont_closure_t *)GC_MALLOC(sizeof(metacont_closure_t));

    mcls->mfn             = lit_id_metacont_fn;

    mcls->nof_closed_vals = 1;
    mcls->closed_vals     = (OBJECT_PTR *)GC_MALLOC(mcls->nof_closed_vals * sizeof(OBJECT_PTR));

    mcls->closed_vals[0]  = exp;
    
    return mcls;
  }
    
  OBJECT_PTR car_exp = car(exp);
  
  if(car_exp == LAMBDA)
  {
    metacont_closure_t *mcls = (metacont_closure_t *)GC_MALLOC(sizeof(metacont_closure_t));

    mcls->mfn             = lambda_metacont_fn;

    mcls->nof_closed_vals = 2;
    mcls->closed_vals     = (OBJECT_PTR *)GC_MALLOC(mcls->nof_closed_vals * sizeof(OBJECT_PTR));

    mcls->closed_vals[0]  = second(exp);
    mcls->closed_vals[1]  = third(exp);
    
    return mcls;    
  }

  if(car_exp == LET)
  {
    metacont_closure_t *mcls = (metacont_closure_t *)GC_MALLOC(sizeof(metacont_closure_t));

    mcls->mfn             = let_metacont_fn;

    mcls->nof_closed_vals = 2;
    mcls->closed_vals     = (OBJECT_PTR *)GC_MALLOC(mcls->nof_closed_vals * sizeof(OBJECT_PTR));

    mcls->closed_vals[0]  = second(exp);
    mcls->closed_vals[1]  = third(exp);
    
    return mcls;
  }

  if(primop(car_exp))
  {
    if(car_exp == RETURN_FROM)
    {
      metacont_closure_t *mcls = (metacont_closure_t *)GC_MALLOC(sizeof(metacont_closure_t));

      mcls->mfn             = return_from_metacont_fn;

      mcls->nof_closed_vals = 1;
      mcls->closed_vals     = (OBJECT_PTR *)GC_MALLOC(mcls->nof_closed_vals * sizeof(OBJECT_PTR));

      mcls->closed_vals[0]  = exp;
    
      return mcls;      
    }
    else if(car_exp == THROW)
    {
      metacont_closure_t *mcls = (metacont_closure_t *)GC_MALLOC(sizeof(metacont_closure_t));

      mcls->mfn             = throw_metacont_fn;

      mcls->nof_closed_vals = 1;
      mcls->closed_vals     = (OBJECT_PTR *)GC_MALLOC(mcls->nof_closed_vals * sizeof(OBJECT_PTR));

      mcls->closed_vals[0]  = second(exp);
    
      return mcls;      
    }
    else if(car_exp == CALL_CC)
    {
      metacont_closure_t *mcls = (metacont_closure_t *)GC_MALLOC(sizeof(metacont_closure_t));

      mcls->mfn             = call_cc_metacont_fn;

      mcls->nof_closed_vals = 1;
      mcls->closed_vals     = (OBJECT_PTR *)GC_MALLOC(mcls->nof_closed_vals * sizeof(OBJECT_PTR));

      mcls->closed_vals[0]  = second(exp);
    
      return mcls;      
    }
    else if(car_exp == BREAK)
    {
      metacont_closure_t *mcls = (metacont_closure_t *)GC_MALLOC(sizeof(metacont_closure_t));

      mcls->mfn             = break_metacont_fn;

      mcls->nof_closed_vals = 0;
      mcls->closed_vals     = NULL;
    
      return mcls;      
    }    
    else
    {
      metacont_closure_t *mcls = (metacont_closure_t *)GC_MALLOC(sizeof(metacont_closure_t));

      mcls->mfn             = primop_metacont_fn;

      mcls->nof_closed_vals = 2;
      mcls->closed_vals     = (OBJECT_PTR *)GC_MALLOC(mcls->nof_closed_vals * sizeof(OBJECT_PTR));

      mcls->closed_vals[0]  = car_exp;  //operator
      mcls->closed_vals[1]  = cdr(exp); //operands
    
      return mcls;
    }
  }
  
  if(car_exp == IF)
  {
    metacont_closure_t *mcls = (metacont_closure_t *)GC_MALLOC(sizeof(metacont_closure_t));

    mcls->mfn             = if_metacont_fn;

    mcls->nof_closed_vals = 3;
    mcls->closed_vals     = (OBJECT_PTR *)GC_MALLOC(mcls->nof_closed_vals * sizeof(OBJECT_PTR));

    mcls->closed_vals[0]  = second(exp);
    mcls->closed_vals[1]  = third(exp);
    mcls->closed_vals[2]  = fourth(exp);
    
    return mcls;    
  }

#ifdef WIN32
  if(car_exp == ERROR1)
#else
  if(car_exp == ERROR)
#endif    
  {
    metacont_closure_t *mcls = (metacont_closure_t *)GC_MALLOC(sizeof(metacont_closure_t));

    mcls->mfn             = error_metacont_fn;

    mcls->nof_closed_vals = 1;
    mcls->closed_vals     = (OBJECT_PTR *)GC_MALLOC(mcls->nof_closed_vals * sizeof(OBJECT_PTR));

    mcls->closed_vals[0]  = second(exp);
    
    return mcls;
  }

  //it is an application
  metacont_closure_t *mcls = (metacont_closure_t *)GC_MALLOC(sizeof(metacont_closure_t));

  mcls->mfn             = app_metacont_fn;

  mcls->nof_closed_vals = 1;
  mcls->closed_vals     = (OBJECT_PTR *)GC_MALLOC(mcls->nof_closed_vals * sizeof(OBJECT_PTR));

  mcls->closed_vals[0]  = exp;
    
  return mcls;
}
//Menu algorithmos condicionais
void load_alg_conditional(void)
{
	do
	{
		printf("\n\t../Conditional Algorithms \n");
		printf("\nPlease choose one of the following options:\n");

		printf("______________________________________________________\n\n");
		printf("1.------------------------------------------------------\n");
		printf("2.------------------------------------------------------\n");
		printf("3.------------------------------------------------------\n");
		printf("4.------------------------------------------------------\n");
		printf("5.------------------------------------------------------\n");
		printf("6.------------------------------------------------------\n");
		printf("7.------------------------------------------------------\n");
		printf("8.------------------------------------------------------\n");
		printf("9.------------------------------------------------------\n");
		printf("10.-----------------------------------------------------\n");
		printf("11.-----------------------------------------------------\n");
		printf("12.Return...\n");
		printf("13.Exit\n");

		printf("_____________________________________________________\n\n");
		printf("\t\tEnter Choice: ");
		scanf("%u", &choice);

		system("clear");

		 switch(choice)
		{
			case 1: first();
				break;
			case 2: second();
				break;
			case 3: third();
				break;
			case 4: fourth();
				break;
			case 5: fifth();
				break;
			case 6: sixth();
				break;
			case 7: seventh();
				break;
			case 8: eighth();
				break;
			case 9: ninth();
				break;
			case 10: tenth();
				break;
			case 11: eleventh();
				break;
			case 12: load_menu();
				break;
			case 13: printf("\n Quitting program!\n");
				exit(FLAG);
				break;
			default: printf("\n Invalid choice!\n");
				break;
		}
	} while (choice != 8);
}
Example #25
0
int main()
{
	window A(800,600,0,0);
	A.ChangeTitle("LOBSTER");

	image up("up.jpg", JPEG);
	image down("down.jpg", JPEG);
	image right("right.jpg", JPEG);
	image left("left.jpg", JPEG);

	image prev = up; // default previous image

	direction dir = N; // default direction

	A.SetBuffering(true);
	int x=A.GetWidth()/2, y=A.GetHeight()/2;
	char k;

	int mx, my; // mouse click coords

	shot s1; // shot
	enemy e1(A); // enemy

	bool crashed = false; // if player runs into enemy
	int emc = 90; // enemy move count

// ====>	MULTIPLE BARRIER OBJECTS BELOW //
	barrier first(0,0,800,50,STEELBLUE);
	barrier second(200,500,700,510,STEELBLUE);
	barrier third(690,200,700,400,STEELBLUE);
	barrier fourth(200,200,500,210,STEELBLUE);

	A.SetFont(35,BOLD,ROMAN,NULL);
	A.SetPen(BLACK,60);
	A.DrawString(80,260,"Shoot the bomb!!");
	A.UpdateBuffer();
	A.WaitKeyPress(k);
	A.SetBrush(WHITE);
	A.SetPen(WHITE,1);
	A.DrawRectangle(0,0,800,600);
	A.DrawImage(up,x-up.GetWidth()/2,y-up.GetHeight()/2);


	while (k!=27)
	{

// ====>	MULTIPLE BARRIER OBJECTS BELOW //
		first.draw(A);
		second.draw(A);
		third.draw(A);
		fourth.draw(A);

		A.SetPen(BLACK,1);
		A.SetFont(15,BOLD,ROMAN,NULL);
		A.DrawString(10,20,"Press 'esc' to quit");
		A.SetFont(25,BOLD,ROMAN,NULL);
		A.DrawString(500,15,"Score:");
		A.DrawInteger(600,15,score);
		A.DrawString(300,15,"Level:");
		A.DrawInteger(400,15,level);


		A.SetBrush(WHITE);
		A.SetPen(WHITE);

		A.GetKeyPress(k); // get user's next action

		switch (k)
		{
		case (4): // if left
			A.DrawRectangle(x-prev.GetWidth()/2-1,y-prev.GetHeight()/2-1, 
							x+prev.GetWidth()/2+1, y+prev.GetHeight()/2+1);
			
// ====>		MULTIPLE BARRIER OBJECTS BELOW //
			if (first.inbounds(x-speed,y,left) &&
				second.inbounds(x-speed,y,left) &&
				third.inbounds(x-speed,y,left) &&
				fourth.inbounds(x-speed,y,left))
				x-=speed;
			else // moves up to the barrier exactly
			{
				if(! first.inbounds(x-speed,y,left))
					x -= ((x-right.GetWidth()/2)-first.getx2());
				if(! second.inbounds(x-speed,y,left))
					x -= ((x-right.GetWidth()/2)-second.getx2());
				if(! third.inbounds(x-speed,y,left))
					x -= ((x-right.GetWidth()/2)-third.getx2());
				if(! fourth.inbounds(x-speed,y,left))
					x -= ((x-right.GetWidth()/2)-fourth.getx2());
			}

			
			A.DrawImage(left,x-left.GetWidth()/2,y-left.GetHeight()/2);
			prev = left;
			dir = W;
			A.UpdateBuffer();
			break;
		case (6): // if right
			A.DrawRectangle(x-prev.GetWidth()/2-1,y-prev.GetHeight()/2-1,
							x+prev.GetWidth()/2+1, y+prev.GetHeight()/2+1);

// ====>		MULTIPLE BARRIER OBJECTS BELOW //
			if (first.inbounds(x+speed,y,right) &&
				second.inbounds(x+speed,y,right) &&
				third.inbounds(x+speed,y,right) && 
				fourth.inbounds(x+speed,y,right))
				x+=speed;
			else // moves up to the barrier exactly
			{
				if(! first.inbounds(x+speed,y,right))
					x += (first.getx1()-(x+right.GetWidth()/2));
				if(! second.inbounds(x+speed,y,right))
					x += (second.getx1()-(x+right.GetWidth()/2));
				if(! third.inbounds(x+speed,y,right))
					x += (third.getx1()-(x+right.GetWidth()/2));
				if(! fourth.inbounds(x+speed,y,right))
					x += (fourth.getx1()-(x+right.GetWidth()/2));
			}

			A.DrawImage(right,x-right.GetWidth()/2,y-right.GetHeight()/2);
			prev = right;
			dir = E;
			A.UpdateBuffer();
			break;
		case (8): // if up
			A.DrawRectangle(x-prev.GetWidth()/2-1,y-prev.GetHeight()/2-1,
							x+prev.GetWidth()/2+1, y+prev.GetHeight()/2+1);

// ====>		MULTIPLE BARRIER OBJECTS BELOW //
			if (first.inbounds(x,y-speed,up) &&
				second.inbounds(x,y-speed,up) &&
				third.inbounds(x,y-speed,up) &&
				fourth.inbounds(x,y-speed,up) )
				y-=speed;
			else // moves exactly to the barrier
			{
				if(! first.inbounds(x,y-speed,up))
					y -= ((y-up.GetHeight()/2)-first.gety2());
				if(! second.inbounds(x,y-speed,up))
					y -= ((y-up.GetHeight()/2)-second.gety2());
				if(! third.inbounds(x,y-speed,up))
					y -= ((y-up.GetHeight()/2)-third.gety2());
				if(! fourth.inbounds(x,y-speed,up))
					y -= ((y-up.GetHeight()/2)-fourth.gety2());
			}


			A.DrawImage(up,x-up.GetWidth()/2,y-up.GetHeight()/2);
			prev = up;
			dir = N;
			A.UpdateBuffer();
			break;
		case (2): // if down
			A.DrawRectangle(x-prev.GetWidth()/2-1,y-prev.GetHeight()/2-1,
							x+prev.GetWidth()/2+1, y+prev.GetHeight()/2+1);

// ====>		MULTIPLE BARRIER OBJECTS BELOW //
			if (first.inbounds(x,y+speed,down) &&
				second.inbounds(x,y+speed,down) &&
				third.inbounds(x,y+speed,down) &&
				fourth.inbounds(x,y+speed,down))
				y+=speed;
			else // moves up to the barrier exactly
			{
				if(! first.inbounds(x,y+speed,down))
					y += (first.gety1()-(y+down.GetHeight()/2));
				if(! second.inbounds(x,y+speed,down))
					y += (second.gety1()-(y+down.GetHeight()/2));
				if(! third.inbounds(x,y+speed,down))
					y += (third.gety1()-(y+down.GetHeight()/2));
				if(! fourth.inbounds(x,y+speed,down))
					y += (fourth.gety1()-(y+down.GetHeight()/2));
			}


			A.DrawImage(down,x-down.GetWidth()/2,y-down.GetHeight()/2);
			prev = down;
			dir = S;
			A.UpdateBuffer();
			break;
		case (' '): // if user shoots, create a shot heading in the right direction from the claws
			if (dir == 0) s1.construct(x,y-prev.GetHeight()/2-3,dir);
			if (dir == 1) s1.construct(x+prev.GetWidth()/2+3,y,dir);
			if (dir == 2) s1.construct(x,y+prev.GetHeight()/2+3,dir);
			if (dir == 3) s1.construct(x-prev.GetWidth()/2-3,y,dir);
			A.UpdateBuffer();
			A.FlushKeyQueue();
			break;
		}

// ====>	MULTIPLE BARRIER OBJECTS BELOW //
		if (emc % 90 == 0&&
			s1.inrange(A) &&
			first.inbounds(s1)  &&
			second.inbounds(s1) &&
			third.inbounds(s1) &&
			fourth.inbounds(s1) ) s1.move(A);

		crashed = false;
		// check if user is touching enemy //
		if ( ( (x-prev.GetWidth()/2 > e1.x1() && x-prev.GetWidth()/2 < e1.x2()) || 
			   (x+prev.GetWidth()/2 > e1.x1() && x+prev.GetWidth()/2 < e1.x2()) ) &&
			 ( (y-prev.GetHeight()/2 > e1.y1() && y-prev.GetHeight()/2 < e1.y2()) ||
			   (y+prev.GetHeight()/2 > e1.y1() && y+prev.GetHeight()/2 < e1.y2()) ) )
		{
			crashed = true;
		}

		if (emc%90 == 0 ) // only moves every 90 frames
			if (!e1.move(A,s1,first,second,third,fourth,crashed)) // if enemy has been killed
			{
				A.SetPen(BLACK,1);
				A.SetFont(35,BOLD,ROMAN,NULL);
				A.DrawString(180,260,"Click to continue");
				A.UpdateBuffer();
				A.FlushMouseQueue();
				A.WaitMouseClick(mx,my);
				A.SetBrush(WHITE);
				A.SetPen(WHITE,1);
				A.DrawRectangle(0,0,800,600);
				A.UpdateBuffer();
				A.FlushKeyQueue();
				s1.ismoving = false;
				if (crashed)
					score -= 237;
				else
					score += 801;
			}
		emc++;

		if (emc%27000 == 0) // score diminishes with time
			score -= 13;
		if (emc%270000 == 0 && score < 0)
		{
			A.SetPen(BLACK,1);
			A.SetFont(75,BOLD,ROMAN,NULL);
			A.DrawString(180,260,"YOU LOSE!!!");
			A.UpdateBuffer();
			break;
		}
		if (score > level * 500)
			level ++;

	}
	A.WaitMouseClick(mx,my);
	A.SetWaitClose(false);
	return 0;
}
Example #26
0
	}
	for(int i = 0; i < sizeof si / sizeof si[0]; i++) {
		std::cout <<"si[" <<i <<"] = " <<si[i] <<std::endl;
	}
	return s.print();
}

class fourth_inc {
	static const fourth scf[];
	static fourth sf[];
public:
	static int display(void);
};

const fourth fourth_inc::scf[] = {
	fourth("hello"), 
	fourth("world"), 
	fourth("!"),
};
fourth fourth_inc::sf[] = {
	fourth("this"),
	fourth("is"),
	fourth("tary"),
	fourth("speaking"),
	fourth("!"),
};

int fourth_inc::display(void) {
	for(int i = 0; i < sizeof scf / sizeof scf[0]; i++) {
		((fourth*)&scf[i])->print();
	}