Data Structures Lab [BCSL305]
Department of CSE- Data Science
Program 1: Develop a Program in C for the following:
a) Declare a calendar as an array of 7 elements (A dynamically Created array) to
represent 7 days of a week. Each Element of the array is a structure having
three fields. The first field is the name of the Day (A dynamically allocated
String), The second field is the date of the Day (A integer), the third field is the
description of the activity for a particular day (A dynamically allocated String).
b) Write functions create(), read() and display(); to create the calendar, to read
the data from the keyboard and to print weeks activity details report on
screen.
Department of CSE- Data Science
Procedure
1. Define a structure to represent a day in the calendar
2. Function to create a calendar – createCalendar()
3. Function to read data from the keyboard- readCalendarData()
4. Function to display the calendar- displayCalendar()
Department of CSE- Data Science
// structure to represent a day in the calendar
struct Day
{
char* dayName;
int date;
char* activity;
};
Department of CSE- Data Science
Stores name of the day
Stores date
Description of the planned activity
// Function to create the calendar
struct Day* createCalendar()
{
struct Day* calendar = (struct Day*)malloc(7 * sizeof(struct Day));
for (int i = 0; i < 7; i++)
{
calendar[i].dayName = (char*)malloc(20 * sizeof(char));
calendar[i].activity = (char*)malloc(100 * sizeof(char));
}
return calendar;
}
Department of CSE- Data Science
Allocates memory for 7 days &
returns a pointer to the block of the
memory
For each day,
allocate
memory for
day name &
activity
// Function to read data from the keyboard
void readCalendarData(struct Day* calendar)
{
for (int i = 0; i < 7; i++)
{
printf("Enter the day name for Day %d: ", i + 1);
scanf("%s", calendar[i].dayName);
printf("Enter the date for Day %d: ", i + 1);
scanf("%d", &calendar[i].date);
printf("Enter the activity for Day %d: ", i + 1);
scanf(" %[^n]s", calendar[i].activity);
}
}
Department of CSE- Data Science
Runs the loop for 7 times asking
the user to enter
→ Day name
→ Date
→ Activity
// function to display the calendar
void displayCalendar(struct Day* calendar)
{
printf("Weekly Activity Report:nn");
for (int i = 0; i < 7; i++)
{
printf("Day %d: %sn", i + 1, calendar[i].dayName);
printf("Date: %dn", calendar[i].date);
printf("Activity: %sn", calendar[i].activity);
printf("n");
}
}
Department of CSE- Data Science
Prints each day’s
details name, date ,
activity
//main() function
int main()
{
struct Day* calendar = createCalendar();
readCalendarData(calendar);
displayCalendar(calendar);
// Free memory
for (int i = 0; i < 7; i++)
{
free(calendar[i].dayName);
free(calendar[i].activity);
}
free(calendar);
return 0;
}
Department of CSE- Data Science

Experiment-1.pptx : program to create a calendar

  • 1.
    Data Structures Lab[BCSL305] Department of CSE- Data Science
  • 2.
    Program 1: Developa Program in C for the following: a) Declare a calendar as an array of 7 elements (A dynamically Created array) to represent 7 days of a week. Each Element of the array is a structure having three fields. The first field is the name of the Day (A dynamically allocated String), The second field is the date of the Day (A integer), the third field is the description of the activity for a particular day (A dynamically allocated String). b) Write functions create(), read() and display(); to create the calendar, to read the data from the keyboard and to print weeks activity details report on screen. Department of CSE- Data Science
  • 3.
    Procedure 1. Define astructure to represent a day in the calendar 2. Function to create a calendar – createCalendar() 3. Function to read data from the keyboard- readCalendarData() 4. Function to display the calendar- displayCalendar() Department of CSE- Data Science
  • 4.
    // structure torepresent a day in the calendar struct Day { char* dayName; int date; char* activity; }; Department of CSE- Data Science Stores name of the day Stores date Description of the planned activity
  • 5.
    // Function tocreate the calendar struct Day* createCalendar() { struct Day* calendar = (struct Day*)malloc(7 * sizeof(struct Day)); for (int i = 0; i < 7; i++) { calendar[i].dayName = (char*)malloc(20 * sizeof(char)); calendar[i].activity = (char*)malloc(100 * sizeof(char)); } return calendar; } Department of CSE- Data Science Allocates memory for 7 days & returns a pointer to the block of the memory For each day, allocate memory for day name & activity
  • 6.
    // Function toread data from the keyboard void readCalendarData(struct Day* calendar) { for (int i = 0; i < 7; i++) { printf("Enter the day name for Day %d: ", i + 1); scanf("%s", calendar[i].dayName); printf("Enter the date for Day %d: ", i + 1); scanf("%d", &calendar[i].date); printf("Enter the activity for Day %d: ", i + 1); scanf(" %[^n]s", calendar[i].activity); } } Department of CSE- Data Science Runs the loop for 7 times asking the user to enter → Day name → Date → Activity
  • 7.
    // function todisplay the calendar void displayCalendar(struct Day* calendar) { printf("Weekly Activity Report:nn"); for (int i = 0; i < 7; i++) { printf("Day %d: %sn", i + 1, calendar[i].dayName); printf("Date: %dn", calendar[i].date); printf("Activity: %sn", calendar[i].activity); printf("n"); } } Department of CSE- Data Science Prints each day’s details name, date , activity
  • 8.
    //main() function int main() { structDay* calendar = createCalendar(); readCalendarData(calendar); displayCalendar(calendar); // Free memory for (int i = 0; i < 7; i++) { free(calendar[i].dayName); free(calendar[i].activity); } free(calendar); return 0; } Department of CSE- Data Science

Editor's Notes

  • #1 Welcome students to the very first Data Structures lab. Explain that this lab will form the backbone for their journey into problem-solving, efficiency, and programming. Highlight how labs are about hands-on practice rather than just theory.
  • #2 Emphasize that students already know C basics, now they will apply it to handle structured data. Show how DS labs will help them solve real-world problems efficiently. Stress on logical thinking: DS is about how data is stored and accessed.
  • #3 Relate DS to their specialization: Data Science. Example: Handling millions of records in a dataset requires efficient structures. Sorting, searching, and graph algorithms are building blocks of machine learning pipelines.
  • #4 Engage students with reflection questions. Push them to think: what if we need dynamic memory? This prepares ground for Linked Lists in upcoming labs.
  • #5 Emphasize that students already know C basics, now they will apply it to handle structured data. Show how DS labs will help them solve real-world problems efficiently. Stress on logical thinking: DS is about how data is stored and accessed.
  • #6 Wrap up with key takeaways. Reiterate: DS is not just coding, it’s about thinking of efficient solutions. Motivate students to practice regularly.
  • #7 Define Data Structure as a systematic way of organizing and accessing data. Connect to examples they’ll study step by step. Mention importance: search engines, databases, social networks all rely on efficient data structures.
  • #8 Reiterate: DS is not just coding, it’s about thinking of efficient solutions. Motivate students to practice regularly.