SEBA Class 10 Computer Science Chapter 9 Structure In C

Join Roy Library Telegram Groups

Hello Viewers Today’s We are going to Share With You, The Complete Syllabus of SEBA Class 10 Computer Science Chapter 9 Structure In C Solutions in English in This Page. Are you a Student of (Secondary Education Board of Assam). SEBA Class 10 Computer Science Chapter 9 Structure In C Notes. Which you Can Download PDF SEBA Class 10 Computer Science Chapter 9 Structure In C Question Answer for free using direct Download Link Given Below in This Post.

SEBA Class 10 Computer Science Chapter 9 Structure In C

We have Shared in This Post, SEBA Class 10 Computer Science Chapter 9 Structure In C Textbook PDF Download for Free with you. SEBA Class 10 Computer Science Chapter 9 Structure In C Solutions PDF. I Hope, you Liked The information About The SEBA Class 10 Computer Science Chapter 9 Structure In C Book PDF. If you liked Class 10 Computer Science Notes Then Please Do Share this Post With your Friends as Well.

TEXTUAL QUESTIONS AND ANSWERS

EXERCISE

1. Define structure in context of a programming language. How is it different from an array?

Ans. Structure is a user-defined data type that allows us to combine data of different types together. Structure helps to construct a complex data type that is more practical and meaningful.

The major difference between an array and structure is that an “array” contains all the elements of “same data type” and the size of an array is defined during its declaration, which is written in number within square brackets, preceded by the array name.

A “structure” contains all the elements of “different data type”, and its size is determined by the number of elements declared in a structure when it is defined.

2. Is structure a built-in-data type? Can we apply basic arithmetic operations such as addition, subtraction to structure variable? Show with an example.

Ans. Structure is not a built – in -data type. We can group various built-in data types into a structure.

Yes, we can apply basic arithmetic operations such as addition, subtraction to structure variable. This can be explained with the help of following example.

Example:

Code:

#include<stdio.h>struct Calc{int n1, n2;int total, diff;};int main(){struct Calc c;printf(“\nEnter two nos.:”);scanf(“%d%d”, &c.n1,&c.n2);c.total = c.n1 + c.n2;c.diff = c.n1- c.n2;printf(“\n Total = %d “, c.total);printf(“\nDifference = %d “, c.diff):return 0;}

Output:

3. Identify the members of the structure from the below code segment.

Ans. Members of the structure: acNo, ifsc, acType, balance, minBalance.

4. Identify the structure variables from the below code segment.

Ans. Structure variables: account1, account2, account3, account [10]

5. Consider the structure below and write statements for the following:

(a) To declare a variable of the structure.

(b) To display age of the teacher.

struct Teacher

{

char name [30];

int age;

};

Solution:

(a) struct Teacher obj;

(b) printf(“\n The age of the teacher is %d”, obj.age);

6. Declare a pointer for structure Teacher (from Q No. 5) and dynamically allocate memory for 10 records.

Solution:

#include<stdio.h>#include<stdlib.h>struct Teacher{char name[30]:int age;};int main(){struct Teacher obj:struct Teacher *ptr,ptr=&obj;ptr= (struct Teacher*)malloc (10 * sizeof(struct Teacher));return 0;}

7. Consider the structure below and write the statements for the following:

(a) To declare a pointer for the above structure and display the salary.

(b) To declare a single pointer for two different variables of the higher structure and display the details of the employee whose salary is more.

struct Employee

{

char name [30];

double salary;

};

Solution:

Code:

#include<stdio.h>#include<stdlib.h>struct Employee{char name[30];double salary:};int main(){struct Employee obj1, obj2;struct Employee *ptr,ptr=&obj1;printf(“\n Enter the name of the first employee: “);gets(ptr->name);printf(“\n Enter the salary: “);scanf(“%lf”, &ptr->salary);ptr=&obj2;printf(“\n Enter the name of the second employee: “);getchar();gets(ptr->name);printf(“\n Enter the salary: “);scanf(“%lf”, &ptr->salary);printf(“\n Details of the employee whose salary is more “);if (obj1.salary > obj2.salary){printf(.”\n Name: “);puts(obj1.name);printf(“\n Salary = %lf”, obj1.salary);}else{printf(“\n Name:”);puts(obj2.name);printf(“\n Salary = %lf”, obj2.salary);}return 0;}Note: The format specifier for double data type is “%lf”

Output:

S.L No.CONTENTS
Chapter 1Introduction To Computer Network
Chapter 2Html5 And Css3
Chapter 3Database Part – II Mysql
Chapter 4Introduction To Loops
Chapter 5Nested Loops In C
Chapter 6Arrays In C
Chapter 7Functions In C
Chapter 8Pointers In C
Chapter 9Structure In C
Chapter 10An Introduction To Object Oriented Programming
Chapter 11Case Studies

8. Rewrite the program of Q. no. 7 to facilitate dynamic memory allocation for N number of record where N is a user input.

Solution:

#include<stdio.h>#include<stdlib.h>struct Employee{char name[30];double salary;};int main(){struct Employee *ptr,inti, n;printf(“\n Enter the number of employees:”);scanf(“%d”, &n);ptr= (struct Employee*) malloc (n * sizeof (struct Employee));for(i=0; i<n; i++){printf(“\n Enter the name of the employee: “);getchar();gets((ptr+i)->name);printf(“\n Enter the salary: “);scanf(“%lf”, (ptr+i)->salary);}return 0;}

9. Consider the below structure and design a simple banking system that supports the following operations.

(a) Opening of accounts

(b) Displaying details based on account number

(c) Displaying all account details

(d) Displaying details of all accounts whose balance is more than 1000.

(e) Depositing an amount from an account

(f) Withdrawing some amount from an account

struct Account

{

char acNo[15];

char ifsc[15];

char acType[7];

double balance;

double minBalance;

};

Solution:

Code:

#include<stdio.h>#include<stdlib.h>#include<string.h>struct Account{char acNo[15]:char ifsc[15]:char acType[8];double balance;double minBalance;};int main(){int n, choice;char ans, s[15];double d, w;struct Account act[2];do{printf(“\n 1. Account opening “);printf(“\n 2. Displaying details based on account number”);printf(“\n 3. Displaying all account details”);printf(“\n 4. Displaying details of all accounts whose balance is more than 1000”);printf(“\n 5. Depositing an amount from an account”);printf(“\n 6. Withdrawing some amount from an account”);printf(“\n 7. Exit”);printf(“\n Enter your choice: “);scanf(“%d”, &choice);switch (choice){case 1:for (int i=0; i<2; i++){printf(“\n Enter account number :”);.getchar();gets(act[i].acNo);printf(“\n Enter IFSC code :”);gets(act[i].ifsc);printf(“\n Enter account type (Saving/Current) :”);gets(act[i].acType);printf(“\n Enter account balance :”);scanf(“%lf”, &act[i]. balance);}break;case 2:printf(“\n Enter the account number to display its details: “);getchar();gets(s);for (int i=0; i<2; i++){if (strcmp(act[i].acNo,s)==0){printf(“\n Account no. :”);puts(act[i].acNo);printf(“\n IFSC code: “);puts (act[i].ifsc);printf(“\n Account type: “);puts(act[i].acType);printf(“\n Balance: %lf”, act[i].balance);}}break;case 3:printf(“\n Displaying all account details \n”);for (int i=0; i<2; i++){printf(“\n Account no. : “);puts(act[i].acNo);printf(“\n IFSC code: “);puts(act[i].ifsc);printf(“\n Account type: “);puts(act[i].acType);printf(“\n Balance: %lf”, act[i].balance)}case 4:for (int i=0; i<2; i++){if(act[i].balance>1000){printf(“\n Account no. :”);puts(act[i].acNo);printf(“\n IFSC code: “);puts(act[i].ifsc);printf(“\n Account type : “);puts(act[i].acType);printf(“\n Balance: %lf”, act[i].balance);}}break;case 5:printf(“\n Enter the account number to deposit amount : “);getchar();gets(s);for (int i=0; i<2; i++){if (strcmp(act[i].acNo,s)==0){printf(“\n Enter the amount to be deposited: “);scanf(“%lf”, &d);act[i].balance = act[i] balance +d;printf(“\n New balance is %lf: “, act[i].balance);}}break;case 6:printf(“\n Enter the account number to withdraw amount : “);getchar();gets(s);for (int i=0; i<2; i++){if (strcmp(act[i].acNo,s)==0){printf(“\n Enter the amount to be withdrawn : “);scanf(“%lf”, &w);act[i].balance = act[i]. balance – w;printf(“\n New balance is %lf: “, act[i].balance);}}break;case 7:return 0;}printf(“\n Do you want to continue : (Y/N)”);getchar();scanf(“%c”,&ans);}while(ans == ‘y’ || ans == ‘Y’);return 0;}
ADDITIONAL QUESTIONS AND ANSWERS

1. What is structure in C?

Ans. Structure is a group of variables of different data types represented by a single name.

2. What is the keyword used to define a structure?

Ans. The struct keyword is used to define the structure.

3. What is structure member in C?

Ans. Structure in C is a collection of different data types which are grouped together and each element in a C structure is called member.

4. What is structure variable in C?

Ans. When a struct type is declared, no storage or memory is allocated. To allocate memory of a given structure type and work with it, we need to create variables. These variables are called structure variables.

5. How is a structure accessed in C?

Ans. Structure members are accessed using dot (.) operator.

6. How is structure different from array?

Ans. Array refers to a collection consisting of elements of homogeneous data type. Structure refers to a collection consisting of elements of heterogeneous data type.

7. What is structure pointer?

Ans. Structure pointer is defined as the pointer which points to the address of the memory block that stores a structure is known as the structure pointer.

8. What operator is used to access the members of structure using pointer?

Ans. The members of the structure can be accessed using a special operator called as an arrow operator (->).

9. What is array of structure in C?

Ans. An array of structure in C programming is a collection of different datatype variables, grouped together under a single name.

10. Write the syntax to access members of a structure.

Ans. The syntax to access members of a structure:

Structure_Variable_Name.Member_Name

11. Write the syntax of a structure definition.

Ans. The general syntax of a structure definition is as follows:

struct Structure_name

{

data_type member1;

data_type member2;

…………………….

…………………….

data_type member;

};

Leave a Reply

error: Content is protected !!
Scroll to Top