1
General discussion / Re: Evilzone Chess Tournament?
« on: May 28, 2013, 01:24:18 AM »
I'd be up for this. I'd also be willing to whip up the program for the name picking.
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
// String1030.h
//@author Lupus
// Header for class that will handle an implementation
// of strings.
#ifndef STRING1030_H
#define STRING1030_H
#include<iostream>
using std::ostream;
using std::istream;
using std::endl;
using std::cerr;
class String1030
{
public:
String1030(const char *buf=0);
String1030(const String1030& oldstring);
~String1030();
String1030& operator=(const String1030& right);
char& operator[](int index);
int getSize(void) const;
void setSize(int newsize);
const char *getString();
void setString(const char *carray);
private:
char *buffer;
int mysize;
};
#endif
//String1030.cpp
//@author Lupus
//March 27th, 2013
#include "String1030.h"
//Basic constructors
String1030::String1030(const char *buf): mysize(0)
{
setString(buf);
}
String1030::String1030(const String1030& oldstring): mysize(0)
{
if(oldstring.getSize() <= 0)
{
setSize(0);
}
else
{
setSize(oldstring.getSize());
for(int i = 0; i < (mysize+1); i++)
{
buffer[i] = oldstring.buffer[i];
}
}
}
//Reallocates the memory.
String1030::~String1030()
{
delete [] buffer;
}
//Overloads the = operator, causing one string to be set to another.
String1030& String1030::operator=(const String1030& right)
{
if(!(&right == this))
{
if(right.getSize() <= 0)
{
setSize(0);
}
else
{
setSize(right.getSize());
for(int i = 0; i < (mysize+1); i++)
{
buffer[i] = right.buffer[i];
}
}
}
return *this;
}
//Deals with operator overloading of the [] operator.
char& String1030::operator[](int index)
{
if(!(index < 0 || index >= mysize))
{
return buffer[index];
}
else return buffer[0];
}
//Simple accessor function for size.
int String1030::getSize(void) const
{
return mysize;
}
//Resetting size of a string.
void String1030::setSize(int newsize)
{
if(!(newsize < 0))
{
if(buffer != NULL)
{
mysize = newsize;
buffer = new char[mysize+1];
}
else
{
mysize = newsize;
buffer = new char[mysize+1];
}
}
}
//A simple accessor function to return the string.
const char* String1030::getString()
{
return buffer;
}
//Handles setting a new string.
void String1030::setString(const char *carray)
{
int index(0);
if(carray != 0)
{
while(*(carray + index) != '\0')
{
index++;
}
mysize = index;
buffer = new char[mysize+1];
for(int i = 0; i < (mysize+1); i++)
{
buffer[i] = carray[i];
}
}
}
// StringTest.cpp
// Testing program for the String1030 class.
#include<iostream>
#include "String1030.h"
using std::cout;
using std::cin;
int main()
{
// check the constructors
String1030 s("My string");
String1030 t(s);
String1030 x;
char in_buf[256];
cout << "S size(): " << s.getSize() << endl;
cout << "T size(): " << t.getSize() << endl;
cout << "X size(): " << x.getSize() << endl;
for(int i=0;i<t.getSize();i++)
cout << t[i];
cout << endl;
s[2]='5';
for(int i=0;i<s.getSize();i++)
cout << s[i];
cout << endl;
// check the assignment operator
x=s;
cout << "X: " << x.getString() << endl;
// check the size reset.
x.setSize(30);
cin >> in_buf;
x.setString(in_buf);
cout << "\nx: " << x.getString() << endl;
//more checks on resize
//set to a negative value, nothing should change
s.setSize(-8);
cout << "S size(): " << s.getSize() << endl;
//set to 0, should be 0
s.setSize(0);
cout << "S size(): " << s.getSize() << endl;
//read into the 0 length array should NOT have an error
//and should NOT transfer any characters. Output should not
//have any errors either.
cin >> in_buf;
s.setString(in_buf);
cout << "S after cin>>: " << s.getString() << endl;
//reset to something larger than 0
s.setSize(10);
cout << "S size(): " << s.getSize() << endl;
//read should work now
cin >> in_buf;
s.setString(in_buf);
cout << "S after cin>>: " << s.getString() << endl;
//now the assignment return value
x=t=s;
cout << "T: " << t.getString() << endl;
cout << "X: " << x.getString() << endl;
return 0;
}
Personally, I oppose this. yes, arch can be frustrating, but it's worth it in the end, you end up with an operating system, that you know a few basic console commands on. if you use ubuntu, you don't get dug in to using command line at the start, so unless you actively try to, you won't learn about it at all. whereas with a distro like arch, you start to understand what you are doing, and how it works. all this, and it is itself much smaller. and as it is starting from pure command line, it's easy to put in place the DE or WM of your choice. or.. as in my case.. put in place a couple, so i can use whichever suits my mood.
@OP i suggest this for a future linux distro https://www.archlinux.org/ . I mean i'd say just go ahead and start messing with it, but it can be very difficult at times. At the least it's good to know about, a little reading can't hurt :p.
... but it's a mess to learn programming on because of #include <windows.h>.