Array Tasks
Array Tasks
Array Tasks
Task 1:
Scenario:
You are developing a student management system for a school using C++. The system should allow
teachers to perform various array operations on student records to efficiently manage their academic
information. Here's the scenario you need to base your question on:
Scenario Description:
You are tasked with creating a C++ program to help teachers manage student records for a school. The
program should provide functionalities for teachers to perform array operations on the student data,
including traversing the list of students, inserting new student records, deleting existing student records,
searching for specific students, and updating student information.
Question:
Develop a C++ program for managing student records in a school. Implement the following array
operations:
Traverse Operation:
Write a function to display the details of all the students currently enrolled in the school.
Insertion:
Implement a function that allows teachers to add a new student record to the system. The function
should prompt the teacher to enter the student's details (e.g., name, roll number, grade), and then add
it to the student records.
Deletion:
Create a function to remove a student record from the system based on the given roll number or name.
The function should prompt the teacher to enter the roll number or name of the student they want to
delete and then remove the corresponding record from the system.
Searching:
Write a function to search for a student in the records based on either the student's roll number or
name. The function should prompt the teacher to enter the roll number or name of the student they
want to search for and then display the student details if found.
Update:
Implement a function to update the information of a student in the records. The function should prompt
the teacher to enter the roll number or name of the student they want to update, and then allow them
to modify any information related to that student (e.g., name, grade, contact information).
Ensure that your program provides a user-friendly interface with clear instructions for each operation.
Test your program with sample inputs to demonstrate its functionality.
#include <iostream>
#include <string>
struct Student {
string name;
int rollNumber;
char grade;
};
Student students[MAX_STUDENTS];
int numStudents = 0;
void traverse() {
cout << "Name: " << students[i].name << ", Roll Number: " << students[i].rollNumber << ", Grade: "
<< students[i].grade << endl;
void insert() {
numStudents++;
} else {
cout << "Maximum number of students reached. Cannot add more students." << endl;
void deletion() {
int rollNumber;
cout << "Enter the roll number of the student you want to delete: ";
if (students[i].rollNumber == rollNumber) {
found = true;
numStudents--;
break;
}
if (!found) {
cout << "Student with roll number " << rollNumber << " not found." << endl;
void searching() {
int rollNumber;
cout << "Enter the roll number of the student you want to search for: ";
if (students[i].rollNumber == rollNumber) {
found = true;
cout << "Name: " << students[i].name << ", Roll Number: " << students[i].rollNumber << ", Grade:
" << students[i].grade << endl;
break;
if (!found) {
cout << "Student with roll number " << rollNumber << " not found." << endl;
void update() {
int rollNumber;
cout << "Enter the roll number of the student you want to update: ";
if (students[i].rollNumber == rollNumber) {
found = true;
cout << "Enter new details for the student:" << endl;
break;
if (!found) {
cout << "Student with roll number " << rollNumber << " not found." << endl;
int main() {
int choice;
do {
switch (choice) {
case 1:
traverse();
break;
case 2:
insert();
break;
case 3:
deletion();
break;
case 4:
searching();
break;
case 5:
update();
break;
case 6:
break;
default:
Output
Lab Task 2
You are tasked with developing a program for managing a library's book inventory using C++. The
program should provide functionality for various array operations to handle the book records efficiently.
Here's the scenario you need to base your question on:
Scenario Description:
You are a software developer working for a library. The library needs a software tool to manage its book
inventory efficiently. Your task is to design a C++ program that allows librarians to perform various array
operations on the book inventory. The program should include functionalities for traversing the book
records, inserting new books, deleting existing books, searching for specific books, and updating book
information.
Question:
Develop a C++ program to manage the book inventory for the library. Implement the following array
operations:
Traverse Operation:
Insertion:
Implement a function that allows the librarian to add a new book to the inventory. The function should
prompt the user to enter the details of the new book (e.g., title, author, ISBN), and then add it to the
inventory.
Deletion:
Create a function to remove a book from the inventory based on the given book title or ISBN. The
function should prompt the user to enter the title or ISBN of the book they want to delete and then
remove it from the inventory.
Searching:
Write a function to search for a book in the inventory based on either the book's title or ISBN. The
function should prompt the user to enter the title or ISBN of the book they want to search for and then
display the book details if found.
Update:
Implement a function to update the information of a book in the inventory. The function should prompt
the user to enter the title or ISBN of the book they want to update, and then allow them to modify any
information related to that book (e.g., title, author, ISBN)
Ensure that your program provides a user-friendly interface with clear instructions for each operation.
Test your program with sample inputs to demonstrate its functionality.
Solution:
#include <iostream>
#include <string>
struct Book {
string title;
string author;
string ISBN;
};
Book books[MAX_BOOKS];
int numBooks = 0;
void traverse() {
cout << "Title: " << books[i].title << ", Author: " << books[i].author << ", ISBN: " << books[i].ISBN <<
endl;
void insert() {
cin.ignore();
getline(cin, books[numBooks].title);
numBooks++;
} else {
cout << "Maximum number of books reached. Cannot add more books." << endl;
void deletion() {
string searchTerm;
cout << "Enter the title or ISBN of the book you want to delete: ";
cin.ignore();
getline(cin, searchTerm);
found = true;
numBooks--;
break;
if (!found) {
void searching() {
string searchTerm;
cout << "Enter the title or ISBN of the book you want to search for: ";
cin.ignore();
getline(cin, searchTerm);
found = true;
cout << "Title: " << books[i].title << ", Author: " << books[i].author << ", ISBN: " << books[i].ISBN
<< endl;
break;
if (!found) {
void update() {
string searchTerm;
cout << "Enter the title or ISBN of the book you want to update: ";
cin.ignore();
getline(cin, searchTerm);
found = true;
cout << "Enter new details for the book:" << endl;
getline(cin, books[i].title);
getline(cin, books[i].author);
break;
if (!found) {
int main() {
int choice;
do {
switch (choice) {
default: cout << "Invalid choice. Please try again." << endl;
Output