Question

Complete the program below in C please #include <stdio.h> #inlcude <stdlib.h> #include <time.h> typedef struct {...

Complete the program below in C please

#include <stdio.h>

#inlcude <stdlib.h>

#include <time.h>

typedef struct

{

int points;

int strength;

} Hero;

/* print out the hero given by the parameter */

void printHero( ... )

{

.

.

}

void main()

{

Hero heroA, heroB;

/* initialize both heroes to your choice of values */

.

/* Pick one hero using rand(). Print out that hero */

.

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <stdio.h>

#include <stdlib.h>

#include <time.h>

typedef struct

{

    int points;

    int strength;

} Hero;

/* print out the hero given by the parameter */

void printHero(Hero h)

{

    printf("Points : %d\n", h.points);

    printf("Strength : %d\n", h.strength);

}

int main()

{

    Hero heroA, heroB;

   

    /* initialize both heroes to your choice of values */

    heroA.strength = 10;

    heroA.points = 5;

   

    /* Pick one hero using rand(). Print out that hero */

    heroB.strength = 9;

    heroB.points = 8;

    // generate random number in range 0 - 1

    int choice = rand() % 2;

    if( choice == 0 )

        printHero( heroA );

    else

        printHero( heroB );

    return 0;

}


Sample Output

Add a comment
Know the answer?
Add Answer to:
Complete the program below in C please #include <stdio.h> #inlcude <stdlib.h> #include <time.h> typedef struct {...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using C++ And #include <stdio.h> #include <stdlib.h> #include <time.h> a) Write a main function and declare...

    Using C++ And #include <stdio.h> #include <stdlib.h> #include <time.h> a) Write a main function and declare an array with 100 elements. b) In the main, initialize each number in the array to be a random number between 100 and 200. c) Write a function that returns the value of the smallest number in the array. Call this function from the main and print the result. d) Declare a 2D array with dimensions 2x2 and initilize the array, as follows: [1,...

  • IN C Programming #include<stdio.h> #include<stdlib.h> typedef struct nodestruct { int item; struct nodestruct *next; } Node;...

    IN C Programming #include<stdio.h> #include<stdlib.h> typedef struct nodestruct { int item; struct nodestruct *next; } Node; typedef struct { int size; // Number of items on user’s list Node *head, *tail; } List; //In addition to creating an empty list, this function will also create two dummy nodes; one for the head, and the other for the tail. List* createList(); //This function creates a node containing the provided item, then inserts it into the list pointed by the provided list...

  • Question 1 Consider the following program fragment that defines a self-referential class: #include <stdlib.h> #include <stdio.h>...

    Question 1 Consider the following program fragment that defines a self-referential class: #include <stdlib.h> #include <stdio.h> struct node_int; typedef struct node int *node; struct node_int void *data; node next; typedef struct list_int (node first;} *list; void main(int argc, char *argv[]) list shopping, t; node n; int x=25; shopping=(list) malloc(sizeof(struct list_int)); n= (node) malloc(sizeof(struct node_int)); n->data=shopping; n->next=NULL; shopping->first=n; t=(list) (shopping->first->data); // ***** t->first=NULL; // ***** n->data=&x; printf("%d\n", *((int *) (shopping->first->data))); a What will be displayed on the screen if the above...

  • #include<stdio.h> #include <stdlib.h> void read(struct Employee *e); struct Employee { int id; int age; }; int...

    #include<stdio.h> #include <stdlib.h> void read(struct Employee *e); struct Employee { int id; int age; }; int main(){ struct Employee e; read(&e); } void read(struct Employee *e){ int a,b; printf("Enter the id employee\n"); scanf("%d",&a); printf("Enter the age employee\n"); scanf("%d",&b); e->id=a; e->age=b; } Question: Declare a pointer variable of type Employee and place the address of the variable created in the above problem in that pointer variable.

  • C PROGRAMMING #include <stdio.h> #include <stdlib.h> struct nodet { int data; struct nodet *link; }; struct...

    C PROGRAMMING #include <stdio.h> #include <stdlib.h> struct nodet { int data; struct nodet *link; }; struct nodet *makeAnode(int val) { struct nodet *box; box = malloc(sizeof(struct nodet) ); box->data = val; box->link = NULL; return box; } void printList(struct nodet *L) { struct nodet = *mov; mov = L; while(mov != NULL) { printf("%d ", mov->data); mov = mov->link; } printf("\n"); } // THIS SHOULD COUNT HOW MANY ITEMS (NODES) ARE IN THE LIST. int listLen(struct nodet **L) { int...

  • Create Functions for the following prototypes. Below is the setup.*program is in c* #include <stdio.h> #include...

    Create Functions for the following prototypes. Below is the setup.*program is in c* #include <stdio.h> #include <string.h> #include <stdarg.h> #include <stdlib.h> //#define constant values #define MAX_URL_LENGTH 50 #define TRUE 1 #define FALSE 0 //typedef for the Element struct which constains a c string to store a URL in the BrowserList typedef struct { char szURL[MAX_URL_LENGTH]; } Element; //Typedef for a node in the doubly linked list (has next and previous pointers). typedef struct NodeDL { Element element; struct NodeDL *pNext;...

  • PLease explain output of these two programs: 1. #include <stdio.h> typedef struct { char *name; int...

    PLease explain output of these two programs: 1. #include <stdio.h> typedef struct { char *name; int x, y; int h, w; } box; typedef struct { unsigned int baud : 5; unsigned int div2 : 1; unsigned int use_external_clock : 1; } flags; int main(int argc, char** argv){ printf("The size of box is %d bytes\n", sizeof(box)); printf("The size of flags is %d bytes\n", sizeof(flags)); return 0; } 2. #include <stdio.h> #include <string.h> /* define simple structure */ struct { unsigned...

  • WRITE IN LANGUAGE C. THANKS Heroic Game Write a program that plays a simple game. Mostly...

    WRITE IN LANGUAGE C. THANKS Heroic Game Write a program that plays a simple game. Mostly the purpose of the program is to practice using structs. Here is a struct that contains information about a character in the game: typedef struct {   int hitPoints;    /* how much life */   int strength;     /* fighting strength */   char name[MAXNAME]; } Hero; The same structure is used for all characters (even non-heroic.) First write the function void printHero( Hero hr )that prints a...

  • C Programming #include <stdio.h> #include <stdlib.h> #include <time.h> // These defines do a text repl...

    C Programming #include <stdio.h> #include <stdlib.h> #include <time.h> // These defines do a text replacement // everytime the string 'ROWS' and 'COLUMNS' // are found in this specific source file. // You can play with these values. #define ROWS 5 #define COLUMNS 5 /* ============= Tutorial on Graph format ============ You are given a randomly generated graph that looks of the form: 0 0 1 1 1 1 0 0 1 1 0 1 0 1 1 1 0 0...

  • Fill in the missing C code according to the comments. #include <stdio.h> typedef struct {   ...

    Fill in the missing C code according to the comments. #include <stdio.h> typedef struct {    int num;    char name[25]; } student; int main(){    student s1;           //assign the value of 1234 to num in the s1 structure    //assign the value of Bob the Builder to name in s1 structure       //display the value of num in the s1 structure    //display the value of name is the s1 structure student *s2;       ...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT