Example #1
0
int main(void)
{
	FILE *fin, *fout;
	fin = fopen("gift1.in", "r");
	fout = fopen("gift1.out", "w");

	int NP;
	fscanf(fin, "%d", &NP);

	int i;
	struct Person *p = NULL;
	struct Person *hp = NULL;
	char name[15];
	for(i = 0; i < NP; i++)
	{	
		fscanf(fin, "%s", name);

		if(p == NULL)
		{
			hp = p = create_person(name); 
		}else {
			p->n = create_person(name);
			p = p->n;
		}		
	}


	for(i = 0; i < NP; i++)
	{
		int b, f; 
		fscanf(fin, "%s %d %d", name, &b, &f);
		p = find_person(hp, name);
		if(b && f)p->balance += -1 * f * (b / f);

		int j;
		for(j = 0; j < f && b; j++)
		{
			fscanf(fin, "%s", name);
			p = find_person(hp, name);
			p->balance += b / f;
		}
	}

	p = hp;
	while(p)
	{
		fprintf(fout, "%s %d\n",p->name,  p->balance);
		hp = p;
		p = p->n;
		free(hp);
	}
	fclose(fin);
	fclose(fout);	

	return 0;
}
//create new person after "oldperson"
person * create_person_after(person* oldperson, int age, int gender, char look, char name[], int x, int y){
		person * newperson;
		newperson=create_person(age,gender,look,name,x,y);
		newperson->next=oldperson->next;
		oldperson->next=newperson;
		return newperson;
}
Example #3
0
int main(){
	person_t *person = create_person();
	printPersonDetails(person);

	printf("\nSize of person: %d bytes\n", (int)sizeof(*person));
	printf("Size of pointer to person: %d bytes\n", (int)sizeof(person));

	return 0;
}
int main (void)
{
    struct node *list = NULL, *n;

    list = create_person (1, "Dave Neary");

    n = create_person (2, "Thomas Perl");
    add_person (list, n);

    n = create_person (3, "Alison Chaiken");
    add_person (list, n);
    
    n = create_person (4, "Andrea Grandi");
    add_person (list, n);
    
    n = create_person (5, "Kevin Ottens");
    add_person (list, n);
    
    for (n=list; n; ) {
        struct node *next = n->next;
        if (n->p->id % 2 == 0) {
            delete_person(n);
        }
        n = next;
    }
    n = create_person (6, "Bob Spencer");
    add_person (list, n);
    
    write_list (list);

    return EXIT_SUCCESS;
}
/*
 * Handles the update of an individual.
 */
Person& PersonDetector::handle_update(const PosePtr pose, const CloudPtr cloud) {
	// First, we need to find the person actually associated with the cloud, if any.
	boost::optional<Person&> victim = classify_message(pose->pose, *cloud);

	// If we don't find a person, we need to create a new person.
	if(!victim.is_initialized())
		return create_person(pose->pose, *cloud);
	else {
		victim->push_pose(pose->pose);
		return victim.get();
	}

}
Example #6
0
int main(){
	person_t person = create_person();
	printPersonDetails(person);
	return 0;
}
Example #7
0
/* This main function does a little testing
   Like all good CS Majors you should test
   your code here. There is no substitute for testing
   and you should be sure to test for all edge cases
   e.g., calling remove_front on an empty list.
*/
int main(void)
{
	/* Now to make use of all of this stuff */
	list* llist = create_list();

  /* What does an empty list contain?  Lets use our handy traversal function */
  printf("TEST CASE 1\nAn Empty list should print nothing here:\n");
  traverse(llist, print_person);
	printf("\n");

 	/* Lets add a person from front and then print */
 	push_front(llist, create_person("Andrew", 24));
 	printf("TEST CASE 2\nA List with one person should print that person:\n");
 	traverse(llist, print_person);
 	printf("\n");

  
  /* Lets remove two persons from front and then print */
  remove_front(llist, free_person); // remove a list with more than 1 elements
 	remove_front(llist, free_person); // remove a list with only 1 element
 	printf("TEST CASE 3\nAnother Empty list should print nothing here:\n");
 	traverse(llist, print_person);
 	printf("\n");

 	/* Lets add two people and then print */
 	push_front(llist, create_person("Nick", 22));
 	push_front(llist, create_person("Randal", 21));
 	printf("TEST CASE 4\nA List with two people should print those two people:\n");
 	traverse(llist, print_person);
 	printf("\n");

	/* Lets copy this list */
	list* llist2 = copy_list(llist, copy_person);
	printf("TEST CASE 5\nA copied list should print out the same two people:\n");
 	traverse(llist2, print_person);
 	printf("\n");

  /* Lets kill the list */
  empty_list(llist, free_person);
 	printf("TEST CASE 6\nAfter freeing all nodes the list should be empty:\n");
 	traverse(llist, print_person);
	printf("\n");

	/* Let's make a list of people, and remove certain ones! */
	/* Should remove anyone whose name is 8+ characters long */
	push_front(llist, create_person("Josephine", 27));
	push_front(llist, create_person("Dave", 34));
	push_front(llist, create_person("Benjamin", 23));
	push_front(llist, create_person("Lisa", 41));
	push_front(llist, create_person("Maximilian", 24));
	remove_if(llist, long_name, free_person);
	printf("TEST CASE 7\nShould only print 2 people with short names:\n");
	traverse(llist, print_person);
  printf("\n");
  
  /* Testing over clean up*/
  empty_list(llist, free_person);
  free(llist);
  empty_list(llist2, free_person);
  free(llist2);


  // MY TESTS!!!

  // Test case 8 -- create_list(); is_empty() and size() when the list is empty
  list* myList = create_list();
  printf("TEST CASE 8\nShould print 1 and then 0:\n");
  printf("%d\t", is_empty(myList));
  printf("%d\n", size(myList));
  printf("\n");

  // Test case 9 -- front() and back() when the list is empty
  printf("TEST CASE 9\nShould print nothing:\n");
  print_person(front(myList));
  print_person(back(myList));
  printf("\n");

  // Test case 10 -- push_front() and push_back() and traverse()
  push_front(myList, create_person("Dan", 24));
  push_back(myList, create_person("Sun", 24));
  push_front(myList, create_person("Someone", 100));
  push_back(myList, create_person("Somebody", 1));
  printf("TEST CASE 10\nShould print 4 people in the order of Someone-Dan-Sun-Somebody:\n");
  traverse(myList, print_person);
  printf("\n");

  // Test case 11 -- size() and is_empty() when the list is not empty
  printf("TEST CASE 11\nShould return 0 and then 4:\n");
  printf("%d\t", is_empty(myList));
  printf("%d\n", size(myList));
  printf("\n");

  // Test case 12 -- front() and back() when the list is not empty
  printf("TEST CASE 12\nShould print Someone then Somebody:\n");
  print_person(front(myList));
  print_person(back(myList));
  printf("\n");

  // Test case 13 -- copy_list()
  list* myListCopy = copy_list(myList, copy_person);
  printf("TEST CASE 13\nA copied list should print 4 people in the order of Someone-Dan-Sun-Somebody:\n");
  traverse(myListCopy, print_person);
  printf("\n");

  // Test case 14 -- remove_front() and remove_back() when the list is not empty
  remove_front(myList, free_person);
  remove_back(myList, free_person);
  printf("TEST CASE 13\nShould print 2 people in the order of Dan-Sun:\n");
  traverse(myList, print_person);
  printf("\n");

  // Test case 15 -- remove_if()
  push_front(myList, create_person("LLLLLLLLLLLLL", 1));
  push_front(myList, create_person("MMMMMMMMM", 1));
  push_front(myList, create_person("AAA", 3));
  push_back(myList, create_person("DDD", 5));
  push_back(myList, create_person("T", 10));
  push_back(myList, create_person("VVVVVVVVVV", 1));
  remove_if(myList, long_name, free_person);
  printf("TEST CASE 13\nShould print 5 people:\n");
  traverse(myList, print_person);
  printf("\n");

  // Test case 16 -- empty_list()
  empty_list(myList, free_person);
  printf("TEST CASE 16\nShould print nothing:\n");
  traverse(myList, print_person);
  printf("\n");

  // Test case 17 -- remove_front() and remove_back() when the list is empty
  remove_front(myList, free_person);
  remove_back(myList, free_person);
  printf("TEST CASE 17\nNo error should occur: \n");
  printf("\n");

  // Test case 18 -- push big data into the copied list to test push_front() and copy_list()
  for (int i = 0; i < 1000000; i++) {
    push_front(myListCopy, create_person("BIG", 1));
  }
  printf("TEST CASE 18\nShould print 1000004 (add a large number of data): \n");
  printf("%d\n", size(myListCopy));
  printf("\n");

  empty_list(myList, free_person);
  free(myList);

  empty_list(myListCopy, free_person);
  free(myListCopy);

  return 0;
}
Example #8
0
// Make a deep copy of a Person
void* copy_person(const void* data)
{
    Person *p = (Person*) data;
    return create_person(p->name, p->age);
}
Example #9
0
/* This main function does a little testing. Like all good CS Majors, you should
 * test your code here. There is no substitute for testing and you should be
 * sure to test for all edge cases, like calling empty_deque on an empty deque.
 */
int main(void) {

	    printf("\n\n**SYDNEY'S TEST CASES**");

    printf("\nTEST CASE 01: PUSHING BACK\n");
    printf("Creating deque...\n");
    deque* abcd = create_deque();

    struct person* abbie = create_person("Abbie", 20);
    struct person* brian = create_person("Brian", 27);
    struct person* charlie = create_person("Charlie", 36);
    struct person* daniel = create_person("Daniel", 15);

    // end result of adding should look like this:
    // (abbie) -> (brian) -> (charlie) -> (daniel)
    push_back(abcd, abbie);
    assert(abcd->size == 1);
    assert(front(abcd) == abbie);
    assert(back(abcd) == abbie);
    traverse(abcd, print_person);
    assert(get(abcd, 0) == abbie);
    printf("Successfully added Abbie, 20 \n\n");
    // (abbie)
    push_back(abcd, brian);
    assert(abcd->size == 2);
    assert(front(abcd) == abbie);
    assert(back(abcd) == brian);
    traverse(abcd, print_person);
    assert(get(abcd, 0) == abbie);
    assert(get(abcd, 1) == brian);
    printf("Successfully added Brian, 27 \n\n");
    // (abbie) -> (brian)
    push_back(abcd, charlie); // push on back Charlie
    assert(abcd->size == 3);
    assert(front(abcd) == abbie);
    assert(back(abcd) == charlie);
    traverse(abcd, print_person);
    assert(get(abcd, 0) == abbie);
    assert(get(abcd, 1) == brian);
    assert(get(abcd, 2) == charlie);
    printf("Successfully added Charlie, 36 \n\n");
    // (abbie) -> (brian) -> (charlie)
    push_back(abcd, daniel); // push on back Daniel
    assert(abcd->size == 4);
    assert(front(abcd) == abbie);
    assert(back(abcd) == daniel);
    traverse(abcd, print_person);
    assert(get(abcd, 0) == abbie);
    assert(get(abcd, 1) == brian);
    assert(get(abcd, 2) == charlie);
    assert(get(abcd, 3) == daniel);
    printf("Successfully added Daniel, 15 \n\n");
    // (abbie) -> (brian) -> (charlie) -> (daniel)
    printf("Everyone added successfully!\n");

    printf("Emptying deque...\n");
    empty_deque(abcd, free_person);
    assert(abcd != NULL);
    assert(abcd->size == 0);
    assert(front(abcd) == NULL);
    assert(back(abcd) == NULL);


    printf("\n\nTEST CASE 02: PUSHING FRONT\n");

    abbie = create_person("Abbie", 20);
    brian = create_person("Brian", 27);
    charlie = create_person("Charlie", 36);
    daniel = create_person("Daniel", 15);

    push_front(abcd, daniel);
    assert(abcd->size == 1);
    assert(front(abcd) == daniel);
    assert(back(abcd) == daniel);
    traverse(abcd, print_person);
    assert(get(abcd, 0) == daniel);
    printf("Successfully added Daniel, 15 \n\n");
    // (daniel)
    push_front(abcd, charlie);
    assert(abcd->size == 2);
    assert(front(abcd) == charlie);
    assert(back(abcd) == daniel);
    traverse(abcd, print_person);
    assert(get(abcd, 0) == charlie);
    assert(get(abcd, 1) == daniel);
    printf("Successfully added Charlie, 36 \n\n");
    // (charlie) -> (daniel)
    push_front(abcd, brian);
    assert(abcd->size == 3);
    assert(front(abcd) == brian);
    assert(back(abcd) == daniel);
    traverse(abcd, print_person);
    assert(get(abcd, 0) == brian);
    assert(get(abcd, 1) == charlie);
    assert(get(abcd, 2) == daniel);
    printf("Successfully added Brian, 27 \n\n");
    // (brian) -> (charlie) -> (daniel)
    push_front(abcd, abbie);
    assert(abcd->size == 4);
    assert(front(abcd) == abbie);
    assert(back(abcd) == daniel);
    traverse(abcd, print_person);
    assert(get(abcd, 0) == abbie);
    assert(get(abcd, 1) == brian);
    assert(get(abcd, 2) == charlie);
    assert(get(abcd, 3) == daniel);
    printf("Successfully added Abby, 20 \n\n");
    // (abbie) -> (brian) -> (charlie) -> (daniel)
    printf("Everyone added successfully!\n");

    printf("\n\nTEST CASE 3: REMOVE IF\n");
    printf("This should check if a node being removed is:\n");
    printf("  1) a head only\n");
    printf("  2) a tail only\n");
    printf("  3) both a head and tail\n");
    printf("  4) neither a head nor tail\n\n");

    printf("Initial config:\n");
    traverse(abcd, print_person);
    printf("\n");

    remove_if(abcd, is_age_15, free_person); // should remove Daniel
    assert(front(abcd) == abbie);
    assert(back(abcd) == charlie);
    assert(abcd->size == 3);
    assert(front(abcd) == abbie);
    assert(back(abcd) == charlie);
    traverse(abcd, print_person);
    assert(get(abcd, 0) == abbie);
    assert(get(abcd, 1) == brian);
    assert(get(abcd, 2) == charlie);
    printf("Removed person who is tail only successfully.\n\n");
    // (abbie) -> (brian) -> (charlie)
    remove_if(abcd, is_age_20, free_person); // should remove Abbie
    assert(front(abcd) == brian);
    assert(back(abcd) == charlie);
    assert(abcd->size == 2);
    traverse(abcd, print_person);
    assert(get(abcd, 0) == brian);
    assert(get(abcd, 1) == charlie);
    printf("Removed person who is head only successfully.\n\n");
    // (brian) -> (charlie)
    remove_if(abcd, is_age_27, free_person); // removes Brian to test a different edge case
    // (charlie)
    remove_if(abcd, is_age_36, free_person); // should Remove Charlie
    assert(abcd->size == 0);
    assert(front(abcd) == NULL);
    assert(back(abcd) == NULL);
    traverse(abcd, print_person);
    // <empty>
    printf("Removed person who is both a head and tail successfully.\n\n");
    printf("Resetting deque...\n");

    abbie = create_person("Abbie", 20);
    brian = create_person("Brian", 27);
    charlie = create_person("Charlie", 36);
    daniel = create_person("Daniel", 15);

    push_back(abcd, abbie);
    push_back(abcd, brian);
    push_back(abcd, charlie);
    push_back(abcd, daniel);
    // (abbie) -> (brian) -> (charlie) -> (daniel)
    printf("Updated config:\n");
    traverse(abcd, print_person);
    printf("\n");

    remove_if(abcd, is_age_36, free_person);
    assert(abcd->size == 3);
    traverse(abcd, print_person);
    assert(get(abcd, 0) == abbie);
    assert(get(abcd, 1) == brian);
    assert(get(abcd, 2) == daniel);
    //
    printf("Removed person that is neither a head nor tail successfully.\n");
    printf("Success!\n");

    empty_deque(abcd, free_person);
    free(abcd);

    printf("\n\nMake sure to write more test cases as well in test.c!\n"
        "Also test using valgrind. Half credit will be given to\n"
        "functions with memory leaks or memory errors.\n");

	return 0;
}
int main(){
		//printf("at the beginning of main");
		person* firstperson;
		person* personlist;
		person* current;
		int intmap[HEIGHT][WIDTH];
		int clock=0;
		int i,j;
		srand(time(NULL));

		//create firstperson
		//printf("before first creation");
		//all names will be overwritten by getname() in createperson()
		firstperson=create_person(-110,10,' ',"God", 0,0);	
		create_person_after(firstperson,0,10,'E',"Eve",2,5);
		create_person_after(firstperson,0,10,'F',"empty",4,5);
		create_person_after(firstperson,0,10,'F',"empty",4,5);
		create_person_after(firstperson,0,10,'F',"empty",4,5);
		create_person_after(firstperson,0,1,'M',"empty",4,5);
		create_person_after(firstperson,0,1,'M',"empty",4,5);
		create_person_after(firstperson,0,1,'M',"empty",4,5);


		while(clock<TIME){
				
				//initialize intmap as empty
				for(i=0;i<HEIGHT;i++){
						for(j=0;j<WIDTH;j++){
								intmap[i][j]=0;
						}
				}
				personlist=firstperson;
				while(personlist){
						intmap[personlist->y][personlist->x]+=personlist->gender;
						//printf("value of intmap is %d\n",intmap[personlist->y][personlist->x]);
						if(intmap[personlist->y][personlist->x]==11&&personlist->fertility){
								//because women are after men in the linked-list this should ensure that only womeng get pregnant.
								//if a pregnant woman has sex, her child will be born sooner... i guess that's a feature then
								personlist->pregnancy+=1;
								printf("%s just got pregnant\n",personlist->name);
						}
						printf("%s has gender %d\n",personlist->name,personlist->gender);

						personlist=personlist->next;
				}
				
		//printf("intmap for starting point is %d", intmap[2][4]);

				printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
				draw_world(firstperson,intmap);
				//printf("before time passes\n");
				time_passes(firstperson);
				//printf("after time passes\n");
				sleep(SLEEP);
				//printf("after sleep\n");
				clock++;
				if(CONTROL!=0){
						printf("there is no one left alive i'm afraid\n you...won i guess?");
						break;
				}
				
				printf("the time is %d\n",clock);
		}




		personlist=firstperson->next;
		free(firstperson);
		while(personlist){
				printf("%s with gender=%d\n",personlist->name,personlist->gender);
				free(personlist);
				personlist=personlist->next;
		}
	
		return 0;
}