Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1a. Declare/Create a structure/class called Card. Declare two variables in it: O

ID: 3736734 • Letter: 1

Question

1a. Declare/Create a structure/class called Card. Declare two variables in it: One a string (char ) called face, and the other another string called 'suit'. 1b. From the main() function, if I Instantiated/Declare a variable/object of the struct/class Card as: struct Card firstCard; Instantiated/Declare a variable/object called 'secondCard of the struct/class Card 1c. If I initialize (assign a value) the face' variable of 'firstCard' with 'Jack' as: firstCard.face "Jack": Initialize your 'face' variable of the secondCard variable/object as 'Queen' 1d. If I initialize the 'suit' variable of 'firstCard' variable/object with 'Hearts' as: firstCard.suit- "Hearts": Initialize your 'suit' variable of the secondCard variable/object with 'Spades'. le. Print 'Jack of Hearts' ('Jack and 'Hearts' from the initialized variables above). Print 'Queen of Spades' ('Queen' and 'Spades' from the initialized variables above). Print 'Jack of Spades' ("Jack and 'Spades' from the initialized variables above). Print "Queen of Hearts' ('Queen' and 'Hearts' from the initialized variables above).

Explanation / Answer

/*

This program in compiled using GCC Compiler in Dev-C++

Question no is added in bold as comment in the program for ease of understanding

*/

#include<stdio.h>

//1(a)

struct Card{

char* face;

char* suit;

};

//2(a)

void changeSuitToClubs(Card card)

{

card.suit="Clubs";

}

int main()

{

struct Card firstCard;

//1(b)

struct Card secondCard;

firstCard.face="Jack";

//1(c)

secondCard.face="Queen";

firstCard.suit="Hearts";

//1(d)

secondCard.suit="Spades";

//1(e)

printf("%s of %s ",firstCard.face, firstCard.suit);

printf("%s of %s ",secondCard.face, secondCard.suit);

/*

We will print 'face of firstCard with Suit of secondCard and vice-versa

*/

printf("%s of %s ",firstCard.face, secondCard.suit);

printf("%s of %s ",secondCard.face, firstCard.suit);

//2(b)

changeSuitToClubs(firstCard);

printf("%s ",firstCard.suit);

/* NO Suit didn't changed

because 'card' was passed by value, in this case modification in done on local copy

if we pass by reference the modification will be visible in parent() */

printf(" ");

//2(c)

printf("%s ",secondCard.suit);

changeSuitToClubs(secondCard);

printf("%s ",secondCard.suit);

/* NO Suit didn't changed

because 'card' was passed by value, in this case modification in done on local copy

if we pass by reference the modification will be visible in parent() */

}

/*

Output:

Jack of Hearts

Queen of Spades

Jack of Spades

Queen of Hearts

Hearts

Spades

Spades

*/

/*

If you have any doubt, do post in comments section.

Give it a Thumbs Up

*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote