I’m a 3rd semester student who is struggling with object oriented programming as our teacher is not helpful in elaborating his lectures.
This is the main cpp
#include "bank.h"
#include<iostream>
using namespace std;
bonk objeExpansion(bonk& obj, int i)
{
bonk* obj2 = new bonk[i];
for (int j = 0; j < i-1; j++)
{
obj2[j] = obj[j];
}
}
int main()
{
int i = 0;
bonk* obj = new bonk[0];
while (true)
{
cout << "What do you want to enter do:n1.Add Usern2.View Usern3.Exit";
int* inp = new int{ -1 };
cin >> *inp;
if (*inp == 1)
{
i++;
system("pause");
int* acnum = new int{ 0 };
float* bal = new float{ 0 };
char* nm = new char[25]{};
cout << "Enter Name: ";
cin.getline(nm, 25);
cout << "Enter Account num: ";
cin >> *acnum;
cout << "Enter balance: ";
cin >> *bal;
}
else if (*inp == 2)
{
if (i > 0)
{
cout << "We currently have these Unlucky People in our database:n";
for (int j = 0; j < i; j++)
{
cout << *(obj[i].getName());
}
}
else
{
cout << "There is no one in the DB rn. Sad :(n";
}
}
else
{
delete inp;
break;
}
system("pause");
}
return 0;
}
This is the header cpp:
#include "bank.h"
#include "iostream"
using namespace std;
bonk::bonk()
{
accNum = 0;
balance = 0;
HoldersName = NULL;
}
bonk::~bonk()
{
delete[] HoldersName;
}
char* bonk:: getName()
{
return HoldersName;
}
This is the header file:
#ifndef rectangle_h
#define rectangle_h
class bonk {
private:
int accNum;
float balance;
char* HoldersName = new char[25]{};
public:
bonk();
~bonk();
char* getName();
};
#endif
I was expecting the program to create a bank account (initialize an object with header and then editing that later on but I guess I cant clear out the basic issues to at least make my code run. I was also expecting the objects to expand as I would be making them dynamically increase in size to insure proper need based memory optimization.
my files order just in case
Muhammad Bin Moazzam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.