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

Krisa-oops_journal

Uploaded by

vsenterprise2917
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)
5 views

Krisa-oops_journal

Uploaded by

vsenterprise2917
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/ 18

ROLL NO :- 2481035 Lakkad Krisa Shaileshbhai SYBCA DIV - E

Q-1 Create a class 'Bank' comprises of data like bank_id, bank_name, brance_name and
create another class 'Account' which holds data like ac_no, ac_name, ac_type
(saving/current), and balance. Create another class 'Transaction' which holds the
functions to perform following operations:

1-Create New Account


2-Deposit & Withdraw (Min 500 balance) in particular
3-List out details of only those accounts whose type is 'saving'

Ans:-
#include <iostream>
#include <vector>
#include <string>
using namespace std;
// Define a struct to represent a bank account
struct Account {
int number; // account number
string name; // account holder's name
string type; // type of account (saving or current)
double balance; // initial balance
};

// Define a class to represent a bank


class Bank {
public:
vector<Account> accounts; // list of all accounts in the bank
// Method to create a new account
void createAccount(int ac_no, string ac_name, string ac_type, double balance) {
if (balance < 500) {
cout << "Minimum balance should be 500" << endl;
} else {
accounts.push_back({ac_no, ac_name, ac_type, balance});
cout << "Account created successfully" << endl;
}
}
// Method to deposit money into an account
void deposit(int ac_no, double amount) {
for (auto &account : accounts) {
if (account.number == ac_no) {
account.balance += amount;
cout << "Deposited " << amount << " into account " << ac_no << endl;
return;
}
}

1
ROLL NO :- 2481035 Lakkad Krisa Shaileshbhai SYBCA DIV - E

cout << "Account not found" << endl;


}
// Method to withdraw money from an account
void withdraw(int ac_no, double amount) {
for (auto &account : accounts) {
if (account.number == ac_no) {
if (account.balance >= amount) {
account.balance -= amount;
cout << "Withdrawn " << amount << " from account " << ac_no << endl;
} else {
cout << "Insufficient balance" << endl;
}
return;
}
}
cout << "Account not found" << endl;
}
// Method to list all the saving accounts
void listSavingAccounts() {
for (auto account : accounts) {
if (account.type == "saving") {
cout << "Account No: " << account.number << ", Account Name: " << account.name
<< endl;
}
}
}
};
int main() {
cout << "NAME: LAKKAD KRISA SHAILESHBHAI\n";
cout << "CLASS : SYBCA - E\n";
cout << "ROLL NO : 2481035\n";
cout << "\n";
Bank bank;
// Create two new accounts
bank.createAccount(12345, " Krisa Lakkad ", "saving", 10000);
bank.createAccount(67890, "Krisa Lakkad", "current", 20000);
// Deposit money into the first account
bank.deposit(12345, 5000);
// Withdraw money from the first account
bank.withdraw(12345, 2000);
// List all the saving accounts
bank.listSavingAccounts();

return 0;

2
ROLL NO :- 2481035 Lakkad Krisa Shaileshbhai SYBCA DIV - E

Output:-

3
ROLL NO :- 2481035 Lakkad Krisa Shaileshbhai SYBCA DIV - E

Q-2 Create a class Str which stores a string value. Overload +, == for concatenation and
comparison operation respectively.

Ans:-
#include <iostream>
#include <string>
using namespace std;
class Str {
public:
string str;
Str(string s) : str(s) {}
Str operator+(Str other) {
return Str(str + other.str);
}
bool operator==(Str other) {

return str == other.str;


}
};
int main() {

cout << "NAME: LAKKAD KRISA SHAILESHBHAI\n";


cout << "CLASS : SYBCA - E\n";
cout << "Roll No : 2481035\n";
cout << "\n";
Str s1(" Krisa ");
Str s2("Lakkad");
Str s3 = s1 + s2;
cout << s3.str << endl;
return 0;
}

Output :-

4
ROLL NO :- 2481035 Lakkad Krisa Shaileshbhai SYBCA DIV - E

Q-3 Create class using multilevel inheritance of student list 1st class contain roll no and
name of student 2nd class contain marks of three subject 3rd class contain total and
percentage Input data of at least 5 student and display all the information in proper
format.

Ans:-
#include <iostream>
#include <string>

using namespace std;

class Student {
public:
int rollNo;
string name;
int marks1, marks2, marks3;
int total;
float percentage;

void setStudentInfo(int r, string n, int m1, int m2, int m3) {


rollNo = r;
name = n;
marks1 = m1;
marks2 = m2;
marks3 = m3;
total = m1 + m2 + m3;
percentage = (float)total / 3;
}

void displayStudentInfo() {
cout << "Roll No: " << rollNo << endl;
cout << "Name: " << name << endl;
cout << "OOPS&DS: " << marks1 << endl;
cout << "DBHUP: " << marks2 << endl;
cout << "CYBER SECURITY: " << marks3 << endl;
cout << "Total: " << total << endl;
cout << "Percentage: " << percentage << "%" << endl;
}
};

int main() {
cout << "NAME: LAKKAD KRISA SHAILESHBHAI\n";
cout << "CLASS : SYBCA - E\n";
cout << "Roll No : 2481035\n";
cout << "\n";

Student students[2];

5
ROLL NO :- 2481035 Lakkad Krisa Shaileshbhai SYBCA DIV - E

students[0].setStudentInfo(1, "Krisa", 80, 70, 90);


students[1].setStudentInfo(2, "Ritika", 50, 60, 70);

for (int i = 0; i < 2; i++) {


cout << "Student " << i + 1 << ":" << endl;
students[i].displayStudentInfo();
cout << endl;
}
return 0;
}

Output :-

6
ROLL NO :- 2481035 Lakkad Krisa Shaileshbhai SYBCA DIV - E

Q-4 Create a book class (bookid, bookname, year, publication) & student class (rollno,
name, year, books). Display list of books borrowed by student from library.

Ans:-
#include <iostream>
#include <string>
#include <vector>

using namespace std;

class Book {
public:
int bookId;
string bookName;
int year;
string publication;

Book(int id, string name, int yr, string pub) {


bookId = id;
bookName = name;
year = yr;
publication = pub;
}

void displayBookInfo() {
cout << "Book ID: " << bookId << endl;
cout << "Book Name: " << bookName << endl;
cout << "Year: " << year << endl;
cout << "Publication: " << publication << endl;
}
};

class Student {
public:
int rollNo;
string name;
int year;
vector<Book> borrowedBooks;

Student(int r, string n, int yr) {


rollNo = r;
name = n;
year = yr;
}

void borrowBook(Book book) {


borrowedBooks.push_back(book);
}

7
ROLL NO :- 2481035 Lakkad Krisa Shaileshbhai SYBCA DIV - E

void displayStudentInfo() {
cout << "Roll No: " << rollNo << endl;
cout << "Name: " << name << endl;
cout << "Year: " << year << endl;
}

void displayBorrowedBooks() {
if (borrowedBooks.empty()) {
cout << "No books borrowed." << endl;
} else {
cout << "Borrowed Books:" << endl;
for (Book book : borrowedBooks) {
book.displayBookInfo();
cout << endl;
}
}
}
};

int main() {

cout << "NAME: LAKKAD KRISA SHAILESHBHAI\n";


cout << "CLASS : SYBCA - E\n";
cout << "Roll No : 2481035\n";
cout << "\n";

// Create books
Book book1(1, "J2L-OOPS", 2020, "Pub1");
Book book2(2, "STATASTICS", 2019, "Pub2");
Book book3(3, "EXPERT IN PYTHON", 2018, "Pub3");

// Create students
Student student1(1, "Krisa", 2022);
Student student2(2, "Ritika", 2021);

// Borrow books
student1.borrowBook(book1);
student1.borrowBook(book2);
student2.borrowBook(book3);

// Display student info and borrowed books


student1.displayStudentInfo();
student1.displayBorrowedBooks();
cout << endl;

student2.displayStudentInfo();
student2.displayBorrowedBooks();

8
ROLL NO :- 2481035 Lakkad Krisa Shaileshbhai SYBCA DIV - E

return 0;
}

Output :-

9
ROLL NO :- 2481035 Lakkad Krisa Shaileshbhai SYBCA DIV - E

Q-5 Create an event class, create dynamic objects of event class and release the memory
of the created object before program terminates.

Ans:-
#include <iostream>
#include <string>

using namespace std;

class Event {
public:
string eventName;
string eventDate;

Event(string name, string date) : eventName(name), eventDate(date) {}

void displayEventInfo() const {


cout << "Event Name: " << eventName << endl;
cout << "Event Date: " << eventDate << endl;
}
};

int main() {
cout << "NAME: LAKKAD KRISA SHAILESHBHAI\n";
cout << "CLASS : SYBCA - E\n";
cout << "Roll No : 2481035\n";
cout << "\n";

const int numEvents = 2; // Fixed to 2 events

Event** events = new Event*[numEvents];

for (int i = 0; i < numEvents; i++) {


string name, date;
cout << "Enter event " << i + 1 << " details:" << endl;
cout << "Name: ";
cin.ignore();
getline(cin, name);
cout << "Date: ";
getline(cin, date);

events[i] = new Event(name, date);


}

cout << "\nEvent Details:" << endl;


for (int i = 0; i < numEvents; i++) {
cout << "Event " << i + 1 << ":" << endl;
events[i]->displayEventInfo();

10
ROLL NO :- 2481035 Lakkad Krisa Shaileshbhai SYBCA DIV - E

cout << endl;


}

// Release the memory


for (int i = 0; i < numEvents; i++) {
delete events[i];
}
delete[] events;

return 0;
}

Output:-

11
ROLL NO :- 2481035 Lakkad Krisa Shaileshbhai SYBCA DIV - E

Q-6 Create a program to implement stack with its operations.

Ans:-
#include <iostream>

using namespace std;

class Stack {
private:
int arr[10];
int top;

public:
Stack() {
top = -1;
}

void push(int value) {


if (top < 9) {
arr[++top] = value;
} else {
cout << "Stack is full." << endl;
}
}

int pop() {
if (top >= 0) {
return arr[top--];
} else {
cout << "Stack is empty." << endl;
return -1;
}
}

void display() {
for (int i = 0; i <= top; i++) {
cout << arr[i] << " ";
}
cout << endl;
}
};

int main() {

cout << "NAME: LAKKAD KRISA SHAILESHBHAI\n";


cout << "CLASS : SYBCA - E\n";
cout << "Roll No : 2481035\n";
cout << "\n";

12
ROLL NO :- 2481035 Lakkad Krisa Shaileshbhai SYBCA DIV - E

Stack stack;

while (true) {
cout << "1. Push" << endl;
cout << "2. Pop" << endl;
cout << "3. Display" << endl;
cout << "4. Exit" << endl;

int choice;
cin >> choice;

switch (choice) {
case 1: {
int value;
cout << "Enter value: ";
cin >> value;
stack.push(value);
break;
}
case 2: {
int value = stack.pop();
if (value != -1) {
cout << "Popped value: " << value << endl;
}
break;
}
case 3: {
stack.display();
break;
}
case 4: {
return 0;
}
default: {
cout << "Invalid choice." << endl;
}
}
}

return 0;
}

13
ROLL NO :- 2481035 Lakkad Krisa Shaileshbhai SYBCA DIV - E

Output :-

14
ROLL NO :- 2481035 Lakkad Krisa Shaileshbhai SYBCA DIV - E

Q-7 Create a program to implement infix to postfix conversion.

Ans:-
#include <iostream>
#include <stack>
#include <string>

using namespace std;

// Function to check operator precedence


int precedence(char op) {
if (op == '+' || op == '-') return 1;
if (op == '*' || op == '/') return 2;
if (op == '^') return 3;
return 0;
}

// Function to convert infix to postfix


string infixToPostfix(string infix) {
stack<char> s;
string postfix = "";

for (char c : infix) {


if (isalnum(c)) postfix += c;
else if (c == '(') s.push(c);
else if (c == ')') {
while (s.top() != '(') {
postfix += s.top();
s.pop();
}
s.pop();
} else {
while (!s.empty() && precedence(c) <= precedence(s.top())) {
postfix += s.top();
s.pop();
}
s.push(c);
}
}

while (!s.empty()) {
postfix += s.top();
s.pop();
}

return postfix;
}

int main() {

15
ROLL NO :- 2481035 Lakkad Krisa Shaileshbhai SYBCA DIV - E

cout << "NAME: LAKKAD KRISA SHAILESHBHAI\n";


cout << "CLASS : SYBCA - E\n";
cout << "Roll No : 2481035\n";
cout << "\n";

string infix;
cout << "Enter infix expression: ";
cin >> infix;

string postfix = infixToPostfix(infix);


cout << "Postfix expression: " << postfix << endl;

return 0;
}

Output :-

16
ROLL NO :- 2481035 Lakkad Krisa Shaileshbhai SYBCA DIV - E

Q-8 Create a program to implement simple queue with its operations.

Ans:-
#include <iostream>
using namespace std;

class Queue {
private:
int queue[10]; // array to store queue elements
int front; // index of front element
int rear; // index of rear element
int count; // number of elements in queue

public:
Queue() {
front = 0;
rear = 0;
count = 0;
}

// Add element to queue


void enqueue(int value) {
if (count < 10) {
queue[rear] = value;
rear = (rear + 1) % 10;
count++;
} else {
cout << "Queue is full!" << endl;
}
}

// Remove element from queue


void dequeue() {
if (count > 0) {
front = (front + 1) % 10;
count--;
} else {
cout << "Queue is empty!" << endl;
}
}

// Display queue elements


void display() {
if (count == 0) {
cout << "Queue is empty!" << endl;
} else {
int i = front;
for (int j = 0; j < count; j++) {
cout << queue[i] << " ";

17
ROLL NO :- 2481035 Lakkad Krisa Shaileshbhai SYBCA DIV - E

i = (i + 1) % 10;
}
cout << endl;
}
}
};

int main() {

cout << "NAME: LAKKAD KRISA SHAILESHBHAI\n";


cout << "CLASS : SYBCA - E\n";
cout << "Roll No : 2481035\n";
cout << "\n";

Queue q;

// Add elements to queue


q.enqueue(10);
q.enqueue(20);
q.enqueue(30);

// Display queue elements


cout << "Queue elements: ";
q.display();

// Remove element from queue


q.dequeue();

// Display queue elements after dequeue


cout << "Queue elements after dequeue: ";
q.display();

return 0;
}

Output:-

18

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy