News Delta Vee!

johan

Donator
Donator
Joined
Jun 30, 2010
Messages
112
Reaction score
0
Points
16
Yes, there has been a lot of discussion, but I'm not exactly sure what to do with the program right now, since I'll have to test some things first, but I can already see a few improvements coming.

:lol: I just finished reading the comments, and there are already calls for an update. Its good to be wanted though :thumbup:.

Work FASTER!

:eek:wned:

:lol: I'm just kidding.
 

BruceJohnJennerLawso

Dread Lord of the Idiots
Addon Developer
Joined
Apr 14, 2012
Messages
2,585
Reaction score
0
Points
36
Work FASTER!

:eek:wned:

:lol: I'm just kidding.

:sos:

MSVCR100.dll has nothing to do with those multi-threading options (which BTW are totally not needed for you code until you are coding multiple execution threads - i.e. later). It's just the VC++ Release 2010 runtime DLL. You can statically link this into your code, but you generally do not want to do this as you hard-compile in runtime vulnerabilities that may need critical patching later. So it's best to shrug your shoulders and say - you need a VC redistributable install to run this, so do it already!

Errr, okay, but there must be some way to break free of the need for dependencies, as most programs eventually do. If I understood that last part correctly, you're saying that removing the dependency is possible, but tricky to do?

For example with this (std::transform is from <algorithm>, toupper is from <cctype> or <ctype.h>):
Code:
std::transform (read_string.begin (), read_string.end (), read_string.begin (), toupper);

Okayy, think I got the general idea from the reference you linked, I just need to ask the user for a string, then place the name of that string in place of read_string?
 

orb

New member
News Reporter
Joined
Oct 30, 2009
Messages
14,020
Reaction score
4
Points
0
I just need to ask the user for a string, then place the name of that string in place of read_string?
The read_string in my example is the string variable you've read to from the user input. I didn't check how your variables are called.
 

BruceJohnJennerLawso

Dread Lord of the Idiots
Addon Developer
Joined
Apr 14, 2012
Messages
2,585
Reaction score
0
Points
36
The read_string in my example is the string variable you've read to from the user input. I didn't check how your variables are called.

Yeah, thats what I meant. Thanks Orb! :tiphat:
 

BruceJohnJennerLawso

Dread Lord of the Idiots
Addon Developer
Joined
Apr 14, 2012
Messages
2,585
Reaction score
0
Points
36
The read_string in my example is the string variable you've read to from the user input. I didn't check how your variables are called.

Okay, I tried this idea right after the main menu input (cin cycle ;))

Code:
    cin >> cycle;
	
	std::transform (cycle.begin (), cycle.end (), cycle.begin (), toupper);

cycle is then compared against the list for any matches, but the code that you posted was supposed to change it to uppercase. The compiler didnt agree there unfortunately, so I'm unsure if I implemented it wrong? I can post the errors that it gave me at compile time if you want to see them.
 
Last edited:

Enjo

Mostly harmless
Addon Developer
Tutorial Publisher
Donator
Joined
Nov 25, 2007
Messages
1,665
Reaction score
13
Points
38
Location
Germany
Website
www.enderspace.de
Preferred Pronouns
Can't you smell my T levels?
The compiler didnt agree there unfortunately, so I'm unsure if I implemented it wrong? I can post the errors that it gave me at compile time if you want to see them.
Necessarily! Only this way we can help you. My bet is that you haven't included <cctype> and <algorithm>
And always try to make your question specific and google it:
www.google.com/search?q=c+++transform+toupper
Usually you'll get many clues at the Stack Exchange site.
 
Last edited:

BruceJohnJennerLawso

Dread Lord of the Idiots
Addon Developer
Joined
Apr 14, 2012
Messages
2,585
Reaction score
0
Points
36
Necessarily! Only this way we can help you. My bet is that you haven't included <cctype> and <algorithm>
And always try to make your question specific and google it:
www.google.com/search?q=c+++transform+toupper
Usually you'll get many clues at the Stack Exchange site.

I'll try to find that later on, but I removed my first try from the code because I wanted to focus on the stability issue first.

PHP:
string inputVar;
double mass;
cout << "Enter mass\n";
cin >> inputVar;
istringstream ss;
ss.str(inputVar);
if (ss >> mass)
{
 // work with mass
}
else
{
 cout << "Please input a number" << endl;
}

I tried this on one of my cin inputs, but the compiler didnt work with it. There appears to be a missing file that I need to add, but I dont know exactly which one?

Code:
1>------ Build started: Project: Delta Vee!, Configuration: Debug Win32 ------
1>  Delta Vee!.cpp
1>Delta Vee!.cpp(119): error C2079: 'ss' uses undefined class 'std::basic_istringstream<_Elem,_Traits,_Alloc>'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>,
1>              _Alloc=std::allocator<char>
1>          ]
1>Delta Vee!.cpp(120): error C2039: 'str' : is not a member of 'System::Int32'
1>          c:\program files (x86)\reference assemblies\microsoft\framework\.netframework\v4.0\mscorlib.dll : see declaration of 'System::Int32'
1>Delta Vee!.cpp(121): error C2297: '>>' : illegal, right operand has type 'double'
1>Delta Vee!.cpp(123): error C2440: '=' : cannot convert from 'std::string' to 'double'
1>          No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
 

Enjo

Mostly harmless
Addon Developer
Tutorial Publisher
Donator
Joined
Nov 25, 2007
Messages
1,665
Reaction score
13
Points
38
Location
Germany
Website
www.enderspace.de
Preferred Pronouns
Can't you smell my T levels?
Then googling istringstream would lead you to including <sstream>
 

BruceJohnJennerLawso

Dread Lord of the Idiots
Addon Developer
Joined
Apr 14, 2012
Messages
2,585
Reaction score
0
Points
36
Then googling istringstream would lead you to including <sstream>

Actually I did, but it didn't. (Google & I don't get along so well)

I would presume that sstream would be analogous to iostream?
 

Enjo

Mostly harmless
Addon Developer
Tutorial Publisher
Donator
Joined
Nov 25, 2007
Messages
1,665
Reaction score
13
Points
38
Location
Germany
Website
www.enderspace.de
Preferred Pronouns
Can't you smell my T levels?
Then first you need to learn a good learning-by-Google methodology, not to ask questions on each compiler error. That's not an insult. People get tired of answering basic questions that are already answered. As an exercise, do try to use Google now to learn that istringstream comes from <sstream>, by watching examples on any C++ reference page, or piece of code.
Furthermore, usually only the first error line counts. You don't need to post the entire compiler's error. Especially if the error concerns STL classes, as the part below is meaningless:
Code:
(...)
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>,
1>              _Alloc=std::allocator<char>
1>          ]

I would presume that sstream would be analogous to iostream?
Yes, they are all streams and provide the same basic functionality, accessible with >> or <<.
istringstream, same as ifstream, sharing the same base class - istream, provides only input functionality with >> (from the PC perspective), while ostringstream, ofstream, with base class ostream, provides only output functionality with <<.
stringstream and fstream, deriving from both istream and ostream, have both functionalities.
The limitation of choosing ifstream, instead of fstream is performed by a defensive coder for the purpose of promising not to write to a stream, which is supposed to not be changed (like when only reading a configuration file)
For more details, check the reference:
http://en.cppreference.com/w/cpp/io/basic_stringstream

Also note, that since the final streams derive from ostream or istream, you can use them in generic handlers, expecting basic streams as parameters, to do some work. This way you guarantee the same system's behavior, whether the input string is entered by user with cin (console input stream), or ifstream (file input stream, for example a config file). You can even define your own rules like that with inheritance, and usage of such generic rules with final classes' implementation unknown to the handler is called polymorphism, but you should leave it for the dessert. However polymorphism, templates, and design patterns are the paradigms that make Object Oriented Programming worthwhile.
And probably even more important is, that they are shared in all major languages - C#, Java and JavaScript. This means, that if you learn it once, you will be able to program anything in any company.
 
Last edited:

BruceJohnJennerLawso

Dread Lord of the Idiots
Addon Developer
Joined
Apr 14, 2012
Messages
2,585
Reaction score
0
Points
36
Then first you need to learn a good learning-by-Google methodology, not to ask questions on each compiler error. That's not an insult. People get tired of answering basic questions that are already answered. As an exercise, do try to use Google now to learn that istringstream comes from <sstream>, by watching examples on any C++ reference page, or piece of code.
Furthermore, usually only the first error line counts. You don't need to post the entire compiler's error. Especially if the error concerns STL classes, as the part below is meaningless:
Code:
(...)
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>,
1>              _Alloc=std::allocator<char>
1>          ]

Sorry about that, its a bad tendency that I need to rein in. I am getting more comfortable with using cplusplus.com, but are there any other good websites that I can use for reference as well?

As far as the program goes, Im still trying to wrestle it into shape. I got the code that you posted working, but Im having trouble with some of the details in getting it to actually work. Part of the confusion is that Im not quite sure what this section is supposed to do.

Code:
	ss.str(Vexhinput);
	if (ss >> Vexh)
	{

	}

the comments you included said "work with mass", so I would guess that I was supposed to perform an operation on the variable retrieved from the input, but the program is more structured to get all of its data, then operate on it. I guess I could set up some sort of loop to retrieve my variables from the same stream one-by-one, but I suspect I'm not grasping the problem properly.

Aha, I think I get it now



I'll read a bit about <sstream>

:hailprobe:
 

Enjo

Mostly harmless
Addon Developer
Tutorial Publisher
Donator
Joined
Nov 25, 2007
Messages
1,665
Reaction score
13
Points
38
Location
Germany
Website
www.enderspace.de
Preferred Pronouns
Can't you smell my T levels?
You ready for this?

PHP:
#include <iostream>
#include <sstream>
#include <fstream>
#include <cmath>

using namespace std;

// Template class - T may be any class
template <class T>
class Result
{
public:
    Result (T value, bool success)
    {
      this->value = value;
      this->success = success;
    }

    T value;
    bool success;
};

struct DataDV
{
    DataDV() // default constructor
    {
        Vexh = Mp = Md = 0;
    }
  double Vexh;
  double Mp;
  double Md;
};

Result<DataDV> ParseInput(istream & is)
{
    DataDV dv;
    // Read all variables in one go, assuming they are space-separated (C++ tokenizing trick)
    if (is >> dv.Vexh >> dv.Mp >> dv.Md)
    {
        // You can return compound structures in OOP languages
        return Result<DataDV>(dv, true);
    }
    else
    {
        return Result<DataDV>(dv, false);
    }
}

Result<DataDV> ReadConsoleInput()
{
    const string infoInput = "Enter space-separated values for Vexh, Mp & Md:";
    cout << infoInput << endl;
    string input;
    getline (cin, input); // Get the whole line, including spaces
    cout <<"INPUT was: " << input << endl;
    istringstream iss;
    iss.str(input);
    Result<DataDV> result = ParseInput(iss);  // Polymorphic call on basic istream
    return result;
}

Result<DataDV> ReadFileInput( const char * fileName )
{
    ifstream file(fileName);
    // could wrap it in:
    // if (file.is_open())
    {
        return ParseInput(file); // Polymorphic call on basic istream
    }
    // else
    //{
    //    return  Result<DataDV>(DataDV(), false);
    //}
}

double GetDeltaV( const DataDV & dv )
{
    // Make a local variable for easier debugging
    double DeeVee = dv.Vexh*(log((dv.Mp+dv.Md)/dv.Md));
    return DeeVee;
}

int main()
{
    Result<DataDV> result = ReadConsoleInput();
    while ( ! result.success )
    {
        result = ReadConsoleInput();
    }
    cout << "Successfully read data\nThe DV is: " << GetDeltaV(result.value) << endl;
    return 0;
}
 

BruceJohnJennerLawso

Dread Lord of the Idiots
Addon Developer
Joined
Apr 14, 2012
Messages
2,585
Reaction score
0
Points
36
You ready for this?

PHP:
#include <iostream>
#include <sstream>
#include <fstream>
#include <cmath>

using namespace std;

// Template class - T may be any class
template <class T>
class Result
{
public:
    Result (T value, bool success)
    {
      this->value = value;
      this->success = success;
    }

    T value;
    bool success;
};

struct DataDV
{
    DataDV() // default constructor
    {
        Vexh = Mp = Md = 0;
    }
  double Vexh;
  double Mp;
  double Md;
};

Result<DataDV> ParseInput(istream & is)
{
    DataDV dv;
    // Read all variables in one go, assuming they are space-separated (C++ tokenizing trick)
    if (is >> dv.Vexh >> dv.Mp >> dv.Md)
    {
        // You can return compound structures in OOP languages
        return Result<DataDV>(dv, true);
    }
    else
    {
        return Result<DataDV>(dv, false);
    }
}

Result<DataDV> ReadConsoleInput()
{
    const string infoInput = "Enter space-separated values for Vexh, Mp & Md:";
    cout << infoInput << endl;
    string input;
    getline (cin, input); // Get the whole line, including spaces
    cout <<"INPUT was: " << input << endl;
    istringstream iss;
    iss.str(input);
    Result<DataDV> result = ParseInput(iss);  // Polymorphic call on basic istream
    return result;
}

Result<DataDV> ReadFileInput( const char * fileName )
{
    ifstream file(fileName);
    // could wrap it in:
    // if (file.is_open())
    {
        return ParseInput(file); // Polymorphic call on basic istream
    }
    // else
    //{
    //    return  Result<DataDV>(DataDV(), false);
    //}
}

double GetDeltaV( const DataDV & dv )
{
    // Make a local variable for easier debugging
    double DeeVee = dv.Vexh*(log((dv.Mp+dv.Md)/dv.Md));
    return DeeVee;
}

int main()
{
    Result<DataDV> result = ReadConsoleInput();
    while ( ! result.success )
    {
        result = ReadConsoleInput();
    }
    cout << "Successfully read data\nThe DV is: " << GetDeltaV(result.value) << endl;
    return 0;
}

Hmmm, unfortunately I don't think I am. Structs are next in my tutorial, but I have to get through Dynamic Memory first.

But...

I managed to hash out a solution with the help of a friend (he mostly does C# & Java, but he was able to suggest the right tack to go on)

Delta Vee! 1.0310

Code:
// Delta Vee!
// A calculator for finding the total change in velocity of a spacecraft.
#include <iostream>
#include <sstream>
#include <math.h>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cctype>
#define NEWLINE '\n'
#define TAB '\t'

using namespace std;

void DeltaVeeCalculation ();
void PropellantMassCalculation ();
void ExhaustVelocityCalculation ();
void PayloadCalculation ();
void Introduction ();
double GiveameINPUT ();

double Vexh;
double Mp;
double DeeVee;
double Md;
double Mrcs;
double Mcons;
double Crew;

double data;

double VexhS2;
double MpS2;
double DeeVeeS2;
double MdS2;
double MrcsS2;
double MconsS2;

int main()
{	string MainMenu1 = "To calculate Delta-Vee, enter 'Dv'.";
	string MainMenu2 = "To calculate Required Propellant Mass, enter 'Mp'.";
	string MainMenu3 = "To calculate Maximum Payload Mass, enter 'Pa'.";
	string MainMenu4 = "To calculate Required Exhaust Velocity, enter 'Ve'.";
	string MainMenu5 = "To Exit, enter 'Q'.";
	string DeltaVee1 = "DV";
	string DeltaVee2 = "Dv";
	string DeltaVee3 = "dV";
	string DeltaVee4 = "dv";
	string Propellant1 = "MP";
	string Propellant2 = "Mp";
	string Propellant3 = "mP";
	string Propellant4 = "mp";
	string ExhaustVelocity1 = "VE";
	string ExhaustVelocity2 = "Ve";
	string ExhaustVelocity3 = "vE";
	string ExhaustVelocity4 = "ve";
	string MaximumPayload1 = "PA";
	string MaximumPayload2 = "Pa";
	string MaximumPayload3 = "pA";
	string MaximumPayload4 = "pa";
	string Exit1 = "Q";
	string Exit2 = "q";
	string cycle;

	Introduction ();
	
  while (true) {

    cout << MainMenu1 << NEWLINE;
    cout << MainMenu2 << NEWLINE;
    cout << MainMenu3 << NEWLINE;
    cout << MainMenu4 << NEWLINE;
    cout << MainMenu5 << NEWLINE << NEWLINE;
    cin >> cycle;

    if ((cycle == DeltaVee1) || (cycle == DeltaVee2)) {
      DeltaVeeCalculation ();
    } else if ((cycle == DeltaVee3) || (cycle == DeltaVee4)) {
      DeltaVeeCalculation ();
    } else if ((cycle == Propellant1) || (cycle == Propellant2)) {
      PropellantMassCalculation ();
    } else if ((cycle == Propellant3) || (cycle == Propellant4)) {
      PropellantMassCalculation ();
    } else if ((cycle == ExhaustVelocity1) || (cycle == ExhaustVelocity2)) {
      ExhaustVelocityCalculation ();
    } else if ((cycle == ExhaustVelocity3) || (cycle == ExhaustVelocity4)) {
      ExhaustVelocityCalculation ();
    } else if ((cycle == MaximumPayload1) || (cycle == MaximumPayload2)) {
      PayloadCalculation ();
    } else if ((cycle == MaximumPayload3) || (cycle == MaximumPayload4)) {
      PayloadCalculation ();
    }
	
	else if ((cycle == Exit1) || (cycle == Exit2)) {
      break;
    } else {
      cout << NEWLINE;
    }
  }

	cout <<NEWLINE;
	return 0;
}



void Introduction ()
{	string Intro = "Delta Vee! 1.0310 by John Lawson";
	cout <<Intro;
	cout <<NEWLINE << NEWLINE;	}

double GiveameINPUT ()
{
	while(true)
	{
		cin >> data;
		if (!cin.fail())
		{	return data;	}
		cin.clear();
		cin.ignore();
	}
}

void DeltaVeeCalculation ()
{	string meterspersecond = "m/s";
	string hailprobe = "Hail the Probe!!!";
	string text1 = "Exhaust Velocity (m/s):";
	string text2 = "Dry Mass (kilograms):";
	string text3 = "RCS Fuel (kilograms):";
	string text4 = "Consumables Mass (kilograms):";
	string text5 = "Propellant Mass(kilograms):";
	string text6 = "Delta-Vee:";
	string text7 = "Crew Number:";

	cout <<NEWLINE;
	cout <<text1;
    Vexh = GiveameINPUT();
	cout <<text2;
	Md = GiveameINPUT();
	cout <<text3;
	Mrcs = GiveameINPUT();
	cout <<text4;
	Mcons = GiveameINPUT();
	cout <<text7;
	Crew = GiveameINPUT();
	cout <<text5;
	Mp = GiveameINPUT();

	DeeVee = Vexh*(log((Mp+Md+Mrcs+Mcons+(Crew*90))/(Md+Mrcs+Mcons+(Crew*90))));

	cout <<text6;
	cout <<TAB;
	cout <<DeeVee;
	cout <<TAB;
	cout <<meterspersecond;
	cout <<NEWLINE;
	cout <<hailprobe;
	cout <<NEWLINE;
	cout <<NEWLINE;	}

void PropellantMassCalculation ()
{	string RequiredPropellantMass = "Propellant Required:";
	string hailprobe = "Hail the Probe!!!";
	string text1 = "Exhaust Velocity (m/s):";
	string text2 = "Dry Mass (kilograms):";
	string text3 = "Delta-Vee:";
	string text4 = "RCS Fuel (kilograms):";
	string text5 = "Consumables Mass (kilograms):";
	string text6 = "Crew Number:";
	string kilograms = "kg";


	cout <<NEWLINE;
	cout <<text1;
	Vexh = GiveameINPUT();
	cout <<text2;
	Md = GiveameINPUT();
	cout <<text4;
	Mrcs = GiveameINPUT();
	cout <<text5;
	Mcons = GiveameINPUT();
	cout <<text6;
	Crew = GiveameINPUT();
	cout <<text3;
	DeeVee = GiveameINPUT();

	Mp = ((exp(DeeVee/Vexh))*(Md+Mrcs+Mcons+(Crew*90)))-(Md+Mrcs+Mcons+(Crew*90));

	cout <<RequiredPropellantMass;
	cout <<TAB;
	cout <<Mp;
	cout <<TAB;
	cout <<kilograms;
	cout <<NEWLINE;
	cout <<hailprobe;
	cout <<NEWLINE;
	cout <<NEWLINE;	}

void ExhaustVelocityCalculation ()
{	string RequiredExhaustVelocity = "Exhaust Velocity Required:";
	string hailprobe = "Hail the Probe!!!";
	string text1 = "Dry Mass (kilograms):";
	string text2 = "RCS Fuel (kilograms):";
	string text3 = "Consumables Mass (kilograms):";
	string text4 = "Propellant Mass (kilograms):";
	string text5 = "Delta-Vee (m/s):";
	string text6 = "Crew Number:";
	string meterspersecond = "m/s";


	cout <<NEWLINE;
	cout <<text1;
	Md = GiveameINPUT();
	cout <<text2;
	Mrcs = GiveameINPUT();
	cout <<text3;
	Mcons = GiveameINPUT();
	cout <<text4;
	Mp = GiveameINPUT();
	cout <<text5;
	DeeVee = GiveameINPUT();
	cout <<text6;
	Crew = GiveameINPUT();

	Vexh = (DeeVee/log((Mp+Md+Mrcs+Mcons+(Crew*90))/(Md+Mrcs+Mcons+(Crew*90))));

	cout <<RequiredExhaustVelocity;
	cout <<TAB;
	cout <<Vexh;
	cout <<TAB;
	cout <<meterspersecond;
	cout <<NEWLINE;
	cout <<hailprobe;
	cout <<NEWLINE;
	cout <<NEWLINE;	}

void PayloadCalculation ()
{	string MaximumPayloadMass = "Maximum Payload:";
	string hailprobe = "Hail the Probe!!!";
	string text1 = "Dry Mass (kilograms):";
	string text2 = "RCS Fuel (kilograms):";
	string text3 = "Consumables Mass (kilograms):";
	string text4 = "Propellant Mass (kilograms):";
	string text5 = "Exhaust Velocity (m/s):";
	string text6 = "Delta-Vee (m/s):";
	string text7 = "Crew Number:";
	string kilograms = "kg";


	cout <<NEWLINE;
	cout <<text1;
	Md = GiveameINPUT();
	cout <<text2;
	Mrcs = GiveameINPUT();
	cout <<text3;
	Mcons = GiveameINPUT();
	cout <<text4;
	Mp = GiveameINPUT();
	cout <<text5;
	Vexh = GiveameINPUT();
	cout <<text6;
	DeeVee = GiveameINPUT();
	cout <<text7;
	Crew = GiveameINPUT();

	Mp = ((Mp/(exp(DeeVee/Vexh)-1))-Md-Mrcs-Mcons-(Crew*90));

	cout <<MaximumPayloadMass;
	cout <<TAB;
	cout <<Mp;
	cout <<TAB;
	cout <<kilograms;
	cout <<NEWLINE;
	cout <<hailprobe;
	cout <<NEWLINE;
	cout <<NEWLINE;	}

Now there is nothing that can glitch it (mostly nothing)

:woohoo:

:hailprobe:
 

Enjo

Mostly harmless
Addon Developer
Tutorial Publisher
Donator
Joined
Nov 25, 2007
Messages
1,665
Reaction score
13
Points
38
Location
Germany
Website
www.enderspace.de
Preferred Pronouns
Can't you smell my T levels?
You see, programing and automation is about automating repeatative tasks. When you do such funny things with upper/lower cases it makes me think what you would do if you had a longer sentence to process. Doing it your way would make you do repeatative tasks in something that's supposed to limit them.

Why don't you write a function like:
string ToLower( string in)
And transform the string inside and return it, then use it each time?
 

BruceJohnJennerLawso

Dread Lord of the Idiots
Addon Developer
Joined
Apr 14, 2012
Messages
2,585
Reaction score
0
Points
36
You see, programing and automation is about automating repeatative tasks. When you do such funny things with upper/lower cases it makes me think what you would do if you had a longer sentence to process. Doing it your way would make you do repeatative tasks in something that's supposed to limit them.

Why don't you write a function like:
string ToLower( string in)
And transform the string inside and return it, then use it each time?

From our discussion:

Functionalize ALL THE THINGS
:lol:

Great advice there.

Ummmm, hmmm

So the upper/lower thing is on my list, but I'll need to hold off just a bit longer; its not really that important of a feature, and I would much rather add a 2 stage calculator & some other neat things as well.

One idea I had was that it might be easier to include keywords that point to numbers? For example, it would be nice if the program would sub in the right value for Vexh, when the user puts in LOX-LH2 or something similar. It sounds awfully tricky to do though...
 

Ripley

Tutorial translator
Donator
Joined
Sep 12, 2010
Messages
3,133
Reaction score
407
Points
123
Location
Rome
Website
www.tuttovola.org
...So the upper/lower thing is on my list, but I'll need to hold off just a bit longer; its not really that important of a feature, and I would much rather add a 2 stage calculator & some other neat things as well...
I'll pop-in with the few reminiscences I have of when I was a programmer, back then, long ago.

I think you should instead highly prioritize what you now refer to as "not really that important of a feature".

Now that you have your input-section (somehow) working, you think it's not worth going over it once again in order to refine it and optimize it. Instead you prefer to go ahead with other important parts of your code.
I understand your point of view, but it's a typical mistake.

I'm afraid that if you go on with the "juicier" parts of your code, while you are still missing (or just skipping) some of the basic important concepts, you'll end up having not-so-neat other things, but rather messy ones instead.

My 2 cents.
:hailprobe:
 
Last edited:

BruceJohnJennerLawso

Dread Lord of the Idiots
Addon Developer
Joined
Apr 14, 2012
Messages
2,585
Reaction score
0
Points
36
I'll pop-in with the few reminiscences I have of when I was a programmer, back then, long ago.

I think you should instead highly prioritize what you now refer to as "not really that important of a feature".

Now that you have your input-section (somehow) working, you think it's not worth going over it once again in order to refine it and optimize it. Instead you prefer to go ahead with other important parts of your code.
I understand your point of view, but it's a typical mistake.

I'm afraid that if you go on with the "juicier" parts of your code, while you are still missing (or just skipping) some of the basic important concepts, you'll end up having not-so-neat other things, but rather messy ones instead.

My 2 cents.
:hailprobe:

Normally I would agree with you, but there is a slight difference here. The change that allowed for error handling was routing numerical data input through GivameINPUT ();. The main menu only scans for text based keywords from cin, and as such didn't need to be plugged in to the new input function. I haven't put a lot of brain steam into the issue at hand, but I suspect that nothing I do in the mean time will make doing it any harder anyways. (Im only adding another calculator mode, so the program wont be changing fundamentally, just maintenance wise)

Hope that explains my reasoning :hailprobe:
 

Enjo

Mostly harmless
Addon Developer
Tutorial Publisher
Donator
Joined
Nov 25, 2007
Messages
1,665
Reaction score
13
Points
38
Location
Germany
Website
www.enderspace.de
Preferred Pronouns
Can't you smell my T levels?
You don't have to explain. We've all been through this :)
 

BruceJohnJennerLawso

Dread Lord of the Idiots
Addon Developer
Joined
Apr 14, 2012
Messages
2,585
Reaction score
0
Points
36
You don't have to explain. We've all been through this :)

Well it was good advice, just not something I wanted to go through with at this point. If I can figure my way through the trickier remaining math for 2-stage, its next.

So a snapshot of whats going on so far. Structs have made my life much happy

Code:
// Delta Vee!
// A calculator for finding the total change in velocity of a spacecraft.
#include <iostream>
#include <math.h>
#include <string>
#include <new>
#define NEWLINE '\n'
#define TAB '\t'
#define BEEP '\a'

using namespace std;

void Introduction ();
void MainMenu ();
void MenuStage1 ();
void MenuStage2 ();
double GiveameINPUT ();

void DeltaVeeCalculation ();
void PropellantMassCalculation ();
void ExhaustVelocityCalculation ();
void PayloadCalculation ();

void DeltaVeeCalculation2S ();
void ExhaustVelocityCalculation2SS1 ();
void ExhaustVelocityCalculation2SS2 ();


//void PropellantMassCalculation2S ();
//void PayloadCalculation2S ();


struct stagedata 
{	double Vexh;
	double Mp;
	double Mpay;
	double DeeVee;
	double Md;
	double Mrcs;
	double Mcons;
	double Crew;
}	singlestage, firststage, secondstage, sumstages;

double Md1;
double Mp1;

double Md2;
double Mp2;

double data;

int main()
{	

	Introduction ();
	MainMenu ();

	cout <<NEWLINE;
	return 0;
}

void MainMenu()
{	string MainMenu1 = "Please enter the number of stages.";
	string MainMenu2 = "To exit enter 'Q'.";

	string Exit1 = "Q";
	string Exit2 = "q";
	string onenumerical = "1";
	string one = "one";
	string twonumerical = "2";
	string two = "two";

	string stagering;





	while (true) 
	{
		cout << MainMenu1 << NEWLINE;
		cout << MainMenu2 << NEWLINE << NEWLINE;

		cin >> stagering;
		cout << NEWLINE;
		if ((stagering == onenumerical) || (stagering == one))
		{
		MenuStage1 ();
		}

		else if ((stagering == twonumerical) || (stagering == two))
		{
		MenuStage2 ();
		}

		else if ((stagering == Exit1) || (stagering == Exit2))
		{
		break;
		}

		else
		{
		cout <<NEWLINE;
		}
	}
}


void MenuStage1 ()
{	  
	string MainMenu1 = "To calculate Delta-Vee, enter 'Dv'.";
	string MainMenu2 = "To calculate Required Propellant Mass, enter 'Mp'.";
	string MainMenu3 = "To calculate Maximum Payload Mass, enter 'Pa'.";
	string MainMenu4 = "To calculate Required Exhaust Velocity, enter 'Ve'.";
	string MainMenu5 = "To go back, enter 'U'.";
	string DeltaVee1 = "DV";
	string DeltaVee2 = "Dv";
	string DeltaVee3 = "dV";
	string DeltaVee4 = "dv";
	string Propellant1 = "MP";
	string Propellant2 = "Mp";
	string Propellant3 = "mP";
	string Propellant4 = "mp";
	string ExhaustVelocity1 = "VE";
	string ExhaustVelocity2 = "Ve";
	string ExhaustVelocity3 = "vE";
	string ExhaustVelocity4 = "ve";
	string MaximumPayload1 = "PA";
	string MaximumPayload2 = "Pa";
	string MaximumPayload3 = "pA";
	string MaximumPayload4 = "pa";
	string Up1 = "U";
	string Up2 = "u";
	string cycle;


	while (true)
{   
	cout << MainMenu1 << NEWLINE;
    cout << MainMenu2 << NEWLINE;
    cout << MainMenu3 << NEWLINE;
    cout << MainMenu4 << NEWLINE;
    cout << MainMenu5 << NEWLINE << NEWLINE;
    cin >> cycle;

    if ((cycle == DeltaVee1) || (cycle == DeltaVee2))
	{	DeltaVeeCalculation ();	}
	else if ((cycle == DeltaVee3) || (cycle == DeltaVee4)) {
      DeltaVeeCalculation ();
    } else if ((cycle == Propellant1) || (cycle == Propellant2)) {
      PropellantMassCalculation ();
    } else if ((cycle == Propellant3) || (cycle == Propellant4)) {
      PropellantMassCalculation ();
    } else if ((cycle == ExhaustVelocity1) || (cycle == ExhaustVelocity2)) {
      ExhaustVelocityCalculation ();
    } else if ((cycle == ExhaustVelocity3) || (cycle == ExhaustVelocity4)) {
      ExhaustVelocityCalculation ();
    } else if ((cycle == MaximumPayload1) || (cycle == MaximumPayload2)) {
      PayloadCalculation ();
    } else if ((cycle == MaximumPayload3) || (cycle == MaximumPayload4)) {
      PayloadCalculation ();
    }
	
	else if ((cycle == Up1) || (cycle == Up2)) 
	{
	  cout <<NEWLINE;
      break;	}
	else
	{	cout << NEWLINE;	}

	}
}

void MenuStage2 ()
{	
	string MainMenu1 = "To calculate Delta-Vee, enter 'Dv'.";
	string MainMenu2 = "To calculate Required Exhaust Velocity for Stage 1, enter 'Ve1'.";
	string MainMenu3 = "To calculate Required Exhaust Velocity for Stage 2, enter 'Ve2'.";
	string MainMenu4 = "To go back, enter 'U'.";
	string DeltaVee1 = "DV";
	string DeltaVee2 = "Dv";
	string DeltaVee3 = "dV";
	string DeltaVee4 = "dv";
	string ExhaustVelocity1 = "VE1";
	string ExhaustVelocity2 = "Ve1";
	string ExhaustVelocity3 = "vE1";
	string ExhaustVelocity4 = "ve1";
	string ExhaustVelocity5 = "VE2";
	string ExhaustVelocity6 = "Ve2";
	string ExhaustVelocity7 = "vE2";
	string ExhaustVelocity8 = "ve2";
	string Up1 = "U";
	string Up2 = "u";
	string cycle;


	while (true)
{   
    cout << MainMenu1 << NEWLINE;
    cout << MainMenu2 << NEWLINE;
    cout << MainMenu3 << NEWLINE;
    cout << MainMenu4 << NEWLINE << NEWLINE;
    cin >> cycle;

    if ((cycle == DeltaVee1) || (cycle == DeltaVee2))
	{	DeltaVeeCalculation2S ();	}
	else if ((cycle == DeltaVee3) || (cycle == DeltaVee4)) {
      DeltaVeeCalculation2S ();
	} else if ((cycle == ExhaustVelocity1) || (cycle == ExhaustVelocity2)) {
      ExhaustVelocityCalculation2SS1 ();
    } else if ((cycle == ExhaustVelocity3) || (cycle == ExhaustVelocity4)) {
      ExhaustVelocityCalculation2SS1 ();
    } else if ((cycle == ExhaustVelocity5) || (cycle == ExhaustVelocity6)) {
      ExhaustVelocityCalculation2SS2 ();
    } else if ((cycle == ExhaustVelocity7) || (cycle == ExhaustVelocity8)) {
      ExhaustVelocityCalculation2SS2 ();
    }
	
	else if ((cycle == Up1) || (cycle == Up2)) 
	{
	  cout <<NEWLINE;
      break;	}
	else
	{	cout << NEWLINE;	}

	}
}

void Introduction ()
{	string Intro = "Delta Vee! 1.04 by John Lawson";
	cout <<Intro;
	cout <<NEWLINE << NEWLINE;	}

double GiveameINPUT ()
{
	while(true)
	{
		cin >> data;
		if (!cin.fail())
		{	return data;	}
		cin.clear();
		cin.ignore();
	}
}

void DeltaVeeCalculation ()
{	string meterspersecond = "m/s";
	string hailprobe = "Hail the Probe!!!";
	string text1 = "Exhaust Velocity (m/s):";
	string text2 = "Dry Mass (kilograms):";
	string text3 = "RCS Fuel (kilograms):";
	string text4 = "Consumables Mass (kilograms):";
	string text5 = "Propellant Mass(kilograms):";
	string text6 = "Delta-Vee:";
	string text7 = "Crew Number:";

	cout <<NEWLINE;
	cout <<text1;
    singlestage.Vexh = GiveameINPUT();
	cout <<text2;
	singlestage.Md = GiveameINPUT();
	cout <<text3;
	singlestage.Mrcs = GiveameINPUT();
	cout <<text4;
	singlestage.Mcons = GiveameINPUT();
	cout <<text7;
	singlestage.Crew = GiveameINPUT();
	cout <<text5;
	singlestage.Mp = GiveameINPUT();

	Mp1 = (singlestage.Mp);

	Md1 = (singlestage.Md+singlestage.Mrcs+singlestage.Mcons+(singlestage.Crew*90));

	singlestage.DeeVee = singlestage.Vexh*(log((Mp1+Md1)/(Md1)));

	cout <<text6;
	cout <<TAB;
	cout <<singlestage.DeeVee;
	cout <<TAB;
	cout <<meterspersecond;
	cout <<NEWLINE;
	cout <<hailprobe;
	cout <<NEWLINE;
	cout <<NEWLINE;	}

void PropellantMassCalculation ()
{	string RequiredPropellantMass = "Propellant Required:";
	string hailprobe = "Hail the Probe!!!";
	string text1 = "Exhaust Velocity (m/s):";
	string text2 = "Dry Mass (kilograms):";
	string text3 = "Delta-Vee:";
	string text4 = "RCS Fuel (kilograms):";
	string text5 = "Consumables Mass (kilograms):";
	string text6 = "Crew Number:";
	string kilograms = "kg";


	cout <<NEWLINE;
	cout <<text1;
	singlestage.Vexh = GiveameINPUT();
	cout <<text2;
	singlestage.Md = GiveameINPUT();
	cout <<text4;
	singlestage.Mrcs = GiveameINPUT();
	cout <<text5;
	singlestage.Mcons = GiveameINPUT();
	cout <<text6;
	singlestage.Crew = GiveameINPUT();
	cout <<text3;
	singlestage.DeeVee = GiveameINPUT();

	Md1 = (singlestage.Md+singlestage.Mrcs+singlestage.Mcons+(singlestage.Crew*90));

	singlestage.Mp = ((exp(singlestage.DeeVee/singlestage.Vexh))*(Md1))-(Md1);

	cout <<RequiredPropellantMass;
	cout <<TAB;
	cout <<singlestage.Mp;
	cout <<TAB;
	cout <<kilograms;
	cout <<NEWLINE;
	cout <<hailprobe;
	cout <<NEWLINE;
	cout <<NEWLINE;	}

void ExhaustVelocityCalculation ()
{	string RequiredExhaustVelocity = "Exhaust Velocity Required:";
	string hailprobe = "Hail the Probe!!!";
	string text1 = "Dry Mass (kilograms):";
	string text2 = "RCS Fuel (kilograms):";
	string text3 = "Consumables Mass (kilograms):";
	string text4 = "Propellant Mass (kilograms):";
	string text5 = "Delta-Vee (m/s):";
	string text6 = "Crew Number:";
	string meterspersecond = "m/s";


	cout <<NEWLINE;
	cout <<text1;
	singlestage.Md = GiveameINPUT();
	cout <<text2;
	singlestage.Mrcs = GiveameINPUT();
	cout <<text3;
	singlestage.Mcons = GiveameINPUT();
	cout <<text4;
	singlestage.Mp = GiveameINPUT();
	cout <<text5;
	singlestage.DeeVee = GiveameINPUT();
	cout <<text6;
	singlestage.Crew = GiveameINPUT();

	Mp1 = (singlestage.Mp);

	Md1 = (singlestage.Md+singlestage.Mrcs+singlestage.Mcons+(singlestage.Crew*90));

	singlestage.Vexh = (singlestage.DeeVee/log((Mp1+Md1)/(Md1)));

	cout <<RequiredExhaustVelocity;
	cout <<TAB;
	cout <<singlestage.Vexh;
	cout <<TAB;
	cout <<meterspersecond;
	cout <<NEWLINE;
	cout <<hailprobe;
	cout <<NEWLINE;
	cout <<NEWLINE;	}

void PayloadCalculation ()
{	string MaximumPayloadMass = "Maximum Payload:";
	string hailprobe = "Hail the Probe!!!";
	string text1 = "Dry Mass (kilograms):";
	string text2 = "RCS Fuel (kilograms):";
	string text3 = "Consumables Mass (kilograms):";
	string text4 = "Propellant Mass (kilograms):";
	string text5 = "Exhaust Velocity (m/s):";
	string text6 = "Delta-Vee (m/s):";
	string text7 = "Crew Number:";
	string kilograms = "kg";


	cout <<NEWLINE;
	cout <<text1;
	singlestage.Md = GiveameINPUT();
	cout <<text2;
	singlestage.Mrcs = GiveameINPUT();
	cout <<text3;
	singlestage.Mcons = GiveameINPUT();
	cout <<text4;
	singlestage.Mp = GiveameINPUT();
	cout <<text5;
	singlestage.Vexh = GiveameINPUT();
	cout <<text6;
	singlestage.DeeVee = GiveameINPUT();
	cout <<text7;
	singlestage.Crew = GiveameINPUT();



	singlestage.Mp = ((singlestage.Mp/(exp(singlestage.DeeVee/singlestage.Vexh)-1))-singlestage.Md-singlestage.Mrcs-singlestage.Mcons-(singlestage.Crew*90));

	cout <<MaximumPayloadMass;
	cout <<TAB;
	cout <<singlestage.Mp;
	cout <<TAB;
	cout <<kilograms;
	cout <<NEWLINE;
	cout <<hailprobe;
	cout <<NEWLINE;
	cout <<NEWLINE;	}



///////////////////////////////////////////////////////////
///////////// 2 Stage calculator modes :) /////////////////
///////////////////////////////////////////////////////////



void DeltaVeeCalculation2S ()
{	string meterspersecond = "m/s";
	string hailprobe = "Hail the Probe!!!";
	string text1 = "Exhaust Velocity (m/s):";
	string text2 = "Dry Mass (kilograms):";
	string text3 = "RCS Fuel (kilograms):";
	string text4 = "Consumables Mass (kilograms):";
	string text5 = "Propellant Mass(kilograms):";
	string text6 = "Total Delta-Vee:";
	string text7 = "Crew Number:";

	string text8 = "Stage 1";
	string text9 = "Stage 2";

	cout <<NEWLINE;
	cout <<text8 << NEWLINE;

	cout <<NEWLINE;
	cout <<text1;
    firststage.Vexh = GiveameINPUT();
	cout <<text2;
	firststage.Md = GiveameINPUT();
	cout <<text3;
	firststage.Mrcs = GiveameINPUT();
	cout <<text4;
	firststage.Mcons = GiveameINPUT();
	cout <<text7;
	firststage.Crew = GiveameINPUT();
	cout <<text5;
	firststage.Mp = GiveameINPUT();

	cout <<NEWLINE;
	cout <<text9 << NEWLINE;

	cout <<NEWLINE;
	cout <<text1;
    secondstage.Vexh = GiveameINPUT();
	cout <<text2;
	secondstage.Md = GiveameINPUT();
	cout <<text3;
	secondstage.Mrcs = GiveameINPUT();
	cout <<text4;
	secondstage.Mcons = GiveameINPUT();
	cout <<text7;
	secondstage.Crew = GiveameINPUT();
	cout <<text5;
	secondstage.Mp = GiveameINPUT();



	Mp1 = (firststage.Mp);

	Md1 = (firststage.Md+firststage.Mrcs+firststage.Mcons+(firststage.Crew*90));

	Mp2 = (secondstage.Mp);

	Md2 = (secondstage.Md+secondstage.Mrcs+secondstage.Mcons+(secondstage.Crew*90));

	sumstages.DeeVee = ((secondstage.Vexh)*(log((Mp2+Md2)/(Md2)))) + ((firststage.Vexh)*(log((Mp1+Md1+Mp2+Md2)/(Mp2+Md1+Md2))));

	cout <<text6;
	cout <<TAB;
	cout <<sumstages.DeeVee;
	cout <<TAB;
	cout <<meterspersecond;
	cout <<NEWLINE;
	cout <<hailprobe;
	cout <<NEWLINE;
	cout <<NEWLINE;	}

void ExhaustVelocityCalculation2SS1 ()		// WIP Under Construction //
{	string RequiredExhaustVelocity = "Exhaust Velocity Required:";
	string hailprobe = "Hail the Probe!!!";
	string text1 = "Dry Mass (kilograms):";
	string text2 = "RCS Fuel (kilograms):";
	string text3 = "Consumables Mass (kilograms):";
	string text4 = "Propellant Mass (kilograms):";
	string text5 = "Delta-Vee (m/s):";
	string text6 = "Crew Number:";
	string meterspersecond = "m/s";

	string text8 = "Stage 1";
	string text9 = "Stage 2";

	string text10 = "Exhaust Velocity (m/s):";

	cout <<NEWLINE;
	cout <<text8 << NEWLINE;

	cout <<NEWLINE;
	cout <<text1;
	firststage.Md = GiveameINPUT();
	cout <<text2;
	firststage.Mrcs = GiveameINPUT();
	cout <<text3;
	firststage.Mcons = GiveameINPUT();
	cout <<text4;
	firststage.Mp = GiveameINPUT();
	cout <<text6;
	firststage.Crew = GiveameINPUT();

	cout <<NEWLINE;
	cout <<text9 << NEWLINE;

	cout <<NEWLINE;
	cout <<text1;
	secondstage.Md = GiveameINPUT();
	cout <<text2;
	secondstage.Mrcs = GiveameINPUT();
	cout <<text3;
	secondstage.Mcons = GiveameINPUT();
	cout <<text4;
	secondstage.Mp = GiveameINPUT();
	cout <<text6;
	secondstage.Crew = GiveameINPUT();
	cout <<text10;
	secondstage.Vexh = GiveameINPUT();

	cout <<text5;
	sumstages.DeeVee = GiveameINPUT();



	Mp1 = (firststage.Mp);

	Md1 = (firststage.Md+firststage.Mrcs+firststage.Mcons+(firststage.Crew*90));

	Mp2 = (secondstage.Mp);

	Md2 = (secondstage.Md+secondstage.Mrcs+secondstage.Mcons+(secondstage.Crew*90));

	firststage.Vexh = ((sumstages.DeeVee-(secondstage.Vexh*log((Md2+Mp2)/(Md2))))/(log((Md1+Mp1+Md2+Mp2)/(Md1+Mp2+Md2))));

	cout <<RequiredExhaustVelocity;
	cout <<TAB;
	cout <<firststage.Vexh;
	cout <<TAB;
	cout <<meterspersecond;
	cout <<NEWLINE;
	cout <<hailprobe;
	cout <<NEWLINE;
	cout <<NEWLINE;	}	// WIP Under Construction //

void ExhaustVelocityCalculation2SS2 ()		// WIP Under Construction //
{	string RequiredExhaustVelocity = "Exhaust Velocity Required:";
	string hailprobe = "Hail the Probe!!!";
	string text1 = "Dry Mass (kilograms):";
	string text2 = "RCS Fuel (kilograms):";
	string text3 = "Consumables Mass (kilograms):";
	string text4 = "Propellant Mass (kilograms):";
	string text5 = "Delta-Vee (m/s):";
	string text6 = "Crew Number:";
	string meterspersecond = "m/s";

	string text8 = "Stage 1";
	string text9 = "Stage 2";

	string text10 = "Exhaust Velocity (m/s):";

	cout <<NEWLINE;
	cout <<text8 << NEWLINE;

	cout <<NEWLINE;
	cout <<text1;
	firststage.Md = GiveameINPUT();
	cout <<text2;
	firststage.Mrcs = GiveameINPUT();
	cout <<text3;
	firststage.Mcons = GiveameINPUT();
	cout <<text4;
	firststage.Mp = GiveameINPUT();
	cout <<text6;
	firststage.Crew = GiveameINPUT();
	cout <<text10;
	firststage.Vexh = GiveameINPUT();

	cout <<NEWLINE;
	cout <<text9 << NEWLINE;

	cout <<NEWLINE;
	cout <<text1;
	secondstage.Md = GiveameINPUT();
	cout <<text2;
	secondstage.Mrcs = GiveameINPUT();
	cout <<text3;
	secondstage.Mcons = GiveameINPUT();
	cout <<text4;
	secondstage.Mp = GiveameINPUT();
	cout <<text6;
	secondstage.Crew = GiveameINPUT();

	cout <<text5;
	sumstages.DeeVee = GiveameINPUT();

	Mp1 = (firststage.Mp);

	Md1 = (firststage.Md+firststage.Mrcs+firststage.Mcons+(firststage.Crew*90));

	Mp2 = (secondstage.Mp);

	Md2 = (secondstage.Md+secondstage.Mrcs+secondstage.Mcons+(secondstage.Crew*90));

	secondstage.Vexh = ((sumstages.DeeVee-(firststage.Vexh*log((Md1+Mp1+Md2+Mp2)/(Md1+Md2+Mp2))))/(log((Md2+Mp2)/(Md2))));

	cout <<RequiredExhaustVelocity;
	cout <<TAB;
	cout <<secondstage.Vexh;
	cout <<TAB;
	cout <<meterspersecond;
	cout <<NEWLINE;
	cout <<hailprobe;
	cout <<NEWLINE;
	cout <<NEWLINE;	}	// WIP Under Construction //
 
Top