Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
dnyanesh1011 authored Dec 11, 2024
0 parents commit e034e1a
Show file tree
Hide file tree
Showing 7 changed files with 611 additions and 0 deletions.
70 changes: 70 additions & 0 deletions Class_Publication.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#include <iostream>
using namespace std;

class publication {
public:
string title;
float prize;

void getdata() {
cout << "Enter Name of Publication: ";
cin >> title;
cout << "Enter Price of Publication: ";
cin >> prize;
cout << endl;
}

void putdata() {
cout << "Publication Title: " << title << endl;
cout << "Publication Price: " << prize << endl;
}
};

class book : public publication {
public:
int pagecount;

void getdata() {
publication::getdata();
cout << "Enter Book Page Count: ";
cin >> pagecount;
cout << endl;
}

void putdata() {
publication::putdata();
cout << "Book Page Count: " << pagecount << endl;
cout << endl;
}
};

class tape : public publication {
private:
float ptime;

public:
void getdata() {
publication::getdata();
cout << "Enter Tape Playing Time (Minutes): ";
cin >> ptime;
cout << endl;
}

void putdata() {
publication::putdata();
cout << "Tape Playing Time: " << ptime << " min" << endl;
cout << endl;
}
};

int main() {
book b;
tape t;

b.getdata();
t.getdata();
b.putdata();
t.putdata();

return 0;
}
68 changes: 68 additions & 0 deletions Complex.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#include <iostream>
using namespace std;

class complex {
float realp, imagp;

public:
complex() {
realp = 0;
imagp = 0;
}

complex(float x, float y) {
realp = x;
imagp = y;
}

complex operator+(complex &);
complex operator*(complex &);

friend istream &operator>>(istream &, complex &);
friend ostream &operator<<(ostream &, const complex &);
};

istream &operator>>(istream &din, complex &c) {
cout << "Enter real part of complex number: ";
din >> c.realp;
cout << "Enter imaginary part of complex number: ";
din >> c.imagp;
return din;
}

ostream &operator<<(ostream &dout, const complex &c) {
dout << c.realp << " + " << c.imagp << "i";
return dout;
}

complex complex::operator+(complex &c) {
complex temp;
temp.realp = realp + c.realp;
temp.imagp = imagp + c.imagp;
return temp;
}

complex complex::operator*(complex &c) {
complex mul;
mul.realp = (realp * c.realp) - (imagp * c.imagp);
mul.imagp = (imagp * c.realp) + (realp * c.imagp);
return mul;
}

int main() {
complex c1, c2, c3;

cout << "Enter complex number 1" << endl;
cin >> c1;

cout << "Enter complex number 2" << endl;
cin >> c2;

c3 = c1 + c2;
cout << "Addition of two complex numbers is: " << c3 << endl;

c3 = c1 * c2;
cout << "Multiplication of two complex numbers is: " << c3 << endl;

return 0;
}
179 changes: 179 additions & 0 deletions Constructor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
#include <iostream>
#include <cstring>
#include <iomanip>
using namespace std;

class db {
int roll;
char name[20];
char Class[10];
char Div[10];
char dob[10];
char bg[3], contact[10];
char phone[10], license[12];

public:
static int stdno;

static void count() {
cout << "No. of objects created: " << stdno << endl;
}

void fin() { cout << "Inline Function!" << endl; }

db() {
roll = 0;
strcpy(name, "Sachin");
strcpy(Class, "I");
strcpy(Div, "A");
strcpy(dob, "11/11/1111");
strcpy(bg, "A");
strcpy(contact, "city");
strcpy(phone, "9000000000");
strcpy(license, "A0101010");
++stdno;
}

db(db* ob) {
strcpy(name, ob->name);
strcpy(dob, ob->dob);
strcpy(Class, ob->Class);
strcpy(Div, ob->Div);
strcpy(bg, ob->bg);
strcpy(contact, ob->contact);
strcpy(phone, ob->phone);
strcpy(license, ob->license);
++stdno;
}

void getdata() {
cout << "Enter Name Of Student: ";
cin >> name;
cout << "Enter Roll Number: ";
cin >> roll;
cout << "Enter Class: ";
cin >> Class;
cout << "Enter Division: ";
cin >> Div;
cout << "Enter Date Of Birth: ";
cin >> dob;
cout << "Enter Blood Group: ";
cin >> bg;
cout << "Enter Address: ";
cin >> contact;
cout << "Enter Contact Number: ";
cin >> phone;
cout << "Enter License No.: ";
cin >> license;
}

friend void display(const db& d);

~db() {
cout << this->name << "(Object) is destroyed!" << endl;
}
};

void display(const db& d) {
cout << setw(12) << "Index" << setw(12) << "Name" << setw(12) << "Roll"
<< setw(10) << "Class" << setw(8) << "Div" << setw(12) << "DOB"
<< setw(5) << "Blood Group" << setw(12) << "Contact" << setw(12) << "Phone"
<< setw(12) << "License" << endl;

cout << setw(12) << 0 << setw(12) << d.name << setw(12) << d.roll
<< setw(10) << d.Class << setw(8) << d.Div << setw(12) << d.dob
<< setw(5) << d.bg << setw(12) << d.contact << setw(12) << d.phone
<< setw(12) << d.license << endl;
}



int db::stdno = 0;

int main() {
db defaultObj;
cout << "Default values of the object: ";
cout<<endl;
display(defaultObj);

int n, i, delIndex;
cout << "How many objects do you want to create?: ";
cin >> n;
db** ptr = new db*[n];
for (i = 0; i < n; i++) {
ptr[i] = new db();
ptr[i]->getdata();
}
cout << setw(12) << "Index" << setw(12) << "Name" << setw(5) << "Roll" << setw(4) << "Class" << setw(4) << "Div" << setw(12) <<
"DOB" << setw(4) << "Blood Group" << setw(12) << "Contact" << setw(12) << "Phone" << setw(12) << "License" << endl;
for (i = 0; i < n; i++) {
cout << setw(12) << i;
display(*ptr[i]);
}
db::count();

char choice;
do {
cout << "**Menu**";
cout << "1. Add new object";
cout << "2. Delete an object";
cout << "3. Exit";
cout << "Enter your choice: ";
cin >> choice;
switch (choice) {
case '1': {
db** newPtr = new db*[n + 1];
for (i = 0; i < n; i++) {
newPtr[i] = ptr[i];
}
newPtr[n] = new db();
newPtr[n]->getdata();
ptr = newPtr;
n++;
cout << setw(12) << "Index" << setw(12) << "Name" << setw(5) << "Roll" << setw(4) << "Class" << setw(4) << "Div" << setw(12) <<
"DOB" << setw(4) << "Blood Group" << setw(12) << "Contact" << setw(12) << "Phone" << setw(12) << "license" << endl;
for (i = 0; i < n; i++) {
cout << setw(12) << i;
display(*ptr[i]);
}
db::count();
break;
}
case '2': {
cout << "Enter the index of the object you want to delete (0 to " << n - 1 << "): ";
cin >> delIndex;
if (delIndex >= 0 && delIndex < n) {
delete ptr[delIndex];
ptr[delIndex] = NULL;
cout << "Object at index " << delIndex << " deleted!" << endl;
} else {
cout << "Invalid index!" << endl;
}

cout << "Remaining objects:" << endl;
for (i = 0; i < n; i++) {
if (ptr[i] != NULL) {
cout << setw(12) << i;
display(*ptr[i]);
}
}
break;
}
case '3': {
cout << "Exiting program." << endl;
break;
}
default:
cout << "Invalid choice!" << endl;
break;
}
} while (choice != '3');

for (i = 0; i < n; i++) {
if (ptr[i] != NULL) {
delete ptr[i];
}
}
delete[] ptr;
return 0;
}
57 changes: 57 additions & 0 deletions Employee_File.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#include<iostream>
#include<fstream>
using namespace std;

class employee {
char name[20];
int ID;
double salary;

public:
void accept() {
cout << "Enter name: ";
cin >> name;
cout << "Enter ID: ";
cin >> ID;
cout << "Enter salary: ";
cin >> salary;
cout<<endl;
}

void display() {
cout << "Name: " << name <<endl;
cout << "ID: " << ID <<endl;
cout << "Salary: " << salary << endl;
cout<<endl;
}
};

int main() {
employee o[5];
fstream f;
int i, n;

cout << "How many employee information do you need to store? ";
cin >> n;

f.open("employee.txt", ios::out | ios::binary);

cout << "Enter information of Employees:" << endl;
for(i = 0; i < n; i++) {
cout << "Enter information of Employee " << (i + 1) << ":" << endl;
o[i].accept();
f.write((char*)&o[i], sizeof(o[i]));
}
f.close();

f.open("employee.txt", ios::in | ios::binary);

cout << "Information of employees is as follows:" << endl;
for(i = 0; i < n; i++) {
f.read((char*)&o[i], sizeof(o[i]));
o[i].display();
}
f.close();

return 0;
}
Loading

0 comments on commit e034e1a

Please sign in to comment.