Page 4 of 5

Cobain Programming

Posted: Fri Dec 03, 2004 5:59 pm
by cobain
W00t! Thanks for your help, now this section of my book actually is about writing mathematical programs, but their's is useless, so mine I thought would be more complicated, but...ok, this is more of a math question than a C++ question, but what would a formula for this be?
http://www.bettycat.com/home/ages.html It tells your cat's age, but it varies up to year two, but at three and above, you just add three more years. How could I write an equation that would work in all instances (<--spelling?) no matter if the user inputs 3.956 or 2, just a consistent equation? All I really need is the equation I think, or equations. I think I could figure out the cout and cin stuff. You said making a program that would factor a trinomial or whatever would be a pain, do you mean by that that it would be complicated or just time consuming, but easy? What does the C++ thing "if" do? Could I do this?

Code: Select all

cout << "Input your cat's age.";
cin >> A
if A=1.5 << B
if A=2.5 << C
by that I am trying to say in probably improper C++ If A=1.5, then store A as B, so that they both have the same value.
I would actually use this command, but basically how do you say the following in proper C++ code? "if variable A = (a certain number) then duplicate variable A and store the duplicate as B. If variable A=2.5 then duplicate variable A and store the duplicate as C. The the program would later define variables B and C and "cout" them to the user. But I would like to know this stuff, but in my case, all I would need is a mathematical formula. But how does "if" work? And how can I make an option at the end of a console program that would let the user restart that program without closing it and opening it again? Oh yeah, can you do this

Code: Select all

X=(D+B)^2 
to raise (D+B) to the second power?
If that doesnt work, how would I be able to complete this:
E=(square root of(C-A)^2 + (D - B)^2) or this

F=((A + C)/2) Would the proper code for the F= thing be as I wrote it? What I really need is raising the variables inside the ( ) to the second or third, and also how could I do the cubed root or fourth root of something in proper code?

Posted: Fri Dec 03, 2004 7:02 pm
by JS Lemming
I clicked on that BettyCat link thing and was like why not just see how they did the equations. So I right clicked in order to view teh source and it goes "Thou Shall Not Steal! This Page is copyright by BettyCat 1999-2002". I'm like, you wish fool! So I bust through their half baked security and got a hold of the javascript for you.

Code: Select all

<script language="JavaScript"><!--
function Calculate()
{
	var strHYears = document.catcal.txHYears.value;	// Age of Cat in Human Years
	var dblHYears;										// As above as a number
	var dblCYears;										// Age of Cat in Cat Years

	document.catcal.txCYears.value = "";				// Initialise Result Textbox

	// Check input

	// Is it a number

	if (isNaN(parseFloat(strHYears)))
	{
		document.catcal.txCYears.value = "Error!";
		return;
	}

	dblHYears = parseFloat(strHYears);

	// Is it a stupid number

	if ((dblHYears < 0) || (dblHYears > 1000))
	{
		document.catcal.txCYears.value = "Error!";
		return;
	}

	// OK - we have something to work on - do the caulculation

	if (dblHYears <= 0.5)
		dblCYears = dblHYears * 26;
	else
	{
		dblCYears = 13;
		if (dblHYears <= 1)
			dblCYears = dblCYears + (dblHYears - 0.5) * 16;
		else
		{
			dblCYears = dblCYears + 8;
			if (dblHYears < 2)
				dblCYears = dblCYears + (dblHYears - 1) * 10;
			else
				dblCYears = dblCYears + 10 + (dblHYears - 2) * 3;
		}
	}

	document.catcal.txCYears.value = Math.round(dblCYears * 100) / 100;

}

// --></script>

BTW Cobain, you might want to reread the control flow chapter again. Those if statements of yours look like horribly mutated couts. J/K

Posted: Sat Dec 04, 2004 2:00 pm
by cobain
thx man! Half baked security eh? That mean firewall? Anywho thanks alot, and how can I make that javascript be in C++? BTW, my "if" statements are similar to my calculator programs, when writing a program for the TI 83+, there are a list of commands you can use and "if" is one of them, and I thought that the if command may be used in similar contexts in C++ and writing calculator programs, although they are nothing alike. I have heard nothing of, flow functions is it? But thanks for that cat age stuff. :D

JS Lemming, I hate to ask you to do this and if its stealing or illegal or soemthing, then w/e, but if you dont mind I could pay you a little @ school for this.
http://www.ticalc.org/archives/files/fi ... 15854.html

That is a calculator program that helps w/ factoring trinomials, but I dont have the right cables and software to get that program from the comptuer to my calculator. Is there any way that you (or I can do it if it is fairly simple) can see the entire code of that program, or just the stuff it uses, so that I may copy that from here to my calculator. BTW, if you do do this, or tell me how, I will give this code or anything to no one. Although If you feel uncomfortable about this ( is it "stealing" if it for one's personal use?), then dont worry about it. If you would rather not post the code or wanna email me or w/e, my email is
ductiledogg@yahoo.com

Posted: Sat Dec 04, 2004 2:24 pm
by JS Lemming
Nah, I don't think its stealing. But the problem lies in the fact that we don't have a font to represent the strange symbols that the TI has. But this is probably easy to decipher.

Code: Select all

ClrHome
Disp "Sean WeeKs(2000)",""
Input " add TO Get:",A
Input "MuLt TO Get:",B
Disp "",""
abs(A)üC
abs(B)üN
úNüF
If A>0 and B>0
1üF
For(Z,F,N)
If Z=0
End
If B/Z=int(B/Z)
Then
If B/Z+Z=A
Then
B/ZüG
ZüH
Output(6,1,"     and      ")
Output(6,1,G)
Output(6,10,H)
Stop
End
End
End
Disp "NON-EXISTANT"
Stop
Ok, by the looks of it, "ú" might be the negative sign, and "ü" is most likely the little store arrow sign.

Posted: Sat Dec 04, 2004 3:37 pm
by cobain

Code: Select all

#include <iostream>
#include <stdlib.h>
#include <cmath>
float A, B, C, D, E, F, G, H, I, J, V, X, Y, Z;
using namespace std;

int main(int argc, char *argv[])
{
  cout << "This program finds the distance, midpoint, and slope of a line having you put in two coordinates.";
  cout << "Another way of looking at this X1 and Y1 stuff is: (X1, Y1) (X2, Y2).  Those being two points on the graph that you wish to obtain the information about. 
  cout << "\n X1=?";
  cin >> A;
  cout << "\n Y1=?";
  cin >> B;
  cout << "\n X2=?";
  cin >> C;
  cout << "\n Y2=?";
  cin >> D;
  
 
            // True equation for finding the distance given the above variables is: _=square root of((C-A)^2+(D-B)^2)
  E=(C-A);
      // V= (C-A)^2
      V=pow(E, 2);
      I=(D-B);
      // X= (D-B)^2
      X=pow(I, 2);
      //Y= (D-B)^2 + (C-A)^2
      Y=(V+X);
      Z=sqrt(Y);
      // Now Z= the _ in the above equation
   
         
      // F and G are the coordinates of the midpoint, F being the X and G being the Y.  (X, Y)
  F=((A+C)/2);
  G=((B+D)/2);
  
  
      // H is the slope of the line formed by connecting the two points.
  H=((D-B)/(C-A));
  
  cout << "\n\n\n The distance between the two points is:" << Z;
  cout << "\n\n The midpoint is:" << F << G;
  cout << "\n\n The slope of the line is:" << H;
  int DumbyVar;
  cin >> DumbyVar;
  return 0;
}
Down at the bottom where it displays F and G, how can I make those appear like this? (F, G)?

Posted: Sat Dec 04, 2004 3:43 pm
by Falco Girgis

Code: Select all

cout << "\n\n The midpoint is: (" << F << "," << G << ")"; 
:watiff:

Posted: Sun Dec 05, 2004 8:39 pm
by JS Lemming
yep yep.

Posted: Sun Dec 05, 2004 9:29 pm
by cobain
Hi, my book mentions "long int", "short int", and just plain "int". What is the difference in them? Secondly, it says this is sometimes used to define variables instead of the "int"s and "float"s: it is "wchar_t" It doesn't specify what it is used for though, what is it used for? Lastly, for now, my book uses this, but I dont understand how it works and what does what. Embedded in other code that I do understand lie these lines.

Code: Select all

char StopCharacter;
cout << endl << "Press a key and \"Enter\": ";
cin >> StopCharacter
The book says this pauses the program until the user hits a key and then hit enter. Is StopCharacter the name of a variable or something? Does that name have anything to do with the program pausing until the user hits a key then hits enter? O yea, and for the record David Bowie is pretty good in my opinion. :D

Posted: Mon Dec 06, 2004 7:27 am
by JS Lemming
its just a version of the dumbyvar deal. REMEMBER--- variable names mean nothing to the actual program!!! When compiled, they simply become numbers.

Posted: Wed Dec 08, 2004 8:26 pm
by Don Pwnious
Aaahhhhhh, Quit with the "my book"," the book", or any form of it!!!!

Posted: Wed Dec 08, 2004 8:33 pm
by cobain
Would you prefer I say "in book it says..."? WTF do you want me to say? Where is your locker at CHS, is nick your little brother? I know him.

Posted: Thu Dec 09, 2004 9:53 pm
by MarauderIIC
http://www.phim.unibe.ch/comp_doc/c_man ... types.html writes:

Code: Select all

 Modifiers
The three data types above have the following modifiers.

    * short
    * long
    * signed
    * unsigned 

The modifiers define the amount of storage allocated to the variable. The amount of storage allocated is not cast in stone. ANSI has the following rules:

        short int <=    int <= long int
            float <= double <= long double

What this means is that a 'short int' should assign less than or the same amount of storage as an 'int' and the 'int' should be less or the same bytes than a 'long int'. What this means in the real world is:

                 Type  Bytes  Bits                Range

            short int    2      16          -32,768 -> +32,767          (32kb)
   unsigned short int    2      16                0 -> +65,535          (64Kb)
         unsigned int    4      32                0 -> +4,294,967,295   ( 4Gb)
                  int    4      32   -2,147,483,648 -> +2,147,483,647   ( 2Gb)
             long int    4      32   -2,147,483,648 -> +2,147,483,647   ( 2Gb)
          signed char    1       8             -128 -> +127
        unsigned char    1       8                0 -> +255
                float    4      32
               double    8      64
          long double   12      96

These figures only apply to todays generation of PCs. Mainframes and midrange machines could use different figures, but would still comply with the rule above.

You can find out how much storage is allocated to a data type by using the sizeof operator.

Posted: Sun Dec 19, 2004 2:07 pm
by cobain
do any of y'all know any good java decompilers? Also, how might I be able to obtain the source code for an online game when it isn't open sourced? How can I change my ip address, my ISP did give us a copule that we can switch to and stuff, but how can I do that? Is it in the ipconfig command somewhere?

Posted: Sun Dec 19, 2004 2:44 pm
by Falco Girgis
Dude, you're kidding.

First off all, how the hell do you plan to get the source of a java applet that is on the server.

Java isn't really a compiled language.

It is compiled into bytecode or something and is then interpretted.

IPConfig only changes your internal IP address, only your ISP can change your external one.

Dude, chill out. There is nothing you can do about anything. The whole Java ordeal is completely impossible. As a matter of fact, everything is. What's up with you?

Posted: Sun Dec 19, 2004 3:42 pm
by cobain
Um...you can obtain the source code by hacking the host's comptuer via his ip, given he has no proxy first of all. From there you can proceed to get to the files and whatnot, but then they're in java. You cannot do a whole lot w/ them when they're in java, which is why i need them in...something else. The ip thing I was just curious about because I was told there is some ipconfig command that can change your ip, I think he said it was:
Ipconfig/ release
but I don't know, and I didnt wanna mess up my machine. I was just wondering about all of it, nothing meant by any of it. I am completely chilled. :D Just wondering how because I was told that it can be done from the command promtp, but w/e. And what is an internal ip? I suppose an exteranl IP is the one that it recognizes when you go to www.whatismyip.com , but what is an internal IP even used for?