Holy <img src="/xxx.gif"><img src="/xxx.gif"><img src="/xxx.gif"><img src="/xxx.gif">. It's a good thing I'm not in that class. I'd fail.
Holy <img src="/xxx.gif"><img src="/xxx.gif"><img src="/xxx.gif"><img src="/xxx.gif">. It's a good thing I'm not in that class. I'd fail.
Leave some shards under the belly
Lay some grease inside my hand
It's a sentimental jury
And the makings of a good plan
scratch that. I already did the seq files.
Now I need to create a "balance class" for the atm program. This class should receive the current balance for an account(savings or checking) and the amount of the transaction from your program and return the updated balance. This class should be utilized every time a balance changes. To simplify the use of the class you should send negative values to the class for withdrawals and positive values for deposits.
Any suggestions? This is a new type of programming that is getting me thinking a lot.
im asking where do i start to develop my balance class
this is what I got. I made a whole different class and he told me it was way too complicated.
#ifndef _BALANCE_H
#define _BALANCE_H
class balance
{
public:
balance();
float getBalance();
float sendBalance();
private:
float returnBalance();
};
This is a program that will ask the user to pick a state, capital, date of unionization, and the postal abbreviation. This will use the vector class and I will use a data file. What is wrong with my program? It has no errors, though. When I type a state nothing shows up.
data file belowCode:#include <string> #include <conio.h> #include <iostream> #include <fstream> #include "vector.h" using namespace std; struct US { char KeyIn[50]; char Abb[50]; char Name[50]; char Capital[50]; char Union[50]; }; vector <US> States(50); //function declarations void Intro(); void UserInter(US &a); void GetData(US &a); void Result(US &a); //main functions int main() { US a; Intro(); UserInter(a); GetData(a); Result(a); getch(); return 0; } void Intro() { cout << "This is the state program. Enter the postal abbreviation, "; cout << "capital, state, or the\ndate in which the state entered "; cout << "the union. "; cin.get(); system("cls"); } void UserInter(US &a) { system("cls"); //Gets user's search term cout << "Key in one of the things please. "; cin.get(a.KeyIn, 50); cin.ignore(80, '\n'); system("cls"); } void GetData(US &a) { ifstream infile; infile.open("NAME_QUIZ3.DAT", ios::in); int i = 0; while(!infile.eof()) { //Abbreviation infile.get(States[i].Abb, 50); infile.ignore(70, '\n'); //State infile.get(States[i].Name, 50); infile.ignore(70, '\n'); //Capital infile.get(States[i].Capital, 50); infile.ignore(70, '\n'); //Date infile.get(States[i].Union, 50); infile.ignore(70, '\n'); i++; } } void Result(US &a) { for(int b = 0; b <= 50; b++) { if(strcmp(States[b].Abb, a.KeyIn) == 0) { cout << "Postal Abbreviation: " << States[b].Abb << endl; cout << "State: " << States[b].Name << endl; cout << "Capital City: " << States[b].Capital << endl; cout << "Date of Unionization: " << States[b].Union << endl; getch(); } else if(strcmp(States[b].Name, a.KeyIn) == 0) { cout << "Postal Abbreviation: " << States[b].Abb << endl; cout << "State: " << States[b].Name << endl; cout << "Capital City: " << States[b].Capital << endl; cout << "Date of Unionization: " << States[b].Union << endl; getch(); } else if(strcmp(States[b].Union, a.KeyIn) == 0) { cout << "Postal Abbreviation: " << States[b].Abb << endl; cout << "State: " << States[b].Name << endl; cout << "Capital City: " << States[b].Capital << endl; cout << "Date of Unionization: " << States[b].Union << endl; getch(); } } }
AL Alabama Montgomery Dec. 14, 1819
AK Alaska Juneau Jan. 3,1959
AZ Arizona Phoenix Feb. 14, 1912
AR Arkansas Little Rock June 15,1836
CA California Sacramento Sept. 9, 1850
CO Colorado Denver Aug. 1, 1876
CT Connecticut Hartford Jan. 9, 1788
DE Delaware Dover Dec. 7, 1787
FL Florida Tallahassee Mar. 3, 1845
GA Georgia Atlanta Jan. 2, 1788
HI Hawaii Honolulu Aug. 21, 1959
ID Idaho Boise July 3, 1890
IL Illinois Springfield Dec. 3, 1818
IN Indiana Indianapolis Dec. 11, 1816
IA Iowa Des Moines Dec. 28, 1846
KS Kansas Topeka Jan. 29, 1861
KY Kentucky Frankfort June 1, 1792
LA Louisiana Baton Rouge Apr. 30, 1812
ME Maine Augusta Mar. 15, 1820
MD Maryland Annapolis Apr. 28, 1788
MA Massachusetts Boston Feb. 6, 1788
MI Michigan Lansing Jan. 26, 1837
MN Minnesota Saint Paul May 11, 1858
MS Mississippi Jackson Dec. 10, 1817
MO Missouri Jefferson City Aug. 10, 1821
MT Montana Helena Nov. 8, 1889
NE Nebraska Lincoln Mar. 1, 1867
NV Nevada Carson City Oct. 31, 1864
NH New Hampshire Concord June 21, 1788
NJ New Jersey Trenton Dec. 18, 1787
NM New Mexico Santa Fe Jan. 6, 1912
NY New York Albany July 26, 1788
NC North Carolina Raleigh Nov. 21, 1789
ND North Dakota Bismarck Nov. 2, 1889
OH Ohio Columbus Mar. 1, 1803
OK Oklahoma Oklahoma City Nov. 16, 1907
OR Oregon Salem Feb. 14, 1859
PA Pennsylvania Harrisburg Dec. 12, 1787
RI Rhode Island Providence May 29, 1790
SC South Carolina Columbia May 23, 1788
SD South Dakota Pierre Nov. 2, 1889
TN Tennessee Nashville June 1, 1796
TX Texas Austin Dec. 29, 1845
UT Utah Salt Lake City Jan. 4, 1896
VT Vermont Montpelier Mar. 4, 1791
VA Virginia Richmond June 25, 1788
WA Washington Olympia Nov. 11, 1889
WV West Virginia Charleston June 20, 1863
WI Wisconsin Madison May 29, 1848
WY Wyoming Cheyenne July 10, 1890
Best scenario: Program loudly does the right thing.
OK scenario: Program silently does the right thing.
Bad scenario: Program loudly does the wrong thing.
Very bad scenario: Program silently does the wrong thing and you somehow discover the problem anyways.
Worst scenario: Program silently does the wrong thing and no one figures it out (until the nuclear reactor explodes).
The fourth is what you have, so it could be worse.Silent bugs are really really bad though.
If you have a big complex multi-branch conditional like yours in the Result() function, you should put a default else{} catch-all block. Your program should never reach this else{} block unless something goes wrong. So unless you have a good reason to do otherwise, in the else{} block you should make your program print a large nasty error message and die a horrible death. (Have the program exit with a return value indicating failure.) Have the error message print as much relevant information as possible. In this case I'd have it print something like this at the very least:
Putting some kind of quoting character( my [] above ) around the output variables will let you know if you're outputting a blank string or a string full of whitespace, which is a hard bug to see visually otherwise. (A good reason to use a monospace font in your console window by the way.)Code:if(strcmp(States[b].Abb, a.KeyIn) == 0) { ... } else if(strcmp(States[b].Name, a.KeyIn) == 0) { ... } else if(strcmp(States[b].Union, a.KeyIn) == 0) { ... } else { cerr << "ERROR: invalid user input: [" << a.KeyIn << "] != [" << States[b].Abb << "] [" << States[b].Name << "] [" << States[b].Union << "]" << endl; // cleanup here if necessary (close filehandles, cleanly deallocate memory, flush buffers if necceasy etc. etc.) exit(1); }
Another possibility would be to loop and re-prompt for input until you get some that's valid, rather than just having your program kill itself. Or whatever else you'd like.
If you have access to a debugger, you can use that to do the same thing in a perhaps more helpful way. Set a breakpoint somewhere in or before the Result() function, and inspect the values of all your data structures as of that moment.
In general you should put those kind of error checks in every program you write, to cover every possible thing you can imagine that could be broken, and then some. Imagine the file doesn't exist. Imagine the file exists but is full of gibberish. Imagine a directory exists with the same name as the file you want. Imagine the file exists but you have no permissions to read it. Imagine the user enters a single space as his input. Imagine the user somehow manages to enter nothing as the input. Imagine the user enters 1000 characters of gibberish. Imagine the user enters numbers if you're expecting text, or text if you're expecting numbers.
A good program will gracefully handle all of those things. At the very least, complain loudly. At most, die a horrible death. If you build this kind of checking into your program as you write it, you will find that it's very easy to debug, and very easy for users to use (or at least easy for you to fix once the user starts complaining to you that it's broken).
As it is, your program cannot correctly read from your data file. And all these if are useless, you can do all of them at once (if cond1 or cond2 or cond 3).
Also, using Borland only functions = bleh![]()
And then there is Death