Skip to content

Commit 39646bc

Browse files
committed
formatting
1 parent 43ce5c7 commit 39646bc

6 files changed

Lines changed: 81 additions & 73 deletions

File tree

.vscode/settings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"C_Cpp.clang_format_fallbackStyle": "",
3+
"C_Cpp.clang_format_style": "{ BasedOnStyle: LLVM, UseTab: Never, IndentWidth: 4, ColumnLimit: 0, AlignConsecutiveAssignments: true, DerivePointerAlignment: true, InsertNewlineAtEOF: true}"
4+
}

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22

33
hello :)
44

5-
https://code.visualstudio.com/docs/cpp/config-linux#_debug-helloworldcpp
5+
https://code.visualstudio.com/docs/cpp/config-linux#_debug-helloworldcpp
6+
7+
https://clang.llvm.org/docs/ClangFormatStyleOptions.html
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <iostream>
22

3-
int main() {
3+
int main(int argc, char const *argv[]) {
44
std::cout << "Hello World!" << std::endl;;
55
return 0;
6-
}
6+
}
Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
#include "CreditCard.h" // provides CreditCard
2-
using namespace std; // make std:: accessible
1+
#include "CreditCard.h" // provides CreditCard
2+
using namespace std; // make std:: accessible
33

44
CreditCard::CreditCard(const string& no, const string& nm, int lim, double bal) {
5-
number = no;
6-
name = nm;
7-
balance = bal;
8-
limit = lim;
5+
number = no;
6+
name = nm;
7+
balance = bal;
8+
limit = lim;
99
}
10-
bool CreditCard::chargeIt(double price) { // make a charge
11-
if (price + balance > double(limit))
12-
return false; // over limit
13-
14-
balance += price;
15-
return true; // the charge goes through
10+
bool CreditCard::chargeIt(double price) {
11+
if (price + balance > double(limit))
12+
return false;
13+
14+
balance += price;
15+
return true;
1616
}
1717

18-
void CreditCard::makePayment(double payment) { // make a payment
19-
balance -= payment;
18+
void CreditCard::makePayment(double payment) {
19+
balance -= payment;
2020
}
21-
// print card information
21+
2222
ostream& operator<<(ostream& out, const CreditCard& c) {
23-
out << "Number = " << c.getNumber() << "\n"
24-
<< "Name = " << c.getName() << "\n"
25-
<< "Balance = " << c.getBalance() << "\n"
26-
<< "Limit = " << c.getLimit() << "\n";
27-
return out;
23+
out << "Number = " << c.getNumber() << "\n"
24+
<< "Name = " << c.getName() << "\n"
25+
<< "Balance = " << c.getBalance() << "\n"
26+
<< "Limit = " << c.getLimit() << "\n";
27+
return out;
2828
}
Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
#ifndef CREDIT_CARD_H // avoid repeated expansion
1+
#ifndef CREDIT_CARD_H // avoid repeated expansion
22
#define CREDIT_CARD_H
33

4-
#include <string> // provides string
5-
#include <iostream> // provides ostream
4+
#include <iostream> // provides ostream
5+
#include <string> // provides string
66

77
class CreditCard {
8-
public:
9-
CreditCard(const std::string& no, const std::string& nm, int lim, double bal=0);
10-
std::string getNumber() const { return number; }
11-
std::string getName() const { return name; }
12-
double getBalance() const { return balance; }
13-
int getLimit() const { return limit; }
8+
public:
9+
CreditCard(const std::string& no, const std::string& nm, int lim, double bal = 0); // constructor
10+
std::string getNumber() const { return number; }
11+
std::string getName() const { return name; }
12+
double getBalance() const { return balance; }
13+
int getLimit() const { return limit; }
1414

15-
bool chargeIt(double price); // make a charge
16-
void makePayment(double payment); // make a payment
17-
private: // private member data
18-
std::string number; // credit card number
19-
std::string name; // card owner's name
20-
int limit; // credit limit
21-
double balance; // credit card balance
15+
bool chargeIt(double price); // make a charge
16+
void makePayment(double payment); // make a payment
17+
private: // private member data
18+
std::string number; // credit card number
19+
std::string name; // card owner's name
20+
int limit; // credit limit
21+
double balance; // credit card balance
2222
};
2323

2424
std::ostream& operator<<(std::ostream& out, const CreditCard& c); // print card information
25-
#endif
25+
#endif
Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,37 @@
1-
#include <vector> // provides STL vector
2-
#include "CreditCard.h" // provides CreditCard, cout, string
3-
4-
using namespace std; // make std accessible
5-
6-
void testCard() { // CreditCard test function
7-
vector<CreditCard*> wallet(10); // vector of 10 CreditCard pointers
8-
9-
// allocate 3 new cards
10-
wallet[0] = new CreditCard("5391 0375 9387 5309", "John Bowman", 2500);
11-
wallet[1] = new CreditCard("3485 0399 3395 1954", "John Bowman", 3500);
12-
wallet[2] = new CreditCard("6011 4902 3294 2994", "John Bowman", 5000);
13-
14-
for (int j=1; j <= 16; j++) { // make some charges
15-
wallet[0]->chargeIt(double(j)); // explicitly cast to double
16-
wallet[1]->chargeIt(2 * j); // implicitly cast to double
17-
wallet[2]->chargeIt(double(3 * j));
18-
}
19-
20-
cout << "Card payments:\n";
21-
for (int i=0; i < 3; i++){ // make more charges
22-
cout << *wallet[i];
23-
while (wallet[i]->getBalance() > 100.0) {
24-
wallet[i]->makePayment(100.0);
25-
cout << "New balance = " << wallet[i]->getBalance() << "\n";
26-
}
27-
cout << "\n";
28-
delete wallet[i]; // deallocate storage
29-
}
1+
#include "CreditCard.h" // provides CreditCard, cout, string
2+
#include <vector> // provides STL vector
3+
4+
using namespace std; // make std accessible
5+
6+
void testCard() { // CreditCard test function
7+
vector<CreditCard *> wallet(10); // vector of 10 CreditCard pointers
8+
9+
// allocate 3 new cards
10+
wallet[0] = new CreditCard("5391 0375 9387 5309", "John Bowman", 2500);
11+
wallet[1] = new CreditCard("3485 0399 3395 1954", "John Bowman", 3500);
12+
wallet[2] = new CreditCard("6011 4902 3294 2994", "John Bowman", 5000);
13+
14+
for (int j = 1; j <= 16; j++) { // make some charges
15+
wallet[0]->chargeIt(double(j)); // explicitly cast to double
16+
wallet[1]->chargeIt(2 * j); // implicitly cast to double
17+
wallet[2]->chargeIt(double(3 * j));
18+
}
19+
20+
cout << "Card payments:\n";
21+
for (int i = 0; i < 3; i++) { // make more charges
22+
cout << *wallet[i];
23+
24+
while (wallet[i]->getBalance() > 100.0) {
25+
wallet[i]->makePayment(100.0);
26+
cout << "New balance = " << wallet[i]->getBalance() << "\n";
27+
}
28+
29+
cout << "\n";
30+
delete wallet[i]; // deallocate storage
31+
}
3032
}
3133

32-
int main() { // main function
33-
testCard();
34-
return EXIT_SUCCESS; // successful execution
35-
}
34+
int main(int argc, char const *argv[]) {
35+
testCard();
36+
return EXIT_SUCCESS; // successful execution
37+
}

0 commit comments

Comments
 (0)