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

Im in need of assistance adding one more field double my_grade (ex: 3.5, 4.0) Th

ID: 3815717 • Letter: I

Question

Im in need of assistance adding one more field

double my_grade (ex: 3.5, 4.0)

Then adjusting the code from 3 to 4 structure fields


#define _CRT_SECURE_NO_DEPRECATE

#include <string.h>
#include <stdio.h>
#define SIZE 20

typedef struct {
   char className[SIZE];  
   char instructor[SIZE];  
   int num_credits;
}class;

//Function Prototypes

// fills the data fields of a card instance
//returns the filled card
class FillClass();

//fills the data fields of a card instance
//by reference using a pointer to a card
void FillClassPtr(class *classptr);

//fills an array of cards
void FillClassArray(class arrayC[], int *size);


//displays one card
void DisplayClass(class anyClass);

int main()
{

   //Declare variables
   class myClass, myClass1, myClass2;
   class myClasses[SIZE];
   int cSize;
   int i;

   //Fill structures with a function
   myClass = FillClass();
   myClass1 = FillClass();

   //print using display function
   printf(" ---------Display myCard ");
   DisplayClass(myClass);
   printf(" ---------Display myCard1 ");
   DisplayClass(myClass1);

   //Fill structure using pointers and dispay it
   FillClassPtr(&myClass2);
   printf(" ---------Display myCard2 ");
   DisplayClass(myClass2);

   //Fill the array with the function
   printf(" ---------Fill array manyCards ");
   FillClassArray(myClasses, &cSize);

   //display an array of cards
   printf(" ---------Display array manyCards ");
   for (i = 0; i<cSize; i++)
   {
       DisplayClass(myClasses[i]);
   }

   return 0;
}

//Function Definitions


// fills the data fields of a card instance
//returns the filled card
class FillClass()
{
   //Declare local variables
   class tempC;
   //prompt and get information
   printf(" please enter the face of your card: ");
   scanf("%s", tempC.className);
   //print to check
   printf("face: %s ", tempC.className);

   //prompt and get information
   printf(" please enter the suit of your card: ");
   scanf("%s", tempC.instructor);
   //print to check
   printf("suit: %s ", tempC.instructor);

   //prompt and get information
   printf(" please enter the point value of your card: ");
   scanf("%d", &tempC.num_credits);
   printf("point value: %d ", tempC.num_credits);
   return tempC;
}

//displays one card
void DisplayClass(class anyCard)
{
   printf(" face: %s ", anyCard.className);
   printf("suit: %s ", anyCard.instructor);
   printf("point value: %d ", anyCard.num_credits);
}


//fills the data fields of a card instance
//by reference using a pointer to a card
void FillClassPtr(class *cardptr)
{
   //prompt and get information
   printf(" please enter the face of your card: ");
   scanf("%s", (*cardptr).className);

   //prompt and get information
   printf(" please enter the suit of your card: ");
   scanf("%s", cardptr->instructor);

   //prompt and get information
   printf(" please enter the point value of your card: ");
   scanf("%d", &(*cardptr).num_credits);
}


//fills an array of cards
void FillClassArray(class arrayC[], int *size)
{
   int i;
   //prompt the user
   printf(" enter the number of cards: ");
   scanf("%d", size);

   //print to check
   printf("size: %d ", *size);

   for (i = 0; i < *size; i++)
   {
       printf("enter face: ");
       scanf("%s", arrayC[i].className);

       printf("enter suit: ");
       scanf("%s", arrayC[i].instructor);

       printf("enter point value: ");
       scanf("%d", &arrayC[i].num_credits);
   }
}

/*please enter the face of your card: king
face: king

please enter the suit of your card: spade
suit: spade

please enter the point value of your card: 10
point value: 10

please enter the face of your card: three
face: three

please enter the suit of your card: heart
suit: heart

please enter the point value of your card: 3
point value: 3

---------Display myCard


face: king
suit: spade
point value: 10

---------Display myCard1


face: three
suit: heart
point value: 3

please enter the face of your card: king

please enter the suit of your card: diamonds

please enter the point value of your card: 10

---------Display myCard2


face: king
suit: diamonds
point value: 10

---------Fill array manyCards

enter the number of cards: 3
size: 3
enter face: jack
enter suit: clubs
enter point value: 10
enter face: four
enter suit: hearts
enter point value: 4
enter face: ace
enter suit: spades
enter point value: 11

---------Display array manyCards


face: jack
suit: clubs
point value: 10


face: four
suit: hearts
point value: 4


face: ace
suit: spades
point value: 11
Press any key to continue . . .*/

Explanation / Answer

I have added my_grade in struct as well as related methods, as no further inofrmation was provided about my grade, it will be read from terminal.

#define _CRT_SECURE_NO_DEPRECATE
#include <string.h>
#include <stdio.h>
#define SIZE 20
typedef struct {
char className[SIZE];
char instructor[SIZE];
int num_credits;
double my_grade;
}class;
//Function Prototypes
// fills the data fields of a card instance
//returns the filled card
class FillClass();
//fills the data fields of a card instance
//by reference using a pointer to a card
void FillClassPtr(class *classptr);
//fills an array of cards
void FillClassArray(class arrayC[], int *size);

//displays one card
void DisplayClass(class anyClass);
int main()
{
//Declare variables
class myClass, myClass1, myClass2;
class myClasses[SIZE];
int cSize;
int i;
//Fill structures with a function
myClass = FillClass();
myClass1 = FillClass();
//print using display function
printf(" ---------Display myCard ");
DisplayClass(myClass);
printf(" ---------Display myCard1 ");
DisplayClass(myClass1);
//Fill structure using pointers and dispay it
FillClassPtr(&myClass2);
printf(" ---------Display myCard2 ");
DisplayClass(myClass2);
//Fill the array with the function
printf(" ---------Fill array manyCards ");
FillClassArray(myClasses, &cSize);
//display an array of cards
printf(" ---------Display array manyCards ");
for (i = 0; i<cSize; i++)
{
DisplayClass(myClasses[i]);
}
return 0;
}
//Function Definitions

// fills the data fields of a card instance
//returns the filled card
class FillClass()
{
//Declare local variables
class tempC;
//prompt and get information
printf(" please enter the face of your card: ");
scanf("%s", tempC.className);
//print to check
printf("face: %s ", tempC.className);
//prompt and get information
printf(" please enter the suit of your card: ");
scanf("%s", tempC.instructor);
//print to check
printf("suit: %s ", tempC.instructor);
//prompt and get information
printf(" please enter the point value of your card: ");
scanf("%d", &tempC.num_credits);
printf("point value: %d ", tempC.num_credits);
//prompt and get information
printf(" please enter the grade value of your card: ");
scanf("%lf", &tempC.my_grade);
printf("grade value: %f ", tempC.my_grade);
return tempC;
}

//displays one card
void DisplayClass(class anyCard)
{
printf(" face: %s ", anyCard.className);
printf("suit: %s ", anyCard.instructor);
printf("point value: %d ", anyCard.num_credits);
printf("grade value: %f ", anyCard.my_grade);
}

//fills the data fields of a card instance
//by reference using a pointer to a card
void FillClassPtr(class *cardptr)
{
//prompt and get information
printf(" please enter the face of your card: ");
scanf("%s", (*cardptr).className);
//prompt and get information
printf(" please enter the suit of your card: ");
scanf("%s", cardptr->instructor);
//prompt and get information
printf(" please enter the point value of your card: ");
scanf("%d", &(*cardptr).num_credits);
//prompt and get information
printf(" please enter the grade value of your card: ");
scanf("%lf", &(*cardptr).my_grade);
}

//fills an array of cards
void FillClassArray(class arrayC[], int *size)
{
int i;
//prompt the user
printf(" enter the number of cards: ");
scanf("%d", size);
//print to check
printf("size: %d ", *size);
for (i = 0; i < *size; i++)
{
printf("enter face: ");
scanf("%s", arrayC[i].className);
printf("enter suit: ");
scanf("%s", arrayC[i].instructor);
printf("enter point value: ");
scanf("%d", &arrayC[i].num_credits);
printf("enter grade value: ");
scanf("%lf", &arrayC[i].my_grade);
}
}