int main(int argc, char *argv[]) { // make two people, createPerson returns a Person* struct Person *joe = createPerson("Joe", 26, 70, 189); struct Person *susan = createPerson("Susan", 28, 66, 115); // %p is used to print pointers (memory location) printf("Joe is at memory location: %p\n", joe); printPerson(joe); printf("Susan is at memory location: %p\n", susan); printPerson(susan); // age everyone 10 years joe->age += 10; joe->height -= 1; joe->weight += 10; susan->age += 10; susan->height -= 2; susan->weight += 5; printPerson(joe); printPerson(susan); // call this method to clean up memory. no delete? destroyPerson(joe); destroyPerson(susan); return 0; }
Graph* buildTrustGraph(int forum, Graph* g) { Graph * trustGraph = createGraph(M,C); char buffer[200]; Node * n; FILE * fp = fopen("forum_hasMember_person.csv","r"); if (fp == NULL) { perror ("Error opening file"); exit(-1); } fgets(buffer,200,fp); while(fgets(buffer,200,fp)!= NULL) //insert users of the forum { if (forum == atoi(strtok (buffer,"|"))) { n = createPerson(atoi(strtok (NULL,"|")),NULL); insertNode(n,trustGraph); } } fclose(fp); Graph * PostGraph = createPostForum("forum_containerOf_post.csv","post_hasCreator_person.csv",forum); //creating posts hash_map Graph * CommentGraph = CreateComments("comment_replyOf_post.csv","comment_hasCreator_person.csv",PostGraph); insertLikes("person_likes_post.csv", PostGraph, trustGraph,g); insertComments("comment_replyOf_post.csv", CommentGraph, PostGraph, trustGraph, g); addTrust(trustGraph,g); freePCGraph(PostGraph); freePCGraph(CommentGraph); return trustGraph; }
void CreditsScreen::setupCredits() { const int personNum = 4; const int titleNum = 3; CCLabelTTF* title1 = 0; CCLabelTTF* title2 = 0; CCLabelTTF* title3 = 0; CCSprite* person1 = 0; CCSprite* person21 = 0; CCSprite* person22 = 0; CCSprite* person3 = 0; title1 = createTitle("PROGRAMMING"); person1 = createPerson("STANISLAV KOROTAEV", "https://twitter.com/TheBrenor", "https://www.facebook.com/stanislav.korotaev"); title2 = createTitle("MUSIC"); person21 = createPerson("MATTHEW PABLO ", "https://twitter.com/matthewpablo", "https://www.facebook.com/pages/Matthew-Pablo/33998389696"); person22 = createPerson("LANE BECKSTROM", "https://twitter.com/lanebeckstrom", "https://www.facebook.com/lane.beckstrom"); title3 = createTitle("BACKGROUNDS"); person3 = createPerson("RAWDANITSU"); const float totalHeight = title1->getContentSize().height * titleNum + person1->getContentSize().height * personNum + PADDING_AFTER_TITLE * (personNum - 1) + PADDING_AFTER_PERSON * (titleNum - 1); title1->setPositionY(totalHeight / 2 - title1->getContentSize().height / 2); person1->setPositionY(title1->getPositionY() - title1->getContentSize().height - PADDING_AFTER_TITLE); title2->setPositionY(person1->getPositionY() - person1->getContentSize().height - PADDING_AFTER_PERSON); person21->setPositionY(title2->getPositionY() - title2->getContentSize().height - PADDING_AFTER_TITLE); person22->setPositionY(person21->getPositionY() - person21->getContentSize().height - PADDING_AFTER_TITLE); title3->setPositionY(person22->getPositionY() - person22->getContentSize().height - PADDING_AFTER_PERSON); person3->setPositionY(title3->getPositionY() - title3->getContentSize().height - PADDING_AFTER_TITLE); addChild(title1); addChild(title2); addChild(title3); addChild(person1); addChild(person21); addChild(person22); addChild(person3); }
int main() { struct Person *joe = createPerson("Joe Alex", 32, 64, 140); struct Person *jack = createPerson("Jack Blank", 20, 72, 180); printf("Joe is at memory location %p\n", joe); printPerson(joe); printf("Jack is at memory location %p\n", jack); printPerson(jack); //printPerson(NULL); //Make everyone age 20 years. joe->Age += 20; joe->Height -=2; joe->Weight +=40; jack->Age += 20; jack->Weight += 20; printPerson(joe); printPerson(jack); struct Person j = *joe; struct Person j2 = j; printf("Joe is at memory location %p\n", &j); j.Age += 3; printf("Joe is %i years old\n", j.Age); printf("Joe is at memory location %p\n", &j2); printf("Joe is %i years old\n", j2.Age); destroyPerson(joe); destroyPerson(jack); //destroyPerson(NULL); return 0; }
int main(int argc, char *argv[]) { printf("Threaded Ticket Seller - Project 3\n"); // Garbage seller is used to hold persons that // have been processed by the other sellers // we have to wait on possible frustrated users // threads have cleared or they may crash when their // data is freed garbage = createSeller(HIGH, 11); // finish creation of the concert hall hall.isSoldOut = FALSE; hall.hasStarted = FALSE; hall.lock = (pthread_mutex_t *) malloc(sizeof(pthread_mutex_t)); pthread_mutex_init(hall.lock,NULL); pthread_mutex_init(&outputLock,NULL); if (argc == 2) { if (argv[1][0] == 'T') { // do self test printf("Self Test\n"); mkTest(); printf("Self test succeeded\n"); exit(0); } int N = atoi(argv[1]); printf("Run with %d customers per ticket seller\n", N); //Create Sellers Seller *allSellers[NUM_SELLERS]; allSellers[0] = createSeller(HIGH, 0); int i; for (i = 1; i < 4; i++) { allSellers[i] = createSeller(MEDIUM, i); } for(i = 1; i < 7; i++){ allSellers[i+3] = createSeller(LOW, i + 3); } //declare person pointer Person *p; int sellerNum; //create thread when adding person to the Seller que pthread_t personThreadId[NUM_SELLERS*N]; //create thread for putting people into concert hall pthread_t sellerThreadId[NUM_SELLERS]; pthread_t timerTID; pthread_create(&timerTID,NULL,&timer,NULL); for (sellerNum = 0; sellerNum < NUM_SELLERS; sellerNum++) { pthread_create(&sellerThreadId[sellerNum], NULL, &sellTickets, (void *) allSellers[sellerNum]); for(i = 0; i < N; i++) { p = createPerson(allSellers[sellerNum]); //p->arrival = 0; pthread_create(&personThreadId[sellerNum*N+i], NULL, &addPerson, (void *) p); } } closeDoorsIn60Minutes(); waitForSellersToFinish(allSellers,NUM_SELLERS); } else { printf("Usage:\n"); printf("threadSeller [T|number]\n"); printf(" T - run self test without any threading\n"); printf(" number - number of customers per ticket seller\n"); printf(" full threaded simulation\n"); } printf("Exiting threadSeller\n"); return 0; }
void mkTest() { printf(" Seller\n"); srand(0); Seller *s; s = createSeller(HIGH, 1); assert(checkT(s->price==HIGH,"Seller is HIGH")); assert(checkT(s->que==NULL,"Seller starts with empty que")); assert(checkN(s->lastRow,1,"HIGH seller starts in row 1")); free(s); s = createSeller(MEDIUM, 1); assert(checkN(s->lastRow,5,"MEDIUM seller starts in row 5")); free(s); s = createSeller(LOW, 1); assert(checkN(s->lastRow,10,"LOW seller starts in row 10")); printf(" Person\n"); Person *p = createPerson(s); assert(checkN(p->arrival,43,"p->arrival")); assert(checkT(s==p->seller,"checkT")); assert(checkT((p->next==p->prev) && (p->prev==p),"p is self referential")); // add person to seller // we need 4 people to test que management // for our testing set arrival to 0 and do not thread printf(" Add Person\n"); int i; for(i=0; i<4;i++) { p=createPerson(s); p->arrival = 0; addPerson(p); } assert(checkN(s->que->id,1,"First customer id")); assert(checkN(s->que->next->id,2,"Second customer id")); assert(checkN(s->que->next->next->id,3,"Third customer id")); assert(checkN(s->que->next->next->next->id,4,"Fourth/Last customer id")); assert(checkN(s->que->next->next->next->next->id,4,"Fifth customer id (tail points to self")); assert(checkT(s->que->inQ==TRUE,"First customer id")); assert(checkT(s->que->next->inQ==TRUE,"Second customer id")); assert(checkT(s->que->next->next->inQ==TRUE,"Third customer id")); assert(checkT(s->que->next->next->next->inQ==TRUE,"Fourth/Last customer id")); printf(" Remove Person\n"); // test removals p = removePerson(s->que);// remove person 1 assert(checkN(p->id,1,"First person on que removed")); assert(checkN(s->que->id,2,"First person on que now number 2")); p = removePerson(s->que->next); // remove person 3 assert(checkN(p->id,3,"Second(middle) person on que removed")); assert(checkN(s->que->id,2,"First person on que now number 2")); assert(checkN(s->que->next->id,4,"Second person should now be #4")); p = removePerson(s->que->next); // remove person 4 assert(checkN(p->id,4,"Second(tail) person on que removed")); assert(checkN(s->que->id,2,"First person on que now number 2")); assert(checkN(s->que->id,s->que->next->id,"Only one person left on que #2")); assert(checkT((p->next==p->prev) && (p->prev==p),"p(2) is self referential")); p = removePerson(s->que);// remove person 2 (single person left) assert(checkN(p->id,2,"Last person on que removed")); assert(checkT(s->que==NULL,"Seller que now empty")); p = removePerson(s->que);// remove person from empty que assert(checkT(p==NULL,"NULL pointer expected")); // printf(" getSeat()\n"); p=createPerson(s); // current low price seller p->id = 42; // check if row full algorithm even works assert(checkT(!isRowFull(&hall,8),"Is row 8 full NO")); printf(" LOW\n"); getSeat(&hall,p,LOW); // first call to low assigns 10,10 Person *cp = hall.seats[10][10]; assert(checkT(cp!=NULL,"Seat 10,10 occupied")); assert(checkN(cp->id,42,"Customer 42 has the seat")); printf(" HIGH\n"); p->seller->lastRow=1; getSeat(&hall,p,HIGH); // first call to low assigns 1,1 cp = hall.seats[1][1]; assert(checkT(cp!=NULL,"Seat 1,1 occupied")); assert(checkN(cp->id,42,"Customer 42 has the seat")); printf(" MEDIUM\n"); p->seller->lastRow=5; getSeat(&hall,p,MEDIUM); // first call to low assigns 5,10 cp = hall.seats[5][10]; assert(checkT(cp!=NULL,"Seat 5,10 occupied")); assert(checkN(cp->id,42,"Customer 42 has the seat")); p->seller->lastRow=3; getSeat(&hall,p,MEDIUM); // first call to low assigns 3,10 cp = hall.seats[3][10]; assert(checkT(cp!=NULL,"Seat 3,10 occupied")); assert(checkN(cp->id,42,"Customer 42 has the seat")); p->seller->lastRow=6; getSeat(&hall,p,MEDIUM); // first call to low assigns 6,1 cp = hall.seats[6][1]; assert(checkT(cp!=NULL,"Seat 6,1 occupied")); assert(checkN(cp->id,42,"Customer 42 has the seat")); // need non-threaded test for sellTickets method // non-threaded test for frustratedPerson() printf(" frustratedPerson()\n"); s = createSeller(HIGH,103); p=createPerson(s); p->arrival=0; addPerson(p); frustratedPerson(p); assert(checkT(s->que==NULL,"Person has left the building")); }
int main (int argc, char* argv[]) { FILE *input,*output; char option; char *s_input, *s_output; int NUM_THREADS=0,rc; if (argc<2){ puts("ARGUMENT MISSING"); return 0; } else { while((option = getopt(argc,argv,"i:o:t:")) != -1){ switch(option){ case 'i': s_input = optarg; break; case 'o': s_output = optarg; break; case 't': NUM_THREADS=atoi(optarg); break; default : exit(0); } } pthread_t threads[NUM_THREADS]; input = fopen(s_input, "r"); output = fopen(s_output, "w"); if (input == NULL){ puts("O ARQUIVO NAO FOI ABERTO"); return 0; } else { //starts to read the input file int a,i,j,y, number, instances; number = 0; fscanf(input, "%d", &instances); PersonList* menList=createPersonList(); PersonList* womenList=createPersonList(); PrefList* menCrushes; PrefList* womenCrushes; Person* men; Person* women; //Reading instances for (a=1; a <= instances; a++) { fscanf(input, "%d", &number); //Creating men preference list for (i=1; i <= number; i++) { menCrushes = createPrefList(); for (j=0; j < number; j++) { fscanf(input, "%d", &y); insertPref(menCrushes,y ); } men=createPerson(i,menCrushes); insertPersonInList(menList, men); } //creating women preference list for (i=1; i <= number; i++) { womenCrushes = createPrefList(); for (j=0; j < number; j++) { fscanf(input, "%d", &y); insertPref(womenCrushes,y ); } women=createPerson(i,womenCrushes); insertPersonInList(womenList, women); } //Stable Marriage Problem -> print in output file SMP(menList, womenList, number); dumpPersonListStatusToOutput(menList, output); //Satisfaction -> print in output file writeOutputSatisfaction(menList, womenList,number, output, NUM_THREADS); for(i=0; i < number; i++){ clear(menList->list_); clear(womenList->list_); } } //Liberar memoria: fclose(input); fclose(output); } } return 0; }
int main(void) { int result; person * person1; person * person2; person * person3 = NULL; /*Start createPerson Test*/ printf("\nTesting createPerson function...\n"); person1 = createPerson(); printf("person1 pointer value: %p\n", &person1); person2 = createPerson(); printf("person2 pointer value: %p\n", &person2); if(&person1 != &person2) { printf("Success! pointers are referencing different mem locations. EXPECTED\n\n"); } else { printf("Fail... pointers are referencing same mem location.\n\n"); } /*End createPerson Test*/ /*Start destroyPerson Test*/ printf("Testing destroyPerson function...\n"); destroyPerson(person1); person1 = NULL; printf("person1 deleted... ptr value: %p\n", &person1); printf("trying to delete again...\n"); destroyPerson(person1); printf("NOTE: must set the pointer to NULL after using destroyPerson, or program will crash due to invalid pointer\n\n"); /*End destroyPerson Test*/ /*Start printPerson Test*/ printf("Testing printPerson function...\n"); printf("printing the destroyed person1...\n"); printPerson(person1); printf("printing the valid person2...\n"); printPerson(person2); printf("\n"); /*End printPerson Test*/ /*Start changeInfo Test*/ printf("Testing changeInfo function...\n") ; printf("Attempting to changeInfo on destroyed person1...\n"); if(changeInfo(person1, "Justin","Fuerth",25)) { printf("Error! person1 is NULL\n"); } else { printf("Successfully changed info... something went wrong...\n"); } printf("Attempting to changeInfo on valid person2...\n"); if(changeInfo(person2, "Justin","Fuerth",25)) { printf("Error! person2 is NULL... that's not right\n"); } else { printf("Successfully changed info for person2!\n"); } printf("Printing person2 again...\n"); printPerson(person2); printf("\n"); /*End changeInfo Test*/ /*recreating person1 for further testing purposes*/ printf("Creating person1 again and giving it values: Stephen, Fuerth, 62\n\n"); person1 = createPerson(); changeInfo(person1, "Stephen", "Fuerth", 62); /*Start equalTo Test*/ printf("Testing the equalTo function...\n"); printf("Testing equalTo with NULL pointer person3...\n"); if((result = equalTo(person3,person3))>-1) { if(result == 0) { printf("the two people are different!\n"); } else { printf("the two people are equal!\n"); } } else { printf("There was an error with the equalTo function. EXPECTED\n"); } printf("Testing equalTo with one NULL and one valid...\n"); if((result = equalTo(person1,person3))>-1) { if(result == 0) { printf("the two people are different!\n"); } else { printf("the two people are equal!\n"); } } else { printf("There was an error with the equalTo function. EXPECTED\n"); } printf("Testing equalTo function with two valid, different people...\n"); if((result = equalTo(person1,person2))>-1) { if(result == 0) { printf("the two people are different! EXPECTED\n"); } else { printf("the two people are equal!\n"); } } else { printf("There was an error with the equalTo function.\n"); } printf("Testing equalTo function with two valid, equal people...\n"); if((result = equalTo(person1,person1))>-1) { if(result == 0) { printf("the two people are different!\n"); } else { printf("the two people are equal! EXPECTED\n"); } } else { printf("There was an error with the equalTo function.\n"); } printf("\n"); /*End equalTo Test*/ /*Start copyInfo Test*/ printf("Testing copyInfo function...\n"); printf("Attempting to copy into a NULL pointer...\n"); if(copyInfo(person1,person3)) { printf("there was an error with the copyInfo function... EXPECTED\n"); } printf("Attempting to copy from a NULL pointer...\n"); if(copyInfo(person3,person1)) { printf("there was an error with the copyInfo function... EXPECTED\n"); } /*creating an empty person3 to copy info into*/ person3 = createPerson(); printf("Attempting to copy from valid person1 to valid person3...\n"); if(copyInfo(person1,person3)) { printf("there was an error with the copyInfo function...\n"); } else { printf("SUCCESS! EXPECTED\n"); } printf("Printing person3... expected: Stephen Fuerth, 62\n"); printPerson(person3); /*End copyInfo Test*/ /*freeing all memory to check memleaks with valgrind*/ destroyPerson(person1); destroyPerson(person2); destroyPerson(person3); /*Aug 26 8:53 - valgrind shows no memory leaks*/ printf("\n"); return 0; }