Where do I stand as a programmer?

I've put several hours into the C++ language, and really I am just wondering where I stand at the moment in comparison to "most" amateur programmers. Below is some code I have wrote over the past few days and I was just wondering kind of where I stand as a programmer. Am I over the "hump"? It certainly feels like I am. I know there are SEVERAL more things for me to learn, but where would you all rate me as a programmer here, amateur? mediocre? beginner? Would I be ready to apply for an entry level programming position?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <iostream>
using namespace std;
#include <string>
#include <vector>
#include <fstream>

class Person
{
private:
	string _name;
	string _number;
	string _address;

public:
	//constructor that initializes all the private variables using parameters
	//supplied by whoever invokes this constructor
	Person(string newName, string newNumber, string newAddress)
		: _name(newName), _number(newNumber), _address(newAddress)
	{ }

	/* We cannot access any of our members in our private class since they are all set to private by default,
	so we need getters and setters to access them.*/
	// getters

	// getters are also used to restrict what the user can see
	// getters are also used to get data from our text file, then we send them to our setter to modify that data in our text file.

	string get_Name()
	{
		return _name;
	}

	string get_Address()
	{
		return _address;
	}

	string get_Number()
	{
		return _number;
	}
	
	//setters
	// setters are also used to restrict what the user can change.
	// setter can modify data in our text file. We must pass data to it through our getter.
	void set_Name(string N)
	{
		_name = N;
	}

	void set_Address(string A)
	{
		_address = A;
	}

	void set_Number(string N)
	{
		_number = N;

	}
};

class AddressBook
{
private:
	vector<Person> _people;

public:
	void addPerson(const Person& p)
	{
		_people.push_back(p);
	}
};

int main()
{
	AddressBook myAddBook;
	ofstream writetofile;
	ifstream readfromfile;
	writetofile.open("AddressBook.dat", ios::app); // opens the file for appending content to the end of it
	const int numPeopleInBook = 2;
	for (int i = 0; i < numPeopleInBook; ++i)
	{
		string nameFromUser, addressFromUser, numberFromUser;

		cout << "Give me a name: ";
		getline(cin, nameFromUser);
		writetofile << nameFromUser << endl;

		cout << "Give me a number: ";
		getline(cin, numberFromUser);
		writetofile << numberFromUser << endl;
		
		cout << "Give me an address: ";
		getline(cin, addressFromUser);
		writetofile << addressFromUser << endl;

		Person p(nameFromUser, numberFromUser, addressFromUser); // we are passing a name, number, and address of type person to our vector
		myAddBook.addPerson(p); // pushes the name, number, and address back into the vector
	}
}
You demonstrate a clear knowledge of classes and parts of the standard library. That is certainly an achievement. Other people might belittle you about your question being vague, or missing the point, but I believe I understand what you are trying to ask, and the answer is yes, you are over the hump. If you have only spent several hours on C++ (implying less than one day), then that leads me to believe you know another programming language, because that is ridiculously fast to learn an entire programming language. If that's really how long you took to learn it, you are very advanced compared to most amateur programmers - they would still struggle with input and output to the command line with less than 1 day of experience.

You are also correct that there is much more for you to learn. I would guess that you have only used the C++ standard library up until now, so compiling a third party library from source is going to be a huge challenge, as will trying to make your program statically link in certain compilers. I'd say you're doing very well so far, and don't be discouraged.

If you want actual tips about your code, I can give you those, as well. I noticed that you declared ifstream readfromfile; in your main method, but never used it. You also forgot to call writetofile.close() at the end of your main method. The address book class isn't very useful in its current form, because the user can only add people, not view them or modify them. If you just want something that behaves identically to a vector<Person> but you want it named something shorter, use typedef vector<Person> AddressBook;. You also arbitrarily defined the number of people in the book to be 2, when you could have asked the user how many people they wanted, and received their answer via cin. Writing everything to a file also seems somewhat pointless, since it is never used again in the program, but I can see how you might have wanted that to be a sort of log.

As for the actual style of your code, I like that you are using descriptive variable names, but I find starting variable names with underscores to be tedious. If you want to make it clear that you are referencing a variable inside of your class instead of a global variable, then use this->variableName (and it's good practice to do that even if you don't have a global variable of the same or similar name). I would also cut out the underscores in your variable names, and use something called camel case. Do not capitalize the first word in the variable name, but capitalize the first letter of every other word, like this: int thisIsCamelCase;. Or, you can opt to capitalize nothing, and separate words with underscores, but I highly recommend camel case.

That's all I have. Great code; keep it up, and it will come naturally to you.

Edit: I learned something today. Also, I didn't mean to advocate camel case as great for any reason other than personal preference.
Last edited on
Very clean. Well-designed. Grade: A.

JSYK, be careful with those underscores. Personally, I like it, and what you are doing here is perfectly fine. But change one of those to something like "_People" or play with it at namespace level and you're driving into 'reserved' territory.

Also, for this kind of stuff, using namespace std is just fine, but you should be aware that some people will hate you for it anyway.
http://www.cplusplus.com/faq/beginners/using-namespace-std/

I'm not exactly sure why you put it between #include directives. I have a personal habit of alphabetizing my #includes:

1
2
3
4
5
6
#include <fstream>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

When the list gets long it makes it a lot easier to manage. IMHO.

You have an extra (unused) variable in there. With streams, you are just as well to construct them when you are ready to use them:

75
76
77
78
int main()
{
	AddressBook myAddBook;
	ofstream writetofile("AddressBook.dat", ios::app);

You can fix it to accept any number of inputs with only a little extra prompting:

79
80
81
82
83
84
85
86
	while (true)
	{
		string nameFromUser, addressFromUser, numberFromuser;

		cout << "Give me a name (or just press Enter to finish): ";
		getline(cin, nameFromUser);
		writetofile << nameFromUser << endl;
		if (nameFromUser.empty()) break;

Finally, you can get actual numbers from the user in a way similar to how you get text. As I just gave in another post, a useful little routine:

1
2
3
4
5
6
7
8
9
10
#include <iostream>
#include <limits>

template <typename T>
std::istream& inputline( std::istream& ins, T& value )
{
	ins >> value;
	ins.ignore( std::numeric_limits <std::streamsize> ::max(), '\n' );
	return ins;
}

You can use it:

79
80
81
82
83
	while (true)
	{
		string   nameFromUser;
		string   addressFromUser;
		unsigned numberFromUser;
90
91
92
		cout << "Give me a number: ";
		inputline(cin, numberFromUser);
		writetofile << numberFromUser << endl;

Things to think about.

Good job!

[edit] Responses to Wyboth
You should only rarely need to explicitly close() your streams -- let RAII do that. OP's code is correct.

Also, the typedef changes the meaning of the code. Your 'AddressBook' type is not the same as his 'AddressBook'. OP's code is correct.

Don't give this->one_size_fits_all rules without reason. It is not good practice; places where they do it to fix something in their code shows that there is something wrong with their code structure or that they've been infected with suits.

Also, why the injunction for camelCase? Because you like it? That's not a good enough reason to disparage his naming style. Personally, iFindCamelCaseExceptionallyHardToRead. As he isn't doing anything wrong with his naming, and no alternative exists that is superior, I don't think there's any reason to "highly recommend" it, outside of your own personal preferences. If you are going to suggest them, make sure to be clear that it is your preference, and not something industry-normal, as per his Q.
Last edited on
Thank you all for the responses, I will look into your suggestions :)

By the way, I didn't mean that I learned all of that in one day, I have taken two C++ classes and have been doing C++ programming for 5 or 6 months now.

............

To be honest with you all though, I plan to go into JAVA after I pass another C++ course I am taking. The reasoning behind this the only places I can seem people using C++ code for is in video games, Operating systems, etc. Large scale powerful project. I like C++ and it is powerful code, but I think JAVA will cover a bit larger area as far as job opportunities. What do you all think?

P.S. sorry for bringing up JAVA on a C++ website, I'm sure you all hate that ;)
closed account (48T7M4Gy)
i_do_not_Find_Camel_Case_Exceptionally_Hard_To_Read_And_this_example_just_as_ridiculous_to_demonstrate_it_so_there
P.S. sorry for bringing up JAVA on a C++ website, I'm sure you all hate that ;)
We are software developers and it's very important to pick the right tool for a certain task to be "good".
So no, we won't hate you for mentioning Java, it's just another tool with some advantages and disadvantages.

but I think JAVA will cover a bit larger area as far as job opportunities.
yeah i think so as well

To be honest with you all though, I plan to go into JAVA after I pass another C++ course I am taking.
You can't be a good software developer when you only know 1 language anyway so yeah, just do it, you'll learn many new things, you'll miss some things but you'll love some things.

The reasoning behind this the only places I can seem people using C++ code for is in video games, Operating systems, etc. Large scale powerful project.
Yeah, it seems that way because these are places where C/C++ is used over 90% of the time BUT that's not the only place you'll find C/C++.
- Real-time audio signal processing or general data signal processing?
- microcontrollers?

The problem I often have when talking with people about C++ is that most of the people don't know that C++ is not C anymore, it has gotten much better (see for example the new standard C++11).
There are some things you can do in C++ but not in Java (at least when looking at the standard libraries).
That being said you can still do almost everything in Java.

Each tool has it's advantages and disadvantages, C++ is not perfect and neither is Java.
Last edited on
1
2
3
Person(string newName, string newNumber, string newAddress)
		: _name(newName), _number(newNumber), _address(newAddress)
	{ }

These parameters are passed by value, which means the program has to allocate space for each string, copy it, and deallocate the space when it's done. It's more efficient to pass the parameters by const reference:
1
2
3
Person(const string &newName, const string &newNumber, const string &newAddress)
		: _name(newName), _number(newNumber), _address(newAddress)
	{ }

The same is true for the getters and setters. The parameters should be passed by const reference, the return value should (maybe) be a const reference.

1
2
	//constructor that initializes all the private variables using parameters
	//supplied by whoever invokes this constructor 

Comments are one of the most important parts of professional coding (IMHO). While this comment may be helpful to you as a beginner, please recognize that it doesn't say anything that a casual reading of the code won't reveal. What's missing in your comments is a description of what the classes are. (Okay, for these classes it's pretty obvious).

A nice rule of thumb is to remember that the code itself says *what* it's doing but not *why*. The comments should give your intention.

You should understand the reasons for having getters and setters. In my opinion they are highly overused. If your getter/setter just get & set a member without doing anything else then think carefully about whether you actually need it. With getters/setters, you give up some flexibility (++, --, take address or reference (maybe)). In my experience, they are usually not needed, or not worth it.
I can see c/c++ being the future of robotics. Even right now most OS are made in c/c++ for embedded systems. Its something that if your learning it already to keep going with that. There is lots of money in java as well. c/c++ strength is its speed and low use of system resources. You wont see much from java in the robotic area and you see less and less of c++ in the gamming area even though its being used today in 3d gamming engines for its speed.
Hey Outlaw:

Great start! You'll learn a lot from the people on this site, as I have (and I'm old!).

Good luck to you in all of your learning!
Topic archived. No new replies allowed.