Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Show Posts

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.

Messages - Supermikhail

Pages: 1 ... 18 19 [20] 21 22 ... 73
286
Hm. I might be wrong, but I believe GCC came with my Ubuntu distribution.

I tried to do it like this:
Code: [Select]
mikhail@misha:~$ g++ /home/mikhail/MyseriousConstructions/ChemicalLego/element_setup.cpp -o element_setup

What's -lm there?

Also, in case it works miraculously, could you put this data to the created file?
Code: [Select]

[Hydrogen:1:H:2.2:1:1]
[Boron:5:B:2.01:1:3]
[Nitrogen:7:N:3.04:5:1,2,3,4,5]

And then try the options that were crossed out previously?

287
Creative Projects / Re: I'm gonna try and write a book.
« on: December 17, 2010, 09:19:33 am »
On a more subjective note: I feel you're going too fast. Fantasy readers generally prefer quite a bit of description to be able to visualise what they're reading. If you like, I'll rewrite your first paragraph for you later to demonstrate what I mean.
I wanted to say that I don't find anything abnormal about the speed, except the jarring contrast with a lot of detalisation... but now I'm confused. Maybe it's the other way around. Also, I've got flu, so my judgement might be clouded.

In this state I want to say, that with the level of experience displayed, the worst thing about this bit is that filiusenox wants to write a book. I suppose if he sticks to it, there'll be lots of improvement, but the fact that the work will have low-quality alongside with improved writing, is going to be a hindrance and a big demotivator. Writing short fiction would be much more useful.

288
Oh. I'd be much obliged.

... I hope you don't mind if I post it all here. I tried uploading to MediaFire, and it doesn't want to take it for some reason. And I condensed it from 2 files.

Yeah, and I tried installing Code::Blocks today. Well, it even doesn't want to get installed, somehow managed to screw up dependencies inside one version. And g++ from the terminal doesn't do anything. It looks more and more like my system could use a fresh install.

Code: [Select]
#include <iostream>
#include <fstream>
#include <stdlib.h>
using namespace std;

const short ELEMENTS_ALLOWED = 96;

const char * filename = "./ElementsData.txt";

class Element
{
public:
Element() {}
~Element() {}

Element (short &, char * &, char * &, float &, short &, short (&)[7]);

void Display() const;
void AssignValues (short &, char (&)[20], char (&)[3], float &, short &, short (&)[7]);

short GetNumber() const { return itsNumber; }
char * GetName() const { return itsName; }
char * GetSymbol() const { return itsSymbol; }
float GetElectronegativity() const { return itsElectronegativity; }
short GetNofValencies() const { return itsNofValencies; }
short GetValencyNo(short &n) const { return itsValencies[n]; }
void DisplayValencies() const;

void readFromFile(ifstream &);
void writeToFile(ofstream &);

private:
short itsNumber;
char * itsName;
char * itsSymbol;
float itsElectronegativity;
short itsNofValencies;
short itsValencies[7];
};

Element::Element (short &number, char * &name, char * &symbol,
float &electronegativity, short &nofValencies, short (&valencies)[7])
{
itsNumber = number;
itsName = name;
itsSymbol = symbol;
itsElectronegativity = electronegativity;
itsNofValencies = nofValencies;

for(int i=0; i<nofValencies; i++)
{
itsValencies[i] = valencies[i];
}

}

void Element::Display() const
{
cout << "The element " << itsName << "'s number in the Periodical ";
cout << "Table is " << itsNumber << ".\nIts symbol is ";
cout << itsSymbol << ".\nIts electronegativity is ";
cout << itsElectronegativity << ".\n";
if (itsNofValencies==1)
{
cout << "It has a single valency which is ";
cout << itsValencies[0];
}
else
{
cout << "Its overall number of valencies is ";
cout << itsNofValencies << "and the valencies are ";

for(short i=0; i<itsNofValencies; i++)
{
cout << itsValencies[i];
if(i<(itsNofValencies-1))
cout << ", ";
else
cout << ".";
}
}
}

void Element::AssignValues (short &number, char (&name)[20], char (&symbol)[3],
float &electronegativity, short &nofValencies, short (&valencies)[7])
{
itsNumber = number;
itsName = name;
itsSymbol = symbol;
itsElectronegativity = electronegativity;
itsNofValencies = nofValencies;

for(int i=0; i<nofValencies; i++)
{
itsValencies[i] = valencies[i];
}

}

void Element::DisplayValencies() const
{
if (itsNofValencies==1)
{
cout << "Element " << itsName << " has a single valency which is ";
cout << itsValencies[0];
}
else
{
cout << "Element " << itsName << "'s overall number of valencies is ";
cout << itsNofValencies << "and the valencies are ";

for(short i=0; i<itsNofValencies; i++)
{
cout << itsValencies[i];
if(i<(itsNofValencies-1))
cout << ", ";
else
cout << ".\n\n";
}
}
}

void Element::readFromFile(ifstream &fin)
{
char temp[10];
fin.ignore(20, '[');
fin.getline(itsName, 21, ':');
fin.getline(temp, ':');
itsNumber = atoi(temp);
fin.getline(itsSymbol, 4, ':');
fin.getline(temp, ':');
itsElectronegativity = atof(temp);
fin.getline(temp, ':');
itsNofValencies = atoi(temp);
for(short i=0; i < itsNofValencies; i++)
{
if(i<(itsNofValencies-1))
{
fin.getline(temp, ',');
itsValencies[i] = atoi(temp);
}
else
{
fin.getline(temp, ']');
itsValencies[i] = atoi(temp);
}
}
}

void Element::writeToFile(ofstream &fout)
{
fout.put('[');
fout << itsName;
fout.put(':');
fout << itsNumber;
fout.put(':');
fout << itsSymbol;
fout.put(':');
fout << itsElectronegativity;
fout.put(':');
fout << itsNofValencies;
fout.put(':');
for(short i=0; i < itsNofValencies; i++)
{
fout << itsValencies[i];
if(i<(itsNofValencies-1))
fout.put(',');
}
fout << "]";
}

short menu(bool &file_fresh, short &elements_available)
{
short choice;

cout << "****Menu****\n\n";

if(elements_available>ELEMENTS_ALLOWED)
{
cout << "(-)Add an element.\n";
}
else
{
cout << "(1)Add an element.\n";
}

if(file_fresh)
{
cout << "(-)List the available elements by numbers.\n";
cout << "(-)List the available elements by names.\n";
cout << "(-)Choose an element to display, by number.\n";
cout << "(-)Choose an element to display, by name.\n";
}
else
{
cout << "(2)List the available elements by numbers.\n";
cout << "(3)List the available elements by names.\n";
cout << "(4)Choose an element to display, by number.\n";
cout << "(5)Choose an element to display, by name.\n";
}

cout << "(6)Quit.\n\n";
cout << ": ";
cin >> choice;
return choice;
}



int main(int argc, char** argv)
{
char name[20];
short number;
char symbol[3];
float electronegativity;
short nofValencies;
short valencies[7];
Element element_list[100];
short elements_available;
bool file_fresh;
ifstream fin;
ofstream fout;

fin.open(filename); //Checking if the file exists
fin.close();

if(fin.fail())
{
cout << "\nElements data file does not exist.\n"; //If the file does not exist,
fout.open(filename); //create it.
fout.close();
cout << "New file created.\n\n";

elements_available = 0;

file_fresh = true;
}
else
{ //If the file exists
fin.open(filename);

cout << "\nElements data file good.\n"; //print a message

file_fresh = false;

//fin.seekg(0, ios::beg);

for(short i=0; i==99; i++) //and read the data into the Elements_list
{
element_list[i].readFromFile(fin);
if(fin.peek()==fin.eof())
{
elements_available = i+1;
break;
}
}

if( elements_available>=ELEMENTS_ALLOWED ) //If there are 96 elements already
{ //(which is the number of elements naturally occurring on Earth)
cout << "Elements full!\n";  //print a message
}

cout << "\n";

fin.close();
}

short choice;
while((choice=menu(file_fresh, elements_available))!=6)
{
if ((choice == 1)&&(elements_available<ELEMENTS_ALLOWED))
{
cout << "Enter the desired element's name: ";
cin >> name;
cout << "\nEnter " << name << "'s number in the Periodical Table: ";
cin >> number;
cout << "\nEnter " << name << "'s symbol: ";
cin >> symbol;
cout << "\nEnter " << name << "'s electronegativity: ";
cin >> electronegativity;
cout << "\nEnter " << name << "'s overall number of valencies: ";
cin >> nofValencies;
for (short i = 0; i<nofValencies; i++)
{
cout << "Enter valency number " << i+1 << ": ";
cin >> valencies[i];
}
cout << "\n";

element_list[elements_available].AssignValues(number, name, symbol, electronegativity,
nofValencies, valencies);
elements_available++;

ofstream fout(filename, ios::app);
if( !fout )
{
cout << "Unable to open elements data for writing" << endl;
return 1;
}
fout.put('\n');
element_list[elements_available-1].writeToFile(fout);
cout << "Element saved.\n\n";

file_fresh = false;

fout.close();
}
else
if ((choice == 2)&&(!file_fresh))
{
cout << "Available elements' numbers are ";
for(short i=0; i<elements_available; i++)
{
cout << element_list[i].GetNumber();
if(i<(elements_available-1))
cout << ", ";
}
cout << ".\n\n";
}
else
if ((choice == 3)&&(!file_fresh))
{
cout << "Available elements are ";
for(short i=0; i<elements_available; i++)
{
cout << element_list[i].GetName();
if(i<(elements_available-1))
cout << ", ";
}
cout << ".\n\n";
}
else
if ((choice == 4)&&(!file_fresh))
{
cout << "Enter the desired element's number: ";
cin >> number;
cout << "\n";

for(short i=0; i<elements_available; i++)
{
if(element_list[i].GetNumber()==(number+1))
{
cout << "The data of the element No. ";
cout << number << ":\n\n";
element_list[i].Display();
cout << "\n";
break;
}
else
if(i==(elements_available-1))
cout << "The requested element not found.\n";
}
cout << "\n";
}
else
if ((choice == 5)&&(!file_fresh))
{
cout << "Enter the desired element's name: ";
cin >> name;
cout << "\n";

for(short i=0; i<elements_available; i++)
{
if(element_list[i].GetName()==name)
{
cout << "The data of the element ";
cout << name << ":\n\n";
element_list[i].Display();
cout << "\n\n";
break;
}
else
if(i==(elements_available-1))
cout << "The requested element not found.\n";
}
cout << "\n";
}
else
{
cout << "Option unavailable. Try again.\n\n";
}
}

return 0;
}

289
In my code, filename is a char array with the actual filename as its value. Including "./" I think it should work the same as your suggestion.

290
Well. That does not work. Terminal still creates the file in the home directory.
I don't know, it's like... I'm even starting to suspect that my compiler is buggy. Or my terminal... Or my whole system, for that matter.
Also, maybe someone could tell me what's wrong with this code:
Code: [Select]
void Element::readFromFile(ifstream &fin)
{
char temp[10];
fin.ignore(20, '[');
fin.getline(itsName, 21, ':');
fin.getline(temp, ':');
itsNumber = atoi(temp);
fin.getline(itsSymbol, 4, ':');
fin.getline(temp, ':');
itsElectronegativity = atof(temp);
fin.getline(temp, ':');
itsNofValencies = atoi(temp);
for(short i=0; i < itsNofValencies; i++)
{
if(i<(itsNofValencies-1))
{
fin.getline(temp, ',');
itsValencies[i] = atoi(temp);
}
else
{
fin.getline(temp, ']');
itsValencies[i] = atoi(temp);
}
}
}
As far as I can see, besides the weird path thing, it's this function that's bugging my code. The program writes data to file perfectly (I copied the format from Toady, and the output is like this: [Boron:5:B:2.01:1:3]), but doesn't want to read. Or it may be in this segment:
Code: [Select]
{ //If the file exists
fin.open(filename, ios::in);

cout << "\nElements data file good.\n"; //print a message

file_fresh = false;

fin.seekg(0, ios::beg);

for(short i=0; i==99; i++) //and read the data into the Elements_list
{
element_list[i].readFromFile(fin);
if(fin.peek()==fin.eof())
{
elements_available = i+1;
break;
}
}

if( elements_available>=ELEMENTS_ALLOWED ) //If there are 96 elements already
{ //(which is the number of elements naturally occurring on Earth)
cout << "Elements full!\n";  //print a message
}

cout << "\n";

fin.close();
}

291
Can anybody with Linux experience help me?
As far as I can figure (and I've been figuring for a long time), when I run my program through the IDI, it creates a file in the directory the executable is in, but when I run it through the terminal, it creates a file in my home directory. Full path, as I first thought, doesn't suit me, because I'd like to distribute the program.
Actually, not only people with Linux experience. If I compile it on Windows, will it do this to me, too?

292
Life Advice / Re: I want to write great music. What should I do?
« on: December 16, 2010, 04:31:20 am »
Great advice. "Go somewhere else with your questions." ;)

I've come up with a bit more for myself. Maybe the way to start is to write exactly the opposite - completely unoriginal stuff. Try to broach different genres, ethnic styles, etc. It could provide useful exercises, just like I wanted. Yeah, what exercises aspiring students of any professions do? Such that they involve the whole range of the sciences they study and increase in difficulty. Maybe I'll start with what my book on guitar starts with - études and simple pieces.

293
Creative Projects / Re: Bay12 Writers Guild
« on: December 16, 2010, 04:16:34 am »
Hey, can somebody offer some competent organiser advice? I've got a collection of my works at Scribd.com, it's nice and growing, but what it started with was very amateurish and what I hope I've advanced beyond now. Also, it has several drafts of a story along with the finished version.

Basically, what I can't decide is if I should remove the mediocre stuff and drafts? Can it be somehow useful to me/others in the future?

294
Creative Projects / Re: An Otherworldly Ark
« on: December 15, 2010, 04:08:33 pm »
Heh. My fascination with zoology before this project was mostly concerned with what things I could get my hands on, that is, furry cute things that run around the street and are sold in pet shops. But this is an entirely different level.

The task is still a little intimidating. But I'll think about it.

295
Life Advice / Re: I want to write great music. What should I do?
« on: December 15, 2010, 02:13:32 pm »
Hm, while I don't trust Wikipedia in the matter of education (in fact, I don't trust most of the Internet in this matter), this advice has been helpful in that I decided to Google to the core. And came up with this article... Scratch that. Not really helpful. I've tried learning music theory on the Internet, but it's kind of hard. I wish there was a really helpful book, like Composition For Dummies, I guess. With great exercises. I believe in the power of exercises. But I haven't met such a book.

Turning off my inner critic... he sooner turns off me, than I him.

296
Life Advice / I want to write great music. What should I do?
« on: December 15, 2010, 12:54:58 pm »
Well, the title says it all. Except that I'm a University student of 22, in a department with no relation to music whatsoever. My musical experience consists mainly of playing guitar for the past 5 years, and mucking about with computer midi for a bit less time. Also, somehow, when I had less experience, that is, about 3-2 years ago, I composed a few pieces that I liked, but now it feels like I just lost something. It might have been youthful naiveté as a source of inspiration.

I guess I could explain what "great music" means for me. My definition would be - "complex, catchy, and original". What I've been putting out recently falls way short of this definition, especially on the third part, when I mostly do transcriptions and adaptations. When I'm inspired to write something original, I either quickly find that the idea is derivative, or I put out repetitive and boring stuff... or the piece turns out so original that I don't know how to progress. ::)

So, can anybody offer some tips, suggest a book, an Internet site, or something that could help my cause?

P.S. There is a website on which you can browse through some of the midis I've done if you for some reason feel like it.

297
Creative Projects / Re: An Otherworldly Ark
« on: December 15, 2010, 09:32:06 am »
 :-\: Wow, that's neat. Especially the idea that shouldn't need so many kidnappings and horrific torture, unless they are a race feeding on emotions. However, say, they are a race feeding on emotions... who are GIANT JELLYFISH EVOLVED FOR aerial flight, and, what's even more cool, CAPABLE OF INTERDIMENSIONAL travel!

And while this idea settles in, I'd like to inform you that I've read past the introduction to Cnidaria, and I have to say... that I'm having a hard time imagining anything more complex or more perfect evolving from the Medusa part of them. I'm growing in opinion that to juggle things like them I first need to evolve something myself to the same complexity. They seem perfectly balanced and to shift the balance you'd have to take something away, make them worse, like remove cnidocytes. But in the same mutation you'd have to add some alternative, because otherwise the mutation won't survive.

Which proves once again the usefulness of education on the subject in this endeavour. I couldn't imagine the beauty and complexity of life before I met Cnidaria.

298
Creative Projects / Re: An Otherworldly Ark
« on: December 14, 2010, 09:35:16 am »
 :-\: Hey, Shoku, how do you explain flying saucers?

299
That will probably involve writing character by character, and I can only dream of conceiving something that will read such a file correctly. And I suspect then there's no need to use string.

Well, tonight the world either changes, or is destroyed in a fiery catsplosion when I'm so depressed after a failed attempt to reconcile my pointers that I'll spend the rest of the night playing DF.

300
Well, that's fancy. Segfault, I mean.

For anyone curious:
Code: [Select]
//element.hpp

#include <iostream>
#include <string>

class Element
{
public:
Element() {}
~Element() {}

Element( const std::string &, short &, double &, short [], short &);

std::string GetName() const { return itsName; }
short GetNumber() const { return itsNumber; }
double GetElectronegativity() const { return itsElectronegativity; }
short GetValnumber() const { return itsValnumber; }
void DisplayValencies() const;

void AssignValues( const std::string , short, double , short[] , short );

private:
std::string itsName;
short itsNumber;
double itsElectronegativity;
short itsValency[7];
short itsValnumber;
};

Element::Element( const std::string & name, short &number, double &electronegativity, short valency [], short &valnumber)
{
itsName = name;
itsNumber = number;
itsElectronegativity = electronegativity;
itsValnumber = valnumber;
for(int i=0; i<valnumber; i++)
{
itsValency[i] = valency[i];
}
std::cout << "*Element constructor called*\n";
}

void Element::AssignValues(const std::string name, short number, double electronegativity, short valency[], short valnumber)
{
itsName = name;
itsNumber = number;
itsElectronegativity = electronegativity;
itsValnumber = valnumber;
for(int i=0; i<valnumber; i++)
{
itsValency[i] = valency[i];
}
}

void Element::DisplayValencies() const
{
for(int i=0; i<itsValnumber; i++)
{
std::cout << itsValency[i];
if( i==(itsValnumber-1) )
std::cout << ".\n";
else
std::cout << ", ";
}
}

Code: [Select]
//element_setup.cpp

#include <iostream>
#include <fstream>
#include "element.hpp"
#include <string>

using namespace std;

int menu()
{
int choice;
cout << "****Menu****\n\n";
cout << "(1)Write.\n";
cout << "(2)Read.\n";
cout << "(3)Quit.\n\n";
cout << ": ";
cin >> choice;
return choice;
}



int main(int argc, char** argv)
{
string name;
short number;
double electronegativity;
short valency[7];
short valnumber;

cout << name.length();

int choice;
while((choice=menu())!=3)
{
if (choice == 1)
{
cout << "Enter the desired element's name: ";
cin >> name;
cout << "\nEnter " << name << "'s number in the Periodical Table: ";
cin >> number;
cout << "\nEnter " << name << "'s electronegativity: ";
cin >> electronegativity;
cout << "\nEnter " << name << "'s overall number of valencies: ";
cin >> valnumber;
for (int i = 0; i<valnumber; i++)
{
cout << "Enter valency number " << i+1 << ": ";
cin >> valency[i];
}
cout << "\n";

Element elemwrite(name, number, electronegativity, valency, valnumber);

ofstream fout("elements_data", ios::binary);
if( !fout )
{
cout << "Unable to open elements data for writing" << endl;
return 1;
}

fout.write((char*) & elemwrite, sizeof elemwrite);

fout.close();
}
else
if (choice == 2)
{
ifstream fin("elements_data", ios::binary);
if( !fin )
{
cout << "Unable to open elements data" << endl;
return 1;
}
else

Element elemread(name, number, electronegativity, valency, valnumber);

fin.read((char*) & elemread, sizeof elemread);

cout << "Element read\n";

cout << "Element " << elemread.GetName();
cout << "'s number in the Periodical Table is ";
cout << elemread.GetNumber() << ".\n";
cout << "Its electronegativity is ";
cout << elemread.GetElectronegativity() << ".\n";
valnumber = elemread.GetValnumber();
if( valnumber == 1 )
cout << "It has single possible valency which is ";
else
{
cout << "Its overall number of possible valencies is ";
cout << valnumber << " which are ";
}
elemread.DisplayValencies();
cout << "\n";

fin.close();
}
else
cout << "Please select again!\n";
}

return 0;
}

Well, it seems I can't make it output a string of characters to a binary file correctly. Which means I have to resort to a text file. :( And then write an encryption function for it.

Pages: 1 ... 18 19 [20] 21 22 ... 73