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

C Programming *Notice: I can only edit the part where it says in /* Your solutio

ID: 3876254 • Letter: C

Question

C Programming

*Notice: I can only edit the part where it says in /* Your solution goes here */ the other part of the code i can't touch it please the solution should be inside that part ad using the code provided

Question 1

Define a function SetBirth, with int parameters monthVal and dayVal, that returns a struct of type BirthMonthDay. The function should assign BirthMonthDay's data member month with monthVal and day with dayVal.

#include <stdio.h>

typedef struct BirthMonthDay_struct {
int month;
int day;
} BirthMonthDay;

/* Your solution goes here */

int main(void) {
BirthMonthDay studentBirthday;
int month;
int day;

scanf("%d %d", &month, &day);
studentBirthday = SetBirth(month, day);
printf("The student was born on %d/%d. ", studentBirthday.month, studentBirthday.day);

return 0;
}

Question2

Assign Carbonara's data member caloriesPerSlice with 350 and Four Cheese's with 280.

#include <stdio.h>
#include <string.h>

typedef struct PizzaInfo_struct {
char pizzaName[30];
int caloriesPerSlice;
} PizzaInfo;

int main(void) {

PizzaInfo availablePizzas[2];

strcpy(availablePizzas[0].pizzaName, "Carbonara");
strcpy(availablePizzas[1].pizzaName, "Four Cheese");

/* Your solution goes here */

printf("A %s pizza contains %d calories ", availablePizzas[0].pizzaName, availablePizzas[0].caloriesPerSlice);
printf("A %s pizza contains %d calories ", availablePizzas[1].pizzaName, availablePizzas[1].caloriesPerSlice);

return 0;
}

Explanation / Answer

#include <stdio.h>
typedef struct BirthMonthDay_struct {
int month;
int day;
} BirthMonthDay;

// Return type is BirthMonthDay since we need to return that structure
// taking 2 parameters month and day
BirthMonthDay SetBirth(int m, int d){
  
// creating one instance of structure
BirthMonthDay temp;
  
// setting values of month and day
temp.month = m;
temp.day = d;
  
// returning structure
return temp;
}


int main(void) {
BirthMonthDay studentBirthday;
int month;
int day;
scanf("%d %d", &month, &day);
studentBirthday = SetBirth(month, day);
printf("The student was born on %d/%d. ", studentBirthday.month, studentBirthday.day);
return 0;
}

/*SAMPLE OUTPUT
3 4
The student was born on 3/4.
*/

#include <stdio.h>
#include <string.h>
typedef struct PizzaInfo_struct {
char pizzaName[30];
int caloriesPerSlice;
} PizzaInfo;
int main(void) {
PizzaInfo availablePizzas[2];
strcpy(availablePizzas[0].pizzaName, "Carbonara");
strcpy(availablePizzas[1].pizzaName, "Four Cheese");

// assigning values
availablePizzas[0].caloriesPerSlice = 350;
availablePizzas[1].caloriesPerSlice = 280;

printf("A %s pizza contains %d calories ", availablePizzas[0].pizzaName, availablePizzas[0].caloriesPerSlice);
printf("A %s pizza contains %d calories ", availablePizzas[1].pizzaName, availablePizzas[1].caloriesPerSlice);
return 0;
}

/*SAMPLE OUTPUT
A Carbonara pizza contains 350 calories
A Four Cheese pizza contains 280 calories
*/

#include <stdio.h>
typedef struct BirthMonthDay_struct {
int month;
int day;
} BirthMonthDay;

// Return type is BirthMonthDay since we need to return that structure
// taking 2 parameters month and day
BirthMonthDay SetBirth(int m, int d){
  
// creating one instance of structure
BirthMonthDay temp;
  
// setting values of month and day
temp.month = m;
temp.day = d;
  
// returning structure
return temp;
}


int main(void) {
BirthMonthDay studentBirthday;
int month;
int day;
scanf("%d %d", &month, &day);
studentBirthday = SetBirth(month, day);
printf("The student was born on %d/%d. ", studentBirthday.month, studentBirthday.day);
return 0;
}

/*SAMPLE OUTPUT
3 4
The student was born on 3/4.
*/

#include <stdio.h>
#include <string.h>
typedef struct PizzaInfo_struct {
char pizzaName[30];
int caloriesPerSlice;
} PizzaInfo;
int main(void) {
PizzaInfo availablePizzas[2];
strcpy(availablePizzas[0].pizzaName, "Carbonara");
strcpy(availablePizzas[1].pizzaName, "Four Cheese");

// assigning values
availablePizzas[0].caloriesPerSlice = 350;
availablePizzas[1].caloriesPerSlice = 280;

printf("A %s pizza contains %d calories ", availablePizzas[0].pizzaName, availablePizzas[0].caloriesPerSlice);
printf("A %s pizza contains %d calories ", availablePizzas[1].pizzaName, availablePizzas[1].caloriesPerSlice);
return 0;
}

/*SAMPLE OUTPUT
A Carbonara pizza contains 350 calories
A Four Cheese pizza contains 280 calories
*/