Question

Given the following program: #include <stdio.h> struct student { int id; char name[20]; char grade; };...

Given the following program:

#include <stdio.h> struct student
{

int id;
char name[20]; char grade;

};
void func(struct student stud); int main()
{

struct student astud; astud.id=9401; strcpy(astud.name, "Joe"); astud.grade = 'A'; func(astud);

return 0; }

Abdelghani Bellaachia, CSCI 1121 Page: 16 void func(struct student astud)
{

printf(" Id is: %d \n", astud.id); printf(" Name is: %s \n", astud.name); printf(" Grade is: %c \n", astud.grade);

}

Modify this program to include the address of a student as a separate structure. The address should include the following:

 Address as an array of 30 characters

 City as a an array of 20 characters

 Zipcode as an integer.

in C programin language

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

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

struct addess
{
char addrs[30];
char city[30];
int zipcode;
};

struct student
{
int id;
char name[20];
char grade;
struct addess adrs;
};

void func(struct student stud);

int main()
{
struct student astud;
astud.id=9401;
strcpy(astud.name, "Joe");
astud.grade = 'A';
  
strcpy(astud.adrs.addrs, "address line");
strcpy(astud.adrs.city, "city");
astud.adrs.zipcode = 123456;
  
func(astud);
return 0;
}
//Abdelghani Bellaachia, CSCI 1121 Page: 16
void func(struct student astud)
{
printf(" Id is: %d \n", astud.id);
printf(" Name is: %s \n", astud.name);
printf(" Address is: %s \n", astud.adrs.addrs);
printf(" City is: %s \n", astud.adrs.city);
printf(" Zipcode is: %d \n", astud.adrs.zipcode);
  
}

Add a comment
Know the answer?
Add Answer to:
Given the following program: #include <stdio.h> struct student { int id; char name[20]; char grade; };...
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
  • #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.

  • #include<stdio.h> #include<stdio.h> int main(){ int i; //initialize array char array[10] = {“Smith”, “Owen”, “Kowalczyk”, “Glass”, “Bierling”,...

    #include<stdio.h> #include<stdio.h> int main(){ int i; //initialize array char array[10] = {“Smith”, “Owen”, “Kowalczyk”, “Glass”, “Bierling”, “Hanenburg”, “Rhoderick”, “Pearce”, “Raymond”, “Kamphuis”}; for(int i=0; i<8;i++){ for(int j=0; j<9; j++){ if(strcmp(array[j],array[j+1])>0){ char temp[20]; strcpy(temp,array[j]); strcpy(array[j],array[j+1]); strcpy(array[j+1],temp); } } } printf(“---------File Names---------\n”); for(inti=0; i<9; i++){ printf(“\t%s\n”,array[i]); } printf(-------5 Largest Files according to sorting----\n”); for(int i=0;i>=5;i--) { printf(“\t%s\n”,array[i]); } return0; } Consider the "sort" program (using with void* parameters in the bubblesort function) from the week 10 "sort void" lecture. Modify it as follows...

  • what is the output of the following program? #include<stdio.h> #include<string.h> int main(void){ char word[20]; int i...

    what is the output of the following program? #include<stdio.h> #include<string.h> int main(void){ char word[20]; int i =0    strcpy(word, "ORGANISE"); while(word[i] !='\0'){ if(i%2 ==1) word[i] = 'C'; i++; } printf("%s",word); return 0; }

  • 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...

  • What is going to be the output of the following program: # include <stdio.h> int main(void)...

    What is going to be the output of the following program: # include <stdio.h> int main(void) {struct dob {int month; int day; int year;}; struct student {int sid; int yearOfAdmission; float currentGPA; struct dob bday; struct student stdnt = {123, 2015, 8.3, 11, 26, 1993}; printf(" Id is: %d \n", stdnt.sid); printf("Year of admission is: %d \n", stdnt.year OfAdmission); printf("Current GPA is: %.2f\n\n", stdnt.currentGPA); printf("Date of Birth is: %d/%d/%d", stdnt. bday. month, stdnt. bday.day, stdnt. bday.} return 0;}

  • Question 1 Given the declarations: #include <stdio.h> struct STRUCTURE { int aa; char bb[20]; } enum...

    Question 1 Given the declarations: #include <stdio.h> struct STRUCTURE { int aa; char bb[20]; } enum Numbers { zero, one, two, three } typedef struct STRUCTURE STR; typedef enum Numbers NB; STR st1, st2; NB value1, value2; check the validity of the following assignments: A) Valid B) Not valid value1 = four; value2 = three; printf (“st1= %d”, st1); st2.aa = two; strcpy(st2.bb,"Quiz4");

  • Convert this C program to Js (Java script) from Visual Studio Code #include<stdio.h> int main(){ char...

    Convert this C program to Js (Java script) from Visual Studio Code #include<stdio.h> int main(){ char firstName[100]; char lastName[100]; printf("Enter Your Full Name: \n"); scanf("%s %s", firstName, lastName); printf("First Name: %s\n", firstName); printf("Last Name: %s\n", lastName); return 0; }

  • Question 6 Predict the output of the following question: 8 pts #include <stdio.h> #include<string.h> char al(5)={...

    Question 6 Predict the output of the following question: 8 pts #include <stdio.h> #include<string.h> char al(5)={ "gate", "kate","rate","date" ); void rec(char a[][5], int n){ if(n<= 1) return; char temp[5]; strcpy(temp'a);//copies the string stored in a into temp strcpy(*a,a[n-1]); strcpy(a[n-1),temp); rec(a+1,n-2); } void main() { rec(a 4); int i = 0; for(;i<4;i++) a[i][4]+= 10; printf("%s", a); }

  • #include <stdio.h> #include <string.h> #define WORDLEN 20 char smallest_word[WORDLEN + 1], largest_word[WORDLEN + 1], word[WORDLEN +...

    #include <stdio.h> #include <string.h> #define WORDLEN 20 char smallest_word[WORDLEN + 1], largest_word[WORDLEN + 1], word[WORDLEN + 1]; void get_first_word(void); void get_another_word(void); void get_word(void); int main(void) { get_first_word(); while (strlen(word) != 4) get_another_word(); printf("\nSmallest word: %s\nLargest word: %s\n", smallest_word, largest_word); return 0; } void get_first_word(void) { get_word(); strcpy(smallest_word, word); strcpy(largest_word, word); } void get_word(void) { printf("Enter word: "); scanf("%20s", word); } void get_another_word(void) { get_word(); if (strcmp(word, smallest_word) < 0) strcpy(smallest_word, word); else if (strcmp(word, largest_word) > 0) strcpy(largest_word, word); }...

  • #include <stdio.h> #include <stdlib.h> #include <string.h> #include<ctype.h> #define MAX_LEN 255 int numWords(char *str); int numDigit(char *str);...

    #include <stdio.h> #include <stdlib.h> #include <string.h> #include<ctype.h> #define MAX_LEN 255 int numWords(char *str); int numDigit(char *str); int numUppltr(char *str); int numLwrltr(char *str); int punChar(char *str); char*readString(char *str); int main() { char givString[MAX_LEN]; puts("Enter your string(Max 255 characters):"); //readString(givString); gets(givString); printf("\nnumber of words :%d",numWords(givString)); printf("\nnumber of uppercase letters %d",numUppltr(givString)); printf("\nnumber of lowercase letters %d",numLwrltr(givString)); printf("\nnumber of punctuations %d\n",punChar(givString)); printf("\nnumber of digits:%d\n",numDigit(givString)); system("pause"); return 0; } char *readString(char *str) { int ch, i=0; while((ch=getchar())!=EOF && ch!='\n') { if(i) { str[i]=ch; i++; }...

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