Ejemplo n.º 1
0
int main(int argc, char *argv[])
{
    // test out THE_AGE accessors
    log_info("My name: %s, age: %d", MY_NAME, get_age());

    set_age(100);

    log_info("My age is now: %d", get_age());

    // test out THE_SIZE extern
    log_info("THE_SIZE is: %d", THE_SIZE);
    print_size();

    THE_SIZE = 9;

    log_info("THE_SIZE is now: %d", THE_SIZE);
    print_size();

    //test the ratio function static
    log_info("Ratio at first: %f", update_ratio(2.0));
    log_info("Ratio again: %f", update_ratio(10.0));
    log_info("Ratio once more: %f", update_ratio(300.0));

    // test the scope demo
    int count = 4;
    scope_demo(count);
    scope_demo(count * 20);

    log_info("count after calling scope_demo: %d", count);

    return 0;
}
Ejemplo n.º 2
0
int main(int argc, char **argv) {
  log_info("My name is %s, age is %d", MY_NAME, get_age());

  set_age(100);

  log_info("My age is now %d", get_age());

  log_info("THE SIZE is %d", THE_SIZE);
  print_size();

  THE_SIZE = 9;

  log_info("THE SIZE is now %d", THE_SIZE);
  print_size();

  log_info("Ratio at first: %f", update_ratio(2.0));
  log_info("Ratio again: %f", update_ratio(10.0));
  log_info("Ratio once more: %f", update_ratio(300.0));

  int count = 4;
  scope_demo(count);
  scope_demo(count * 20);

  log_info("count after calling scope demo %d", count);

  return 0;
}
Ejemplo n.º 3
0
int main(int argc, const char *argv[])
{
	log_info("My name: %s, age: %d",MY_NAME,get_age());
	set_age(24);
	log_info("My age is now: %d",get_age());

	log_info("The Size is: %d",THE_SIZE);
	print_size();

	THE_SIZE=9;
	log_info("The Size is now: %d",THE_SIZE);
	print_size();

	log_info("Ratio at first: %f",update_ratio(2.0));
	log_info("Ratio again: %f",update_ratio(10.0));
	log_info("Ratio once more: %f",update_ratio(300.0));

	int count=4;
	scope_demo(count);
	scope_demo(count*20);

	log_info("Count after calling scope_demo: %d",count);
	return 0;

	return 0;
}
Ejemplo n.º 4
0
int main(int argc, char *argv[])
{
	log_info("My name: %s, age: %d", MY_NAME, get_age());

	set_age(100);

	log_info("My age is now: %d", get_age());

	log_info("THE_SIZE is; %d", THE_SIZE);
	print_size();

	THE_SIZE = 9;

	log_info("THE SIZE is now: %d", THE_SIZE);
	print_size();

	log_info("Ratio at first: %f", update_ratio(2.0));
	log_info("Ratio again: %f", update_ratio(10.0));
	log_info("Ratio once more: %f", update_ratio(300.0));

	int count = 4;
	scope_demo(count);
	scope_demo(count * 20);
	
	log_info("count after calling scope_demo: %d", count);
	
	log_info("The value of ratio is : %f", *RATIO_PTR);

	test_func();
	log_info("The value of x outside test_func is : %d", *xptr);
	scope_demo(14);
	log_info("The value of x outside test_func is : %d", *xptr);

	return 0;
}
Ejemplo n.º 5
0
/**
 * Main routine for filling funnels from weather effects.
 */
void fill_funnels( int rain_depth_mm_per_hour, bool acid, const trap &tr )
{
    const double turns_per_charge = tr.funnel_turns_per_charge( rain_depth_mm_per_hour );
    // Give each funnel on the map a chance to collect the rain.
    const auto &funnel_locs = g->m.trap_locations( tr.loadid );
    for( auto loc : funnel_locs ) {
        units::volume maxcontains = 0_ml;
        if( one_in( turns_per_charge ) ) { // FIXME:
            //add_msg("%d mm/h %d tps %.4f: fill",int(calendar::turn),rain_depth_mm_per_hour,turns_per_charge);
            // This funnel has collected some rain! Put the rain in the largest
            // container here which is either empty or contains some mixture of
            // impure water and acid.
            auto items = g->m.i_at( loc );
            auto container = items.end();
            for( auto candidate_container = items.begin(); candidate_container != items.end();
                 ++candidate_container ) {
                if( candidate_container->is_funnel_container( maxcontains ) ) {
                    container = candidate_container;
                }
            }

            if( container != items.end() ) {
                container->add_rain_to_container( acid, 1 );
                container->set_age( 0_turns );
            }
        }
    }
}
Ejemplo n.º 6
0
int
main(int argc, char *argv[]) {
    const double    value = 2.0;
    NL;
    log_info("name in ex22-main.c = %s, static int THE_AGE in ex22.c is = %d",
             MY_NAME, get_age());

    log_info("nset static int THE_AGE in ex22.c to 30:");
    set_age(30);
    log_info("static int THE_AGE in ex22.c in main() is now: %d", get_age());
    NL;
    log_info("can't directly access static int THE_AGE in ex22.c in main:");
    log_info("-> log_info(\"THE_AGE = %%d\", THE_AGE);");
    NL;
    log_info("can't directly access int THE_SIZE in ex22.c in main:");
    log_info("-> log_info(\"THE_SIZE = %%d\", THE_SIZE);");
    NL;
    log_info("can directly access int THE_EXTERN_SIZE in ex22.c in main:");
    log_info("THE_EXTERN_SIZE = %d", THE_EXTERN_SIZE);
    NL;
    log_info("update value to (double) THE_EXTERN_SIZE from %.1f",
             update_static((double) THE_EXTERN_SIZE));
    log_info("update value to const double value from %.1f", update_static(value));
    log_info("update value to 10.0 from %.1f", update_static(10.0));
    NL;

    return 0;
}
Ejemplo n.º 7
0
int main(int argc, char *argv[])
{
	log_info("my name: %s, age: %d", MY_NAME, get_age());

	set_age(100);

	log_info("my age is now: %d", get_age());

	// test ou thte SIZE_EXTERN
	log_info("THE_SIZE is: %d", THE_SIZE);
	print_size();

	log_info("Ratio at first: %f", *update_ratio(2.0));
	log_info("Ratio again: %f", *update_ratio(10));
	log_info("Ratio once more: %f", *update_ratio(300.0));

	int count = 4;
	scope_demo(count);
	scope_demo(count * 20);

	log_info("count after calling scope_demo: %d", count);

	double *static_ratio = update_ratio(0.5);
	log_info("reaching in to the static ratio: %f", *static_ratio);

	*static_ratio = .001;
	
	log_info("changed the static ration in to the static ratio: %f", *static_ratio);

	return 0;
}
Ejemplo n.º 8
0
int main()
{
	log_info("My name : %s, age: %d",MY_NAME,get_age());
	
	set_age(100);
	
	log_info("My name now is : %d",get_age());
	
	log_info("THE_SIZE is: %d", THE_SIZE);
	
	print_size();
	
	THE_SIZE = 9;

    log_info("THE SIZE is now: %d", THE_SIZE);
    print_size();
    
    log_info("Ratio at first: %f", update_ratio(2.0));
    log_info("Ratio again: %f", update_ratio(10.0));
    log_info("Ratio once more: %f", update_ratio(300.0));
    
    // test the scope demo
    int count = 4;
    scope_demo(count);
    scope_demo(count * 20);

    log_info("count after calling scope_demo: %d", count);
    
	return 0;
}
Ejemplo n.º 9
0
int main(int argc, char *argv[])
{
    log_info("my name %s, age %d", MY_NAME, get_age());

    set_age(100);

    log_info("my age is now %d", get_age());
    log_info("THE_SIZE is %d", THE_SIZE);
    print_size();

    THE_SIZE = 9;

    log_info("THE_SIZE is now %d ", THE_SIZE);
    print_size();

    log_info("ratio at first : %f", update_ratio(2.0));
    log_info("ratio now : %f", update_ratio(10.0));
    log_info("ratio finally : %f", update_ratio(300.0));

    int count = 4;
    scope_demo(count);
    scope_demo(count * 20);

    log_info("Count after calling scope_demo : %d", count);

    return 0;
}
Ejemplo n.º 10
0
/** \brief Compute vital state (satiation, energy, age) for the next cycle.

    - Mark creature as aged, if age is greater as max age.
    - Mark creature as starved, if satiation falls under half of the maximum
    satiation.
    - Mark creature as underfed, if energy level falls under half of the maximum
    energy.
*/
void
Creature::next_vital_state() {

    if (living_state == LivingState::alive()) {

        set_age(get_age() + 1);
        if (get_age() == get_max_age()) {
            living_state = LivingState::aged();
        }
        else {
            set_satiation(get_raw_satiation() - get_satiation_consumption());
            if (get_satiation() == 0) {
                living_state = LivingState::starved();
            }
            else {

                // TODO (joobog#2#): code verbessern
                double value = 2 * get_energy_consumption() *
                    ((double) get_satiation() /
                     (double) get_max_satiation() - (double) 0.5);

                if ( value < 0) {
                    set_energy(get_raw_energy() - (unsigned int) (-value));
                }
                if ( value > 0) {
                    set_energy(get_raw_energy() + (unsigned int) value);
                }

                if (get_energy() == 0) {
                    living_state = LivingState::underfed();
                }
            }
        }
    }
}
Ejemplo n.º 11
0
int main(int argc, char *argv[])
{
    // test out THE_AGE accessors
    log_info("My name: %s, age: %d", MY_NAME, get_age());

    set_age(100);

    log_info("My age is now: %d", get_age());

    int new_age = 44;
    log_info("Setting age directly to %d", new_age);
    int *age = get_age_pointer();
    *age = new_age;

    log_info("My age is now: %d", get_age());

    // test out THE_SIZE extern
    log_info("THE_SIZE is: %d", THE_SIZE);
    print_size();

    THE_SIZE = 9;

    log_info("THE_SIZE is now: %d", THE_SIZE);
    print_size();

    // test the ratio function static
    log_info("Ratio at first: %f", update_ratio(2.0));
    log_info("Ratio again: %f", update_ratio(10.0));
    log_info("Ratio once more: %f", update_ratio(300.0));

    // accessing a function static
    double *func_static_value = get_function_static(4.0);
    log_info("get_function_static(4.0) = %.1f", *func_static_value);
    double new_func_static_value = 8.0;
    log_info("Setting the function static var directly to %.1f",
            new_func_static_value);
    *func_static_value = new_func_static_value;
    log_info("get_function_static(4.0) = %.1f", *get_function_static(4.0));

    // test the scope demo
    int count = 4;
    scope_demo(count);
    scope_demo(count * 20);

    log_info("count after calling scope_demo: %d", count);

    return 0;
}
Ejemplo n.º 12
0
void Human::set_human()
{
	cout << "--------------------------------------------------\n" 
		<< "Enter name: ";
	string name;
	cin >> name;
	set_name(name);
	cout << "Last name: ";
	string last_name;
	cin >> last_name;
	set_last_name(last_name);
	cout << "Sex [1]male, [2]female: ";

	int sc;
	cin >> sc;
	if (sc == 1)
		set_sex(male);
	else if (sc == 2)
		set_sex(female);
	
	cout << "Age: ";
	int age;
	cin >> age;
	set_age(age);

	cout << "Number of favorite books: ";
	int nfavorite_books;
	cin >> nfavorite_books;
	set_nfavorite_books(nfavorite_books);
	if (nfavorite_books != 0)
	{
		string *favorite_books = new string[nfavorite_books];
		cout << "Type " << nfavorite_books << " favorite books:\n";
		for (int i = 0; i < nfavorite_books; i++)
		{
			cout << i + 1 << ". ";
			cin >> favorite_books[i];
		}
		cout << "\n";
		set_favorite_books(favorite_books);
	}
Ejemplo n.º 13
0
int main(int argc, char *argv[])
{
	// test out THE_AGE accessors
	log_info("My names: %s, age: %d", MY_NAME, get_age());

	set_age(100);

	log_info("My age is now: %d", get_age());

	// test out THE_SIZE extern
	log_info("THE_SIZE is: %d", THE_SIZE);
	print_size();

	THE_SIZE = 9;

	log_info("THE_SIZE is now: %d", THE_SIZE);
	print_size();

	// test the ration function static
	log_info("Ratio at first: %f", update_ratio(2.0));
	log_info("Ratio again: %f", update_ratio(10.0));
	log_info("Ratio once more: %f", update_ratio(300.0));

	double *res = update_ratio_ptr(2.0);
	log_info("Ratio by pointer: %f\n", *res);
	*res = 100.0;
	res = update_ratio_ptr(15.0);
	log_info("Ratio by pointer: %f\n", *res);

	// test the scope demo
	int count = 4;
	scope_demo(count);
	scope_demo(count * 20);

	log_info("count after calling scope_demo: %d", count);

	log_info("Recursive result: %llu\n", recursive(100000, 0));

	return 0;
}
Ejemplo n.º 14
0
int main(int argc, char** argv) {
        log_info("My name is %s and I am %d years old.", MY_NAME, get_age());

        set_age(100);

        log_info("Now I'm older! I'm %d.", get_age());

        log_info("The size is: %d", THE_SIZE);
        print_size();

        THE_SIZE = 9;

        log_info("The size is now: %d", THE_SIZE);
        print_size();

        // test the ratio function static
        log_info("Ratio: %f", *update_ratio(2.0));
        log_info("Ratio: %f", *update_ratio(10.0));
        log_info("Ratio: %f", *update_ratio(300.0));

        double* evil = update_ratio(1.0);

        // H4X. I grabbed a static function variable and am changing its
        // contents here.
        log_info("%f", *evil);
        *evil = 123.0;
        log_info("%f", *evil);
        update_ratio(9);

        // test the scope demo
        int count = 4;
        scope_demo(count);
        scope_demo(count * 20);

        log_info("count after calling scope_demo: %d", count);

        return 0;
}
Ejemplo n.º 15
0
  void ObjectHeader::initialize_copy(Object* other, unsigned int new_age) {
    /* Even though we dup it, we have to be careful to maintain
     * the zone. */

    // DO NOT, EVER, CHANGE obj_type_.
    // obj_type_ indicates the shape of the object in memory. There are
    // f****d up cases where this is called where other is another type
    // (that, btw, is likely a bug in itself), but we should never,
    // MUST never change obj_type_ to make them match. This causes the GC
    // to get confused about the memory shape of the object!
    assert(type_id() == other->type_id());
    set_age(new_age);
    klass_ = other->klass_;
    ivars_ = other->ivars_;

#ifdef RBX_OBJECT_ID_IN_HEADER
    set_object_id(other->object_id());
#endif

    clear_forwarded();

    if(other->is_tainted_p()) set_tainted();
  }
Ejemplo n.º 16
0
int main(int argc, char *argv[])
{
	// test out THE_AGE accessors
	log_info("My name: %s, age: %d", MY_NAME, get_age());
	set_age(200);
	log_info("My age is now: %d", get_age());
	// test out THE_SIZE extern
	log_info("THE_SIZE is: %d", THE_SIZE);
	log_info("The address of THE_SIZE is: %p", &THE_SIZE);
	print_size();

	THE_SIZE = 9;

	log_info("The SIZE is now: %d", THE_SIZE);
	print_size();

	// test the ratio function static
	log_info("Ratio at first: %f", update_ratio(2.0));
	log_info("Ratio again: %f", update_ratio(10.0));
	log_info("Ratio once more: %f", update_ratio(300.0));

	// test the scope demo
	int count = 4;
	scope_demo(count);
	scope_demo(count * 20);
/*	
	log_info("count after calling scope_demo: %d", count);
	log_info("The ratio is: %f", ratio);

	log_info("The address of THE_AGE: %p", &get_age());
	log_info("The current value of THE_AGE: %d", get_age());
	*get_age() = 0;
	log_info("After setting THE_AGE pointer to 0 THE_AGE value is: %d", THE_AGE);	
*/
	return 0;
}