C++ -- Vector of Bank Accounts (15 pts) Please help! :(
Lab 12a Solution:
Bank.h:
#ifndef
BANK_H
#define BANK_H
#include <string>
using namespace
std;
struct Customer
//Capitalize Names of classes and
structs
{
string
name;
string
address;
};
class Bank
{
private:
Customer
customer;
int
acctNumber;
float
balance;
public:
Bank(); //default
constructor
Bank(string
_name, int
_number, float
_balance); //constructor
string
getName(){return
customer.name;}
void
setName(string
_name){customer.name=_name;}
string
getAddress(){return
customer.address;}
void
setAddress(string
_address)
{customer.address
= _address;}
int
getAcctNumber() {return
acctNumber;}
void
setAcctNumber(int
_number){acctNumber =
_number;}
float
getBalance(){return
balance;}
void
increaseBalance(float
amount);
void
print();
};
#endif
Bank.cpp:
#include "Bank.h"
#include <iostream>
using namespace
std;
Bank::Bank()
{
customer.name
= "";
customer.address
= "";
acctNumber
= 0;
balance
= 0;
}
Bank::Bank(string
_name, int
_number, float
_balance)
{
customer.name
= _name;
customer.address
= "";
//this requires that you set address after
declaring
acctNumber
= _number;
balance =
_balance;
}
void
Bank::increaseBalance(float
amount)
{
balance
= balance + amount;
}
void Bank::print()
{
cout <<
customer.name
<<endl;
cout <<
customer.address
<< endl;
cout <<
"Account Number: " <<
acctNumber <<
endl;
cout <<
"Account Balance: " <<
balance <<
endl;
}
lab12a.cpp:
#include
<iostream>
#include "Bank.h"
using namespace
std;
int main()
{
Bank
acct1("Alpha",
123,
12.50);
//constructor
Bank
acct2; //default constructor
cout
<< "After
declaring\n";
cout <<
"Account1:\n";
acct1.print();
cout
<<"\nAccount2:\n";
acct2.print();
acct1.increaseBalance(200.00);
cout <<
"After increasing
Balance\n";
cout <<
"Account1:\n";
acct1.print();
cout <<
"Since we are outside the class definition
\n";
cout <<
"we must use public member functions to access private
variables\n";
cout <<
"Acct 1: " <<
acct1.getName()
<<endl;
return
0;
}
Code and code as text for each file:
//Lab13.cpp
#include <iostream>
#include <algorithm>
#include <vector>
#include "Bank.h"
#include "functions.h"
using namespace std;
int main()
{
vector<Bank> accounts;
Bank acct1("Alpha", 123, 12.50); //constructor
Bank acct2("Beta", 456, 9.27);
Bank acct3("Gamma", 789, 11.22);
accounts.push_back(acct1);
accounts.push_back(acct2);
accounts.push_back(acct3);
cout << "Unsorted accounts are: \n\n";
for (int i = 0; i < accounts.size(); i++) {
cout << accounts[i] << endl;
}
cout << "\nSorting by account balance..\n";
SortByBalance(accounts);
cout << "Sorted accounts are: \n\n";
for (int i = 0; i < accounts.size(); i++) {
cout << accounts[i] << endl;
}
return 0;
}
//Bank.cpp
#include "Bank.h"
#include <iostream>
using namespace std;
Bank::Bank()
{
customer.name = "";
customer.address = "";
acctNumber = 0;
balance = 0;
}
Bank::Bank(string _name, int _number, float _balance)
{
customer.name = _name;
customer.address = ""; //this requires that you set address after declaring
acctNumber = _number;
balance = _balance;
}
void Bank::increaseBalance(float amount)
{
balance = balance + amount;
}
void Bank::print()
{
cout << customer.name <<endl;
cout << customer.address << endl;
cout << "Account Number: " << acctNumber << endl;
cout << "Account Balance: " << balance << endl;
}
//Bank.h
#ifndef BANK_H
#define BANK_H
#include <string>
#include <iostream>
using namespace std;
struct Customer //Capitalize Names of classes and structs
{
string name;
string address;
};
class Bank
{
private:
Customer customer;
int acctNumber;
float balance;
public:
Bank(); //default constructor
Bank(string _name, int _number, float _balance); //constructor
string getName(){return customer.name;}
void setName(string _name){customer.name=_name;}
string getAddress(){return customer.address;}
void setAddress(string _address) {customer.address = _address;}
int getAcctNumber() {return acctNumber;}
void setAcctNumber(int _number){acctNumber = _number;}
float getBalance(){return balance;}
void increaseBalance(float amount);
void print();
// overload << operator
friend ostream &operator<<(ostream &out, Bank bank) {
out << "Customer name: " << bank.customer.name << "\nAccount Number: " << bank.acctNumber << "\nBalance: " << bank.balance;
return out;
}
// overload < operator
bool operator <(Bank bank) {
if (balance < bank.balance) {
return true;
}
return false;
}
};
#endif
//functions.h
/* function to sort accounts on basis of account balance */
void SortByBalance(vector<Bank>);
//functions.cpp
#include "Bank.h"
#include <vector>
#include <algorithm>
void SortByBalance(vector<Bank> accounts) {
sort(accounts.begin(), accounts.end()); // use sort from <algorithms>
}
Sample run:
C++ -- Vector of Bank Accounts (15 pts) Please help! :( Use csegrid or Clion for...
This is assignment and code from this site but it will not compile....can you help? home / study / engineering / computer science / computer science questions and answers / c++ this assignment requires several classes which interact with each other. two class aggregations ... Question: C++ This assignment requires several classes which interact with each other. Two class aggregatio... (1 bookmark) C++ This assignment requires several classes which interact with each other. Two class aggregations are formed. The program...
Greetings, everybody I already started working in this program. I just need someone to help me complete this part of the assignment (my program has 4 parts of code: main.cpp; Student.cpp; Student.h; StudentGrades.cpp; StudentGrades.h) Just Modify only the StudentGrades.h and StudentGrades.cpp files to correct all defect you will need to provide implementation for the copy constructor, assignment operator, and destructor for the StudentGrades class. Here are my files: (1) Main.cpp #include <iostream> #include <string> #include "StudentGrades.h" using namespace std; int...
This is a c++ code /** Write a function sort that sorts the elements of a std::list without using std::list::sort or std::vector. Instead use list<int>::iterator(s) */ using namespace std; #include <iostream> #include <iomanip> #include <string> #include <list> void print_forward (list<int>& l) { // Print forward for (auto value : l) { cout << value << ' '; } cout << endl; } void sort(list<int>& l) { write code here -- do not use the built-in list sort function }...
You are given a partial implementation of two classes. GroceryItem is a class that holds the information for each grocery item. GroceryInventory is a class that holds an internal listing of GroceryItems as well as the tax rate for the store. Your inventory could be 100 items it could be 9000 items. You won’t know until your program gets the shipment at runtime. For this you should use the vector class from the C++ standard library. I've completed the GroceryItem.h...
//header files #ifndef Contact_H // header files should always have this to avoid #define Contact_H // multiple inclusion in other files #include <string> // this is the only programming assignment which will use this statement. // normally "using namespace std" is looked down upon because it // introduces many common keywords that could be accidentally used, but // it identifies useful types such as string and would normally be used // std::string or std::vector. using namespace std; class Contact...
Please zoom in so the pictures become high resolution. I need three files, FlashDrive.cpp, FlashDrive.h and user_main.cpp. The programming language is C++. I will provide the Sample Test Driver Code as well as the codes given so far in text below. Sample Testing Driver Code: cs52::FlashDrive empty; cs52::FlashDrive drive1(10, 0, false); cs52::FlashDrive drive2(20, 0, false); drive1.plugIn(); drive1.formatDrive(); drive1.writeData(5); drive1.pullOut(); drive2.plugIn(); drive2.formatDrive(); drive2.writeData(2); drive2.pullOut(); cs52::FlashDrive combined = drive1 + drive2; // std::cout << "this drive's filled to " << combined.getUsed( )...
Hi, I have C++ programming problem here: Problem: Please modify your string type vector in for push_back() function as below: void push_back(string str) { // increase vector size by one // initialize the new element with str } In addition, the standard library vector doesn't provide push_front(). Implement push_front() for your vector. Test your code with the main function below. int main() { vector v1(3); cout<<"v1: "; v1.print(); // this should display -, -, - for...
You are to implement a MyString class which is our own limited implementation of the std::string Header file and test (main) file are given in below, code for mystring.cpp. Here is header file mystring.h /* MyString class */ #ifndef MyString_H #define MyString_H #include <iostream> using namespace std; class MyString { private: char* str; int len; public: MyString(); MyString(const char* s); MyString(MyString& s); ~MyString(); friend ostream& operator <<(ostream& os, MyString& s); // Prints string MyString& operator=(MyString& s); //Copy assignment MyString& operator+(MyString&...
Subject: Object Oriented Programming (OOP) Please kindly solve the above two questions as soon as possible would be really grateful to a quick solution. would give a thumbs up. Thank you! Q3: Question # 3 [20] Will the following code compile? If it does not, state the errors. If it does compile, write the output. //Function.cpp #include <iostream> using namespace std; void printData (long i) cout<<"In long print Data "«<i<<endl; } void printData(int i) cout<<"In int printData "<<i<<endl; ) void...
C++ Language I have a class named movie which allows a movie object to take the name, movie and rating of a movie that the user inputs. Everything works fine but when the user enters a space in the movie's name, the next function that is called loops infinetly. I can't find the source of the problem. Down below are my .cpp and .h file for the program. #include <iostream> #include "movie.h" using namespace std; movie::movie() { movieName = "Not...