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

Assignment 4

The document outlines an assignment consisting of ten tasks focused on character arrays, structures, dynamic memory allocation, and file handling in C++. Each task requires writing a program to perform specific operations, such as string manipulation, data management using structures, and file operations, with a final task integrating all concepts into a simple library management system. Submission guidelines include providing source code, testing outcomes, and a deadline of January 14, 2024.

Uploaded by

haleemasadia0024
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Assignment 4

The document outlines an assignment consisting of ten tasks focused on character arrays, structures, dynamic memory allocation, and file handling in C++. Each task requires writing a program to perform specific operations, such as string manipulation, data management using structures, and file operations, with a final task integrating all concepts into a simple library management system. Submission guidelines include providing source code, testing outcomes, and a deadline of January 14, 2024.

Uploaded by

haleemasadia0024
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Assignment 4

Task 1: Working with 1D Character Arrays

Objective: Perform basic operations on 1D character arrays.

1. Write a program to:

o Input a string from the user and store it in a character array.

o Calculate the length of the string without using built-in


functions.

o Reverse the string using pointers.

o Concatenate another string to the original using character-by-


character copying.

Deliverable: A program demonstrating manual string operations using


character arrays and pointers.

Task 2: Operations with 2D Character Arrays

Objective: Manipulate and search in a 2D array of strings.

1. Create a program to:

o Store names of 5 students in a 2D character array.

o Implement a search function using pointers to find a name


entered by the user.

o Replace one name in the list with another entered by the user.

Deliverable: A program showcasing manipulation of 2D character arrays


and searching strings.

Task 3: Introduction to Structures

Objective: Define and use structures to manage data.

1. Define a structure Student with the following members:

o ID (integer)

o Name (1D character array)

o Marks (array of 3 integers)

2. Write a program to:

o Input and store data for 3 students.

o Calculate and display the average marks of each student.


Deliverable: A program demonstrating the use of structures for
organizing data.

Task 4: Dynamic Memory Allocation

Objective: Allocate memory dynamically for storing data.

1. Write a program to:

o Allocate memory dynamically for storing names of n students.

o Input and display each student's name.

o Deallocate the memory after use.

Deliverable: A program illustrating dynamic memory allocation and


deallocation using new and delete.

Task 5: Combining Structures and Dynamic Memory Allocation

Objective: Use structures with dynamic memory allocation.

1. Define a structure Book with:

o ID (integer)

o Title (dynamic 1D character array)

o Author (dynamic 1D character array)

2. Write a program to:

o Dynamically allocate memory for storing details of 5 books.

o Input and display details of each book.

o Deallocate the memory after displaying the details.

Deliverable: A program combining structures and dynamic memory


allocation.

Task 6: File Handling Basics

Objective: Perform basic file operations.

1. Write a program to:

o Open a file in write mode and store names of 5 students.

o Open the file in read mode and display the contents on the
console.

o Update the file by adding 2 more names in append mode.


Deliverable: A program demonstrating file handling basics, including
writing, reading, and appending.

Task 7: File Handling with Structures

Objective: Store and retrieve structured data using files.

1. Write a program to:

o Define a structure Student with ID, Name, and Marks.

o Input details for 3 students and write them to a file.

o Read the data from the file and display it on the console.

Deliverable: A program showcasing the use of file handling for structured


data storage.

Task 8: Building a Simple Library Management System

Objective: Integrate structures, dynamic memory, and file handling.

1. Create a mini-library system where:

o Book details (ID, Title, Author) are stored in a structure.

o Use dynamic memory allocation for storing book titles and


authors.

o Save book records to a file, and load them at program startup.

Deliverable: A program that integrates concepts into a real-world


scenario.

Task 9: Exploring File Modes

Objective: Work with different file modes.

1. Write a program to:

o Open a file in ios::in mode and check if it exists.

o Open a file in ios::out mode and overwrite its contents.

o Open a file in ios::app mode and add new data.

o Use ios::binary to store and retrieve data in binary format.

Deliverable: A program demonstrating various file modes and their


usage.

Task 10: Character Array Operations with Pointers

Objective: Perform advanced character operations using pointers.


1. Write a program to:

o Input a string and count the occurrence of each vowel.

o Use pointers to replace all spaces in the string with


underscores (_).

o Create a function to find substrings within the string using


pointers.

Deliverable: A program demonstrating advanced operations on character


arrays using pointers.

Submission Guidelines:

 Submit the C++ source code for each task.


 Ensure that the program compiles and runs without errors.
 For each program, test it with multiple inputs and write down the
expected outcome.
 Handwritten Assignment snapshoots as pdf on Slate.
 Deadline: 14th January 2024

You might also like