Week 13 Lab A

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Software Development Fundamentals Lab – I [15B17CI171]

Assignment Sheet: Week 13 [6th – 11th Nov, 2023]


Lab – A (Topic: Structures and Union)
Q1. Write a program to add two distances in inch-feet using structure. The values of the
distances is to be taken from the user.

Q2. Enter the marks of 5 students in Chemistry, Mathematics and Physics (each out of 100)
using a structure named Marks having elements roll no., name, chem_marks, maths_marks
and phy_marks and then display the percentage of each student.

Q3. Write a structure to store the roll no., name, age (between 11 to 14) and address of students
(more than 10). Store the information of the students. Using Switch case find the following
1. To print the names of all the students having age 14.
2. To print the names of all the students having even roll no.
3. To display the details of the student whose roll no is given (i.e. roll no. entered by the
user).

Q4. Create a structure to specify data of customers in a bank. The data to be stored is:
Account number, Name, Balance in account. Assume maximum of 20 customers in the bank.
Create a function to read all customers details and call it in main. Your program must be
menu driven with following options
1. Print the Account number and name and balance of each customer.
2. Withdraw money
3. Deposit money
4. Search Customer

Q5. Write a program to compare two dates entered by user. Make a structure named Date to
store the elements day, month and year to store the dates. If the dates are equal, display "Dates
are equal" otherwise display "Dates are not equal".

Q6. Virtual Lab experiment on Structures Virtual Labs (vlabs.ac.in)

Q7. Define a union ‘student’ which can record the roll number, name and age. The name
contains up to 33 characters, roll number requires long integer value and age 2-digit integer
value. Write a program to compute the size of this union. Also, write the reason for resulting
size.

Q8. Include courses enrolled in the union given in the previous question student can be
enrolled for maximum 5 courses and 20 characters may be needed to write the full course
name. Write a program to compute the size of union. Also, write the reason for resulting size.
Q9. Define a union which can record the ID, Name, Age, and Salary of two employees
Employee. Using loops, record the input for five users and print all the records such that no
data is lost while printing the output.

Q.10 Define a union with three members – one each of char, int, and float data types. The
char variable should be able to handle a string of a maximum of 10 characters. Declare two
variables of this union.
1. The first variable read user input for all the three members first and then print their values to
the output screen.
2. For the second variable, one by one, read input for one member and then print its
value.
3. Print the size of the union variables.

Examine the difference in the outputs of the first and second steps.

Q.11 Write a program in C to demonstrate the difference between union and structure.
1. Define a structure and a union with three members, one each of int, float, and char
data-type.
2. Take user input for each member, both for union and structure.
3. Print the value of each member variable and size of structure and union variable.

Examine the difference between the output of structure and union, if any.

You might also like