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

BASIC COMPUTER ENG

BASIC COMPUTER ENG

Uploaded by

kapiljeewnani64
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
471 views

BASIC COMPUTER ENG

BASIC COMPUTER ENG

Uploaded by

kapiljeewnani64
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 55

Acropolis Institute of Technology and Research, Indore

B.Tech. First Year

Basic Computer Engineering


(BT - 205)

Submitted To : Prof. Reshma Shivhare

Submitted By : Durgesh Jhala


Class/Year/Sem: I Year/ I Sem

1
Certificate

This is to certify that Mr./Ms. DURGESH JHALA Enrolment No.:0827CE241023


B. Tech Ist Year Ist Semester in CIVIL ENGINEERING (Sub. Code CE) has
performed experiments as per the syllabus prescribed by RGPV Bhopal and
submitted satisfactory work in the institute during the academic year 2024 -
2025

Signature of Head Signature of Faculty

2
List of Practical

S.
Experiment
No.

A campus is arriving in the college and they need resumes of students to do the short listing.
Prepare your resume to appear in campus. Resume should be in MS Word in proper format
1 as given by class teacher.

Assume you are a trainer of Computer Fundamentals. To make students understand what is
2
“Computer System organisation” prepare a presentation.

Create a system for departmental store to perform various arithmetic operations on sailing and
3
purchasing prices of goods.

Store monthly rainfall amounts in an array. Then display the monthly rainfall amounts, the total
annual rainfall amount, the average rainfall amount, the highest rainfall amount, or the lowest
4 rainfall amount First get the rainfall amounts for the 12 months.

Create a checker to check whether a number is a prime number or not using the function.
5

For the students of school create a table generator, so that they will be able to learn table of
6 any no. given by them.

Asks the user several questions and selects a car for them. The questions are 1) do you have
children; 2) do you have lots of money; 3) do you like trucks.

Porsche: have no children, have lots of money, don’t like trucks Yukon: have no children, have
7 lots of money, like trucks Civic: have no children, have little money Villager: have children, have
lots of money, don’t like trucks Explorer: have children, have lots of money, like trucks Sentra:
have children, have little money

3
Create a tool to calculate the circle's area and circumference. create a class called Circle that
has private member variables for radius. Include member functions to calculate the circle's
8 area and circumference.

Create a tool that can give sum of given numbers (2,3 or 4). with function overloading.
9

10 Illustrate with example, how to overload increment operator.

Implement a class called Shape with member functions for calculating area and perimeter.
Derive classes such as Circle, Rectangle, and Triangle from the Shape class and overload
11 functions accordingly.

Implement a stack using an array with push and pop operations. Find the top element of the
stack and check if the stack is empty or not.
12

For the doctor's clinic create a waiting list of patients as per their arrival (FCFS) and find out
13 total no. of persons in waiting queue.

Create a list of even nos. from 1 to 20 without using array.


14

How can you navigate, open, and manipulate files on your computer without using GUI.
15

How to :1) List all the processes running. 2) Change the file permissions of the directories. 3)
check disk space usage. 4) List all the partitions on your system.
16

4
Index

Date of Date of Faculty Sign


S. No Title of the Practical
Practical Submission with date.

A campus is arriving in the college and they


need resumes of students to do the short
1 listing. Prepare your resume to appear in
campus. Resume should be in MS Word in
proper format as given by class teacher.

Assume you are a trainer of Computer


Fundamentals. To make students understand
2
what is “Computer System organisation”
prepare a presentation.

Create a system for departmental store


3 to perform various arithmetic operations
on sailing and purchasing prices of goods.

Store monthly rainfall amounts in an array.


Then display the monthly rainfall amounts, the
total annual rainfall amount, the average
4
rainfall amount, the highest rainfall amount, or
the lowest rainfall amount First get the rainfall
amounts for the 12 months.

Create a checker to check whether a number is


5
a prime number or not using the function.

For the students of school create a table


6 generator, so that they will be able to learn
table of any no. given by them.
Asks the user several questions and selects a
car for them. The questions are 1) do you have
children; 2) do you have lots of money; 3) do
you like trucks.
7
Porsche: have no children, have lots of money,
don’t like trucks Yukon: have no children, have
lots of money, like trucks Civic: have no
children, have little money Villager: have
children, have lots of money, don’t like trucks

5
Create a tool to calculate the circle's area and
circumference. create a class called Circle that
8 has private member variables for radius. Include
member functions to calculate the circle's area
and circumference.

9 Create a tool that can give sum of given


numbers(2,3 or 4). with function overloading.

10 Illustrate with example, how to overload


increment operator.

Implement a class called Shape with member


functions for calculating area and perimeter.
11 Derive classes such as Circle, Rectangle, and
Triangle from the Shape class and overload
functions accordingly.

Implement a stack using an array with push and


12 pop operations. Find the top element of the
stack and check if the stack is empty or not.

For the doctor's clinic create a waiting list of


13 patients as per their arrival (FCFS) and find out
total no. of persons in waiting queue.

14 Create a list of even nos. from 1 to 20 without


using array.

15 How can you navigate, open, and manipulate


files on your computer without using GUI.

How to :1) List all the processes running. 2)


16 Change the file permissions of the directories. 3)
check disk space usage. 4) List all the partitions
on your system.

6
EXPERIMENT – 1
EXPERIMENT TITLE: A campus is arriving in the college and they need resumes of students to do
the short listing. Prepare your resume to appear in campus. Resume should be in MS Word in proper
format as given by class teacher.

Durgesh Jhala
586, Jyoti Colony, Kshipra, Indore (MP)
Contact: 9981787937 | Email: [email protected]

Career Objective
Dedicated and detail-oriented first-year Civil Engineering student at Acropolis Institute of
Technology, eager to leverage my academic background and skills in office management and
computer applications. Aspiring to contribute effectively to the growth of a dynamic organization
while enhancing my professional abilities.

Educational Qualifications
Bachelor of Technology (Civil Engineering)
Acropolis Institute of Technology, Indore
(MP) 1st Year, 1st Semester
Higher Secondary School Certificate (HSC)
Kshipranjali Public H.S. School, Kshipra (MP Board)
Stream: PCM

Certifications
 Office Management Program
 Comprehensive training in administrative and organizational tasks.

Technical Skills
Proficient in basic computer operations.
Hands-on experience with:

7
 MS Word
 MS PowerPoint
 MS Excel
Hobbies
 Sketching
 Painting
 Crafting

Work Experience
 Fresher

Strengths
 Strong organizational and multitasking abilities.
 Creative problem-solving skills.
 Willingness to learn and adapt to new environments.

Declaration
I hereby declare that all the information provided above is true to the best of my knowledge and
belief.

SIGNATURE

8
EXPERIMENT – 2
EXPERIMENT TITLE: Assume you are a trainer of Computer Fundamentals. To make students
understand what is “Computer System organisation” prepare a presentation.

9
1
0
11
12
13
EXPERIMENT – 3
EXPERIMENT TITLE : Create a system for departmental store to perform various arithmetic operations on
sailing and purchasing prices of goods.

CODE:
#include <iostream>
#include <vector>
#include <string>
using namespace std;

// Structure to store product details struct Product {

string name; double purchasePrice; double


sellingPrice; int quantity;

// Function to calculate profit or loss double calculateProfitOrLoss() {

return (sellingPrice - purchasePrice) * quantity;

}
};

// Class for departmental store class DepartmentalStore {


private: vector<Product> products;

public:

// Add a product void addProduct() { Product product; cout <<


"Enter product name: "; cin >> product.name; cout << "Enter
purchase price: "; cin >> product.purchasePrice; cout << "Enter
selling price: "; cin >> product.sellingPrice; cout << "Enter
quantity: "; cin >> product.quantity;
products.push_back(product);

cout << "Product added successfully!\n";

// Display all products void displayProducts()

{ if (products.empty()) {

cout << "No products available.\n"; return;

14
cout << "\nProduct Details:\n"; cout << "Name\tPurchase Price\tSelling Price\tQuantity\tProfit/Loss\n";
for (const auto& product : products) {

cout << product.name << "\t" << product.purchasePrice << "\t\t"

<< product.sellingPrice << "\t\t" << product.quantity << "\t\t"

<< product.calculateProfitOrLoss() << "\n";

}
}

// Calculate total profit or loss void calculateTotalProfitOrLoss()

{ double total = 0.0; for (const auto& product : products) {

total += product.calculateProfitOrLoss();

cout << "\nTotal Profit/Loss: " << total << "\n";

}
};

// Main function int main() {

DepartmentalStore store; int choice;

do {

cout << "\nDepartmental Store System\n"; cout << "1. Add Product\n";
cout << "2. Display Products\n"; cout << "3. Calculate Total Profit/Loss\n";
cout << "4. Exit\n"; cout << "Enter your choice: "; cin >> choice;

switch (choice) { case 1:

store.addProduct(); break;

case 2:

store.displayProducts(); break;

case 3:

store.calculateTotalProfitOrLoss(); break;

case 4: cout << "Exiting the system. Thank you!\n"; break;

default:

cout << "Invalid choice. Please try again.\n";

15
} while (choice != 4);

return 0;

MENU:

1. Add Product
2. Display Products
3. Calculate Total Profit/Loss
4. Exit

SAMPLE RUN:

Enter product name: Soap

Enter purchase price: 20

Enter selling price: 25

Enter quantity: 100

Product added successfully!

Product Details:

Name Purchase Price Selling Price Quantity Profit/Loss

Soap 20 25 100 500

Total Profit/Loss: 500

16
EXPERIMENT – 4

EXPERIMENT TITLE: Store monthly rainfall amounts in an array. Then display the monthly rainfall
amounts, the total annual rainfall amount, the average rainfall amount, the highest rainfall amount, or the lowest
rainfall amount First get the rainfall amounts for the 12 months.

Code:
#include <iostream>
#include <string>
#include <limits>
using namespace std;

int main() {

const int MONTHS = 12;

double rainfall[MONTHS]; string monthNames[MONTHS] = {"January", "February", "March", "April",


"May", "June",

"July", "August", "September", "October", "November", "December"};


double totalRainfall = 0, highestRainfall, lowestRainfall, averageRainfall; int
highestMonth = 0, lowestMonth = 0;

// Input rainfall data cout << "Enter rainfall amounts for each month
(in mm):\n"; for (int i = 0; i < MONTHS; i++) {

cout << monthNames[i] << ": ";

cin >> rainfall[i];

// Validate input while (rainfall[i] < 0) { cout << "Rainfall cannot be negative. Enter again for " <<
monthNames[i] << ": "; cin >> rainfall[i];

} totalRainfall += rainfall[i];

if (i == 0) { // Initialize highest and lowest rainfall highestRainfall =


lowestRainfall = rainfall[i];

} else {

if (rainfall[i] > highestRainfall) { highestRainfall =


rainfall[i]; highestMonth = i;

if (rainfall[i] < lowestRainfall) { lowestRainfall =


rainfall[i]; lowestMonth = i;

17
}
}
}

// Calculate average rainfall averageRainfall =


totalRainfall / MONTHS;

// Display results cout << "\nMonthly Rainfall


Data:\n"; for (int i = 0; i < MONTHS; i++) {

cout << monthNames[i] << ": " << rainfall[i] << " mm\n";

cout << "\nTotal Annual Rainfall: " << totalRainfall << " mm"; cout << "\nAverage Monthly Rainfall: " <<
averageRainfall << " mm"; cout << "\nHighest Rainfall: " << highestRainfall << " mm in " <<
monthNames[highestMonth]; cout << "\nLowest Rainfall: " << lowestRainfall << " mm in " <<
monthNames[lowestMonth] <<

"\n";

return 0;

Input:
January: 100

February: 80

March: 120

April: 150

May: 110

June: 90

July: 200

August: 190

September: 170

October: 140

November: 130

December: 120

18
Output:
Monthly Rainfall Data:

January: 100 mm

February: 80 mm

March: 120 mm

April: 150 mm

May: 110 mm

June: 90 mm

July: 200 mm

August: 190 mm

September: 170 mm

October: 140 mm

November: 130 mm

December: 120 mm

Total Annual Rainfall: 1600 mm

Average Monthly Rainfall: 133.333

mm Highest Rainfall: 200 mm in July

Lowest Rainfall: 80 mm in February

19
EXPERIMENT – 5
EXPERIMENT TITLE: Create a checker to check whether a number is
prime number or not using the function.

Code:
#include <iostream>
using namespace std;

// Function to check if a number is prime bool isPrime(int


number) {

if (number <= 1) {

return false; // Numbers less than or equal to 1 are not prime

for (int i = 2; i * i <= number; i++) { // Check divisors up to the square root of the number

if (number % i == 0) {

return false; // If divisible, it's not a prime number

}
}

return true; // If no divisors found, it's a prime number

int main() {

int num; cout << "Enter a number to check if it's a prime number: "; cin >>
num;

// Call the function and display the result if


(isPrime(num)) {

cout << num << " is a prime number.\n";

} else { cout << num << " is not a prime number.\n";

}
return 0;
}
Input: Output:
Enter a number to check if it's a prime number: 29 29 is a prime number.
Enter a number to check if it's a prime number: 10 10 is not a prime number.

2
0
EXPERIMENT – 6
EXPERIMENT TITLE: For the students of school create a table generator, so that they will be able to learn
table of any no. given by them.
Code:
#include <iostream>
using namespace std;

void generateTable(int number, int range) {


cout << "Multiplication Table for " << number << ":\n";
for (int i = 1; i <= range; i++) {
cout << number << " x " << i << " = " << number * i << endl;
}
}

int main() {
int number, range;

// Asking the user for the number and range


cout << "Enter the number for which you want to generate the multiplication table: ";
cin >> number;

cout << "Enter the range up to which you want the table: ";
cin >> range;

// Generate and display the table


generateTable(number, range);

return 0;
}

Output:
Enter the number for which you want to generate the multiplication table: 5
Enter the range up to which you want the table: 10
Multiplication Table for
5: 5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50

21
EXPERIMENT – 7
EXPERIMENT TITLE: Asks the user several questions and selects a car for them. The questions are 1) do
you have children; 2) do you have lots of money; 3) do you like trucks.

Porsche: have no children, have lots of money, don’t like trucks Yukon: have no children, have lots of money,
like trucks Civic: have no children, have little money Villager: have children, have lots of money, don’t like
trucks Explorer: have children, have lots of money, like trucks Sentra: have children, have little money

Code:
#include <iostream>
#include <string>
using namespace std;

int main() {

char haveChildren, haveMoney, likeTrucks;

// Ask the user questions

cout << "Do you have children? (y/n): ";

cin >> haveChildren;

cout << "Do you have lots of money? (y/n): ";

cin >> haveMoney;

cout << "Do you like trucks? (y/n): ";

cin >> likeTrucks;

// Determine car based on user input

if (haveChildren == 'n' && haveMoney == 'y' && likeTrucks == 'n')

{ cout << "You should buy a Porsche." << endl;

} else if (haveChildren == 'n' && haveMoney == 'y' && likeTrucks == 'y')

{ cout << "You should buy a Yukon." << endl;

22
} else if (haveChildren == 'n' && haveMoney == 'n')

{ cout << "You should buy a Civic." << endl;

} else if (haveChildren == 'y' && haveMoney == 'y' && likeTrucks == 'n')

{ cout << "You should buy a Villager." << endl;

} else if (haveChildren == 'y' && haveMoney == 'y' && likeTrucks == 'y')

{ cout << "You should buy an Explorer." << endl;

} else if (haveChildren == 'y' && haveMoney == 'n') {

cout << "You should buy a Sentra." << endl;

} else {

cout << "Sorry, we couldn't match a car for you." << endl;

return 0;

Output:
Case 1:
Do you have children? (y/n): n

Do you have lots of money? (y/n): y

Do you like trucks? (y/n): n

You should buy a Porsche.

Case 2:
Do you have children? (y/n): y

Do you have lots of money? (y/n): n

Do you like trucks? (y/n): y

You should buy a Sentra.

23
EXPERIMENT – 8
EXPERIMENT TITLE: Create a tool to calculate the circle's area and circumference. create a class called
Circle that has private member variables for radius. Include member functions to calculate the circle's area and
circumference.

Code:
#include <iostream>
#include <cmath>
using namespace std;

class Circle {

private:

double radius;

public:

// Constructor to initialize the radius

Circle(double r) {

if (r >= 0)

{ radius =

r;

} else {

cout << "Radius cannot be negative. Setting radius to 0." << endl;

radius = 0;

// Function to set the radius

void setRadius(double r) {

if (r >= 0)

{ radius =

r;

} else {

cout << "Radius cannot be negative. Please enter a valid radius." << endl;

24
}

25
}

// Function to get the radius

double getRadius() const {

return radius;

// Function to calculate the area of the circle

double calculateArea() const {

return M_PI * radius * radius; // M_PI is a constant for pi from <cmath>

// Function to calculate the circumference of the circle

double calculateCircumference() const {

return 2 * M_PI * radius;

};

int main()

{ double

radius;

// Prompt user for radius

cout << "Enter the radius of the circle: ";

cin >> radius;

// Create a Circle object

Circle circle(radius);

// Display the area and circumference

26
cout << "Circle's Area: " << circle.calculateArea() << endl;

27
cout << "Circle's Circumference: " << circle.calculateCircumference() << endl;

return 0;

Output:
Case 1:
Enter the radius of the circle: 5

Circle's Area: 78.5398

Circle's Circumference: 31.4159

Case 2:
Enter the radius of the circle: -3

Radius cannot be negative. Setting radius to 0.

Circle's Area: 0

Circle's Circumference: 0

28
EXPERIMENT – 9
EXPERIMENT TITLE: Create a tool that can give sum of given numbers (2,3 or 4). with function
overloading.

Code:
#include <iostream>

using namespace std;

class SumCalculator {

public:

// Function to calculate the sum of 2 numbers

int calculateSum(int a, int b) {

return a + b;

// Function to calculate the sum of 3 numbers

int calculateSum(int a, int b, int c) {

return a + b + c;

// Function to calculate the sum of 4 numbers

int calculateSum(int a, int b, int c, int d) {

return a + b + c + d;

};

int main() {

SumCalculator calculator;

int choice;

cout << "Enter the number of values you want to sum (2, 3, or 4): ";

29
cin >> choice;

if (choice == 2) {

int num1,

num2;

cout << "Enter two numbers: ";

cin >> num1 >> num2;

cout << "Sum: " << calculator.calculateSum(num1, num2) << endl;

} else if (choice == 3) {

int num1, num2, num3;

cout << "Enter three numbers: ";

cin >> num1 >> num2 >> num3;

cout << "Sum: " << calculator.calculateSum(num1, num2, num3) << endl;

} else if (choice == 4) {

int num1, num2, num3, num4;

cout << "Enter four numbers: ";

cin >> num1 >> num2 >> num3 >> num4;

cout << "Sum: " << calculator.calculateSum(num1, num2, num3, num4) << endl;

} else {

cout << "Invalid choice. Please enter 2, 3, or 4." << endl;

return 0;

Output:
Case 1:
Enter the number of values you want to sum (2, 3, or 4):

2 Enter two numbers: 5 7

Sum: 12

21
0
Case 2:
Enter the number of values you want to sum (2, 3, or 4):

3 Enter three numbers: 1 2 3

Sum: 6

Case 3:
Enter the number of values you want to sum (2, 3, or 4):

4 Enter four numbers: 4 5 6 7

Sum: 22

21
1
EXPERIMENT – 10
EXPERIMENT TITLE: Illustrate with example, how to overload increment operator.

Code:
#include <iostream>

using namespace std;

class Counter {

private:

int count;

public:

// Constructor to initialize count

Counter(int c = 0) : count(c) {}

// Overloading the pre-increment operator (++obj)

Counter& operator++() {

++count; // Increment count

return *this; // Return updated object

// Overloading the post-increment operator (obj++)

Counter operator++(int) {

Counter temp = *this; // Store current state

++count; // Increment count

return temp; // Return old state

// Display function to print the

count void display() const {

3
0
cout << "Count: " << count << endl;

};

int main()

{ Counter

obj(5);

cout << "Initial state: ";

obj.display();

// Pre-increment

++obj;

cout << "After pre-increment (++obj): ";

obj.display();

// Post-increment

obj++;

cout << "After post-increment (obj++): ";

obj.display();

return 0;

Output:
Initial state: Count: 5

After pre-increment (++obj): Count: 6

After post-increment (obj++): Count: 7

31
EXPERIMENT – 11
EXPERIMENT TITLE: Implement a class called Shape with member functions for calculating area and
perimeter. Derive classes such as Circle, Rectangle, and Triangle from the Shape class and overload functions
accordingly.

Code:
#include <iostream>
#include <cmath>
using namespace std;

// Base class: Shape

class Shape {

public:

// Virtual functions for area and perimeter

virtual double calculateArea() const = 0;

virtual double calculatePerimeter() const = 0;

// Virtual destructor

virtual ~Shape() {}

};

// Derived class: Circle

class Circle : public Shape {

private:

double radius;

public:

Circle(double r) : radius(r) {}

double calculateArea() const override

{ return M_PI * radius * radius;

32
double calculatePerimeter() const override

{ return 2 * M_PI * radius;

};

// Derived class: Rectangle

class Rectangle : public Shape {

private:

double length, width;

public:

Rectangle(double l, double w) : length(l), width(w) {}

double calculateArea() const override

{ return length * width;

double calculatePerimeter() const override

{ return 2 * (length + width);

};

// Derived class: Triangle

class Triangle : public Shape {

private:

double a, b, c; // Sides of the triangle

public:

Triangle(double side1, double side2, double side3) : a(side1), b(side2), c(side3) {}

33
double calculateArea() const override {

double s = (a + b + c) / 2; // Semi-perimeter

return sqrt(s * (s - a) * (s - b) * (s - c)); // Heron's formula

double calculatePerimeter() const override

{ return a + b + c;

};

int main()

{ Shape*

shape;

// Circle

shape = new Circle(5);

cout << "Circle Area: " << shape->calculateArea() << endl;

cout << "Circle Perimeter: " << shape->calculatePerimeter() << endl;

delete shape;

// Rectangle

shape = new Rectangle(4, 7);

cout << "Rectangle Area: " << shape->calculateArea() << endl;

cout << "Rectangle Perimeter: " << shape->calculatePerimeter() << endl;

delete shape;

// Triangle

shape = new Triangle(3, 4, 5);

cout << "Triangle Area: " << shape->calculateArea() << endl;

34
cout << "Triangle Perimeter: " << shape->calculatePerimeter() << endl;

35
delete shape;

return 0;

Output:
Circle Area: 78.5398

Circle Perimeter: 31.4159

Rectangle Area: 28

Rectangle Perimeter: 22

Triangle Area: 6

Triangle Perimeter: 12

36
EXPERIMENT – 12
EXPERIMENT TITLE: Implement a stack using an array with push and pop operations. Find the top element
of the stack and check if the stack is empty or not.

Code:
#include <iostream>

using namespace std;

class Stack {

private:

int* arr; // Pointer to the stack array

int topIndex; // Index of the top

element

int capacity; // Maximum capacity of the stack

public:

// Constructor to initialize the stack

Stack(int size) {

capacity = size;

arr = new int[capacity];

topIndex = -1; // Stack is initially empty

// Destructor to clean up dynamically allocated memory

~Stack() {

delete[] arr;

// Push operation: Add an element to the top of the stack

void push(int value) {

if (topIndex == capacity - 1) {

37
cout << "Stack Overflow! Cannot push " << value << "." << endl;

38
return;

arr[++topIndex] = value;

// Pop operation: Remove the top element from the stack

void pop() {

if (isEmpty()) {

cout << "Stack Underflow! Cannot pop from an empty stack." << endl;

return;

topIndex--;

// Top operation: Get the top element of the stack

int top() const {

if (isEmpty()) {

cout << "Stack is empty! No top element." << endl;

return -1; // Returning -1 to indicate an error

return arr[topIndex];

// isEmpty operation: Check if the stack is empty

bool isEmpty() const {

return topIndex == -1;

// Size operation: Get the number of elements in the stack

int size() const {

39
return topIndex + 1;

};

int main() {

Stack stack(5); // Create a stack with a maximum capacity of 5

// Push elements into the stack

stack.push(10);

stack.push(20);

stack.push(30);

// Get the top element

cout << "Top element: " << stack.top() << endl;

// Pop an element

stack.pop();

cout << "Top element after pop: " << stack.top() << endl;

// Check if the stack is empty

if (stack.isEmpty()) {

cout << "Stack is empty." << endl;

} else {

cout << "Stack is not empty." << endl;

// Push more elements to demonstrate overflow

stack.push(40);

stack.push(50);

stack.push(60); // This will trigger a stack overflow

31
0
return 0;

Output:
Top element: 30

Top element after pop: 20

Stack is not empty.

Stack Overflow! Cannot push 60.

31
1
EXPERIMENT – 13
EXPERIMENT TITLE: For the doctor's clinic create a waiting list of patients as per their arrival (FCFS) and
find out total no. of persons in waiting queue.

Code:
#include <iostream>
#include <queue>
#include <string>
using namespace std;

class ClinicQueue {

private:

queue<string> patientQueue;

public:

// Add a patient to the waiting list

void addPatient(const string& name)

patientQueue.push(name);

cout << "Patient " << name << " added to the waiting list." << endl;

// Serve the next patient

void servePatient() {

if (patientQueue.empty()) {

cout << "No patients in the waiting list." << endl;

} else {

cout << "Serving patient: " << patientQueue.front() << endl;

patientQueue.pop();

4
0
// Get the total number of patients in the queue

4
0
int totalPatients() const {

return patientQueue.size();

// Display the waiting list

void displayQueue() const {

if (patientQueue.empty()) {

cout << "The waiting list is empty." << endl;

} else {

queue<string> tempQueue = patientQueue; // Copy to avoid modifying the original queue

cout << "Current waiting list:" << endl;

while (!tempQueue.empty()) {

cout << tempQueue.front() << endl;

tempQueue.pop();

};

int main() {

ClinicQueue clinic;

int choice;

string name;

do {

cout << "\n--- Doctor's Clinic Menu ---" << endl;

cout << "1. Add Patient" << endl;

cout << "2. Serve Patient" << endl;

cout << "3. Show Total Patients" << endl;

cout << "4. Display Waiting List" << endl;

41
cout << "5. Exit" << endl;

cout << "Enter your choice:

"; cin >> choice;

switch (choice)

{ case 1:

cout << "Enter patient's name: ";

cin.ignore();

getline(cin, name);

clinic.addPatient(name);

break;

case 2:

clinic.servePatient();

break;

case 3:

cout << "Total patients in the queue: " << clinic.totalPatients() << endl;

break;

case 4:

clinic.displayQueue();

break;

case 5:

cout << "Exiting the program. Have a nice day!" << endl;

break;

default:

cout << "Invalid choice. Please try again." << endl;

} while (choice != 5);

return 0;

42
Output:
--- Doctor's Clinic Menu ---

1. Add Patient

2. Serve Patient

3. Show Total Patients

4. Display Waiting List

5. Exit

Enter your choice: 1

Enter patient's name: John Doe

Patient John Doe added to the waiting list.

--- Doctor's Clinic Menu ---

1. Add Patient

2. Serve Patient

3. Show Total Patients

4. Display Waiting List

5. Exit

Enter your choice: 1

Enter patient's name: Jane Smith

Patient Jane Smith added to the waiting list.

--- Doctor's Clinic Menu ---

1. Add Patient

2. Serve Patient

3. Show Total Patients

4. Display Waiting List

5. Exit
Enter your choice: 4

Current waiting list:

43
John Doe

Jane Smith

--- Doctor's Clinic Menu ---

1. Add Patient

2. Serve Patient

3. Show Total Patients

4. Display Waiting List

5. Exit

Enter your choice: 2

Serving patient: John Doe

--- Doctor's Clinic Menu ---

1. Add Patient

2. Serve Patient

3. Show Total Patients

4. Display Waiting List

5. Exit

Enter your choice: 3

Total patients in the queue: 1

44
EXPERIMENT – 14
EXPERIMENT TITLE: Create a list of even nos. from 1 to 20 without using array.

Code:
#include <iostream>
using namespace std;

int main() {

cout << "Even numbers from 1 to 20:" << endl;

for (int i = 1; i <= 20; ++i) {

if (i % 2 == 0) {

cout << i << " ";

cout << endl;

return 0;

Output:
Even numbers from 1 to 20:

2 4 6 8 10 12 14 16 18 20

45
EXPERIMENT – 15
EXPERIMENT TITLE: How can you navigate, open, and manipulate files on your computer
without using GUI.
To navigate, open, and manipulate files on a computer without using a Graphical User Interface
(GUI), you typically rely on the command-line interface (CLI). Here are key concepts and steps:

1. Navigation using Command Line (CLI)


Change Directory (cd):
cd command is used to navigate directories.
Example: cd /path/to/directory to switch to a specific directory.

List Files and Directories (ls):


ls command displays the contents of a directory.
Example: ls -l for detailed listing.

List Drives (in Windows):


Use dir in Windows to list files and directories.

2. File Operations
Create a File:
touch filename.txt (in Linux/Mac)
type nul > filename.txt (in Windows)

Open a File:
Use a text editor like nano, vim, or notepad.
Example: nano filename.txt to open a file in Linux.

Copy Files:
cp source.txt destination.txt (Linux/Mac)
46
copy source.txt destination.txt (Windows)

Move Files:
mv source.txt destination/ (Linux/Mac)
move source.txt destination/ (Windows)

Delete Files:
rm filename.txt (Linux/Mac)
del filename.txt (Windows)

View File Content:


cat filename.txt (Linux/Mac)
type filename.txt (Windows)

3. File Manipulation Commands


Search for Files:
find /path/to/search -name "filename.txt" (Linux/Mac)
dir /s /p filename.txt (Windows)

Archive Files (Compress):


tar -czvf archive.tar.gz filename.txt (Linux/Mac)
zip archive.zip filename.txt (Windows)

Extract Files:
tar -xzvf archive.tar.gz
(Linux/Mac) unzip archive.zip
(Windows)

47
EXPERIMENT – 16
EXPERIMENT TITLE: How to :1) List all the processes running. 2) Change the file permissions of the
directories. 3) check disk space usage. 4) List all the partitions on your system.

1. List all the processes running


Use the following commands:
ps command:
ps aux
a shows processes for all users.
u displays user-oriented format.
x lists processes not attached to a terminal.
top command:
top
Displays real-time process usage and system statistics.
htop command (if installed):
htop
An interactive and user-friendly process viewer.
pidof command (for specific processes):
pidof <process_name>

2. Change file permissions of directories


Use the chmod command:
To set specific permissions:
chmod 755 directory_name
7 = read, write, execute (owner).
5 = read, execute (group and others).
To recursively change permissions for all subdirectories:
chmod -R 755 directory_name
To grant only specific permissions:
Add execute permission:
chmod +x directory_name

48
Remove write permission:
chmod -w directory_name

3. Check disk space usage


Use the df and du commands:
df command (disk free):
df -h
-h: human-readable format.
du command (disk usage):
du -sh directory_name
-s: summary for the directory.
-h: human-readable format.

4. List all the partitions on your system


Use the following commands:
lsblk command:
lsblk
Displays block devices, partitions, and mount points.
fdisk command:
sudo fdisk -l
Lists partition tables of all disks.
blkid command:
blkid
Lists detailed information about partitions and UUIDs.
parted command:
sudo parted -l
Shows partition details for all storage devices.

49

You might also like