- Joined
- Aug 6, 2009
- Messages
- 2,132
- Reaction score
- 429
So before I started college I wanted to get a hang of C++ programming. Syntax was easy and general code writing was piece of cake, but when you get into objects, pointers, arrays it get's too complicated and you simply give up. That's what I did.
Well now that I am taking CS in college, and this is only week 3, I can say that it has been the most progressive week in learning c++ programming. Why?
When you get into a CS class a professor will set a requirments for your labs/assignments. For example my class we are not allowed to use string or vector, and simply can't use stdio library.
Well crap, how do you output a string? How do you keep a list of objects? This is when you actually learn. What I am saying is, when you have to implement your own objects instead of using premade ones you get the experience or the feel from it. For example here is my implementation of string using char array. It's not perfect in any way but it makes my job easier later when working on the lab.
So if you wanna learn or get a feel of actually learning, just attend CS courses at college near you.
Disclaimer: You might, or might not agree with what I wrote. It's your choice and my choice to state my opinion.
Well now that I am taking CS in college, and this is only week 3, I can say that it has been the most progressive week in learning c++ programming. Why?
When you get into a CS class a professor will set a requirments for your labs/assignments. For example my class we are not allowed to use string or vector, and simply can't use stdio library.
Well crap, how do you output a string? How do you keep a list of objects? This is when you actually learn. What I am saying is, when you have to implement your own objects instead of using premade ones you get the experience or the feel from it. For example here is my implementation of string using char array. It's not perfect in any way but it makes my job easier later when working on the lab.
Code:
#pragma once#include <iostream>
#include <cstring>
class String
{
public:
// Overloading cout <<
friend std::ostream& operator<<(std::ostream& output, const String& s)
{
if (s.string != NULL)
output << s.string;
return output;
}
// Overloading cin >>
friend std::istream& operator>>(std::istream& input, String& s)
{
char temp[255];
input.get(temp, sizeof(temp)-1, '\n');
s.SetString(temp);
return input;
}
String operator=(String& s)
{
this->SetString(s.string);
return *this;
}
bool operator != (String s) const
{
return ( strcmp(string, s.string)!=0 ) ? true : false;
}
bool operator == (String s) const
{
return ( strcmp(string, s.string)==0 ) ? true : false;
}
String(void)
{
string = NULL;
}
String(char data[])
{
string = new char[strlen(data) + 1];
strcpy(string, data);
}
~String(void)
{
}
bool Compare(char data[])
{
return (std::strcmp(string, data) == 0) ? true : false;
}
char* GetString()
{
return string;
}
void SetString(char data[])
{
if (string != NULL)
{
delete [] string;
}
string = new char[strlen(data) + 1];
strcpy(string, data);
}
private:
char *string;
};
So if you wanna learn or get a feel of actually learning, just attend CS courses at college near you.
Disclaimer: You might, or might not agree with what I wrote. It's your choice and my choice to state my opinion.