0% found this document useful (0 votes)
11 views

Structure in C

This document provides instructions for three exercises to practice working with structures in C: 1) Creating a contact list program using a structure to represent each contact and storing contacts in an array of structures. The program allows adding, displaying, and searching contacts. 2) Developing an advanced student record management system using dynamic arrays and structures. The program implements various features like adding, displaying, searching, updating, deleting student records and sorting. 3) Building a personal address book program representing a person's details using nested structures for address and person information. The program allows adding people to an address book array and viewing details.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Structure in C

This document provides instructions for three exercises to practice working with structures in C: 1) Creating a contact list program using a structure to represent each contact and storing contacts in an array of structures. The program allows adding, displaying, and searching contacts. 2) Developing an advanced student record management system using dynamic arrays and structures. The program implements various features like adding, displaying, searching, updating, deleting student records and sorting. 3) Building a personal address book program representing a person's details using nested structures for address and person information. The program allows adding people to an address book array and viewing details.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Structure In C

Exercise 1: Managing a Contact List


Suppose you need to create a C program to manage a contact list. Each contact is represented
by a structure containing the following information:
• Last Name
• First Name
• Phone Number
We want to create a program that allows the user to add contacts to the list, display the existing
contact list, and search for a contact by name. Here are the steps for the exercise:
1. Define a structure named Contact that contains fields for last name, first name, and
phone number.
2. Declare an array of Contact structures to store the contact list. You can choose a
maximum size for the array, for example, 100 contacts.
3. Write a function to add a contact to the list. This function should take the last name, first
name, and phone number of the contact as input and add it to the list.
4. Write a function to display the list of contacts. Iterate through the array of structures and
display the details of each contact.
5. Write a function to search for a contact by name. The user should enter a name, and the
program should display all contacts with that name.
6. In the main() function, create an interactive menu that allows the user to add, display,
or search for contacts, or exit the program.
7. Ensure that the program handles cases where the contact list is full or when no matching
contact is found in the search.

Exercise 2: Advanced Student Record Management with Dynamic Arrays


In this exercise, you'll create a C program to manage student records using dynamic arrays and
structures. Each student record will contain the following information:
• Student ID (a unique integer)
• Name (a string)
• GPA (a floating-point number)

GPA stands for "Grade Point Average.


We want implement the following features:
1. Implement an initial dynamic array for student records.
2. Create a menu-driven system that allows the user to perform the following actions:
• Add a new student record to the dynamic array.
• Display all student records.
• Search for a student by student ID.
• Update a student's information (name and GPA) by student ID.
• Delete a student record by student ID.
• Calculate and display the average GPA of all students.
• Sort and display the student records based on GPA in ascending or descending
order.
• Exit the program.

Exercise 3: Creating a Personal Address Book in C


We want to create a personal address book in C using structures to represent a person's
information, including their name and an address structure to store their address details.
Instructions:
1. Define two C structures: Address and Person. The Address structure should include
the following fields:
• Street (string)
• City (string)
• State (string)
• Zip code (string)
The Person structure should include the following fields:
• First name (string)
• Last name (string)
• Address (an instance of the Address structure)
• Phone number (string)
2. Create an array to store multiple instances of the Person structure, effectively creating
an address book. You can choose the size of the array based on your preferences (e.g.,
10 entries).
3. Write a function to input information for a person and add it to the address book.
4. Write a function to display the details of a specific person based on their index in the
address book.
5. Implement a menu-driven program that allows the user to perform the following
operations:
• Add a new person to the address book
• View the details of a person by their index
• Quit the program
6. Use a loop to display the menu and perform the chosen operation until the user decides
to quit.
7. Ensure error handling for out-of-bounds indices when viewing a person's details.
8. Test your program by adding a few entries to the address book and viewing their details.

You might also like