All you need to know is the slope formula, and how to create a mx+b line.
Do you know how to do that?
MosaicFuneral commented: lol, That's some sweet shit! +0
All you need to know is the slope formula, and how to create a mx+b line.
Do you know how to do that?
Good Luck. Looks like its coming out fine so far.
>>it's not coming out right... can anyone help?
I would but can you be more descriptive?
They will pretty much teach you the same thing at least the concept part,
like loops, if else statements, control flow, variables, ints, floats ,blah blah
blah.
I think if you take C++, then picking up C by your self is not hard. If you
had to pick 1 , I would suggest picking C++, if you wan't to take both,
then go ahead. If both of these class becomes a big load to handle,
then drop 1 of the, I suggest C.
Hmm, I must be rusty, int/int = int correct?
If by that you mean an integer number divided by an integer
number will result in the integer division, so :
float area = 1/2;
Above area is 0 since 1 is an integer and so is 2.
I think you mean something like this :
float foo( float left){ return left/2; }
and a cal like this :
foo(1);
That code should produce 0.5 because the parameter is expecting
a float but a int is passed. So the compiler implicitly promotes
the int to a float. So the division is just like doing this : 1.0f/2 = 0.5
Google Arrays.sort.
Just get the user input into an array, and use Arrays.sort( anArray),
then the anArray is sorted.
yea thats not a compiler error message. you could say that its a remark, i guess the code i wrote doesnt do what it wants me to. but i dont understand what it wants. what i wrote looks right to me, but it says its wrong so its wrong.
Is "it" a online judge? If so then post the question.
Use the mode (%) operator inside a for loop like so :
final int MAX = 100;
for(int i = 1; i < MAX; ++i){
if(i % 2 == 0 ) /* if i is a multiple of 2 */
{ //do stuff }
else if(i % 3 == 0 )/* if i is a multiple of 3 */
{// do stuff }
else if( i % 5 == 0 ) /* if i is a multiple of 5 */
{ //do stuff }
}
you are probably reading/writing a invalid memory.
That tells me that you are updating the ball late. Specifically, you have
some render method inside you move function or you call some render
function inside your move function. Do you have a render function for
the pacman thats being called inside the move function or do you
draw the pacman on the move function( whatever the move function maybe)?
C++ should automatically convert the int into a double, if I'm not mistaken.
Not in this case.
@OP , You have this prototype :
double fuelconsumption(int litre, kilometer);
Its wrong. It should be :
double fuelconsumption(double litre, double kilometer);
Notice you need to specify each variable type.
Make the same change to its definition. And add what jonsca said.
nodePtr->setPosition( 0, -80, 0 );
assuming its setPosition( x , y , z), then your x is 0 and your wall is
just at position (0,-80). You can just check if the pacman + its radius is
at posX = 0, and at posY = -80. If so then a collision is detected, else not.
This assumes that the pacman can't hit the wall from behind.
If I misunderstood, then maybe a snapshot would help more.
What is wall? How do you have it oriented. Depending of the orientations
of the wall, the collision detection will be easy or harder.
did you try the red book?
Alternativly, you give each object a unique color and easily go about
selection from there.
1. use win32 with directx
2. use win32 with opengl
3. use java with opengl.
4. make a wrapper of win32 in c++ of the things you need, and use either opengl/glut or directx
You don't. Use c++ clock() or if you are on windows, use queryPerformaceCounter.
>>litre per 100 km.
means :
litre / (100 * km )
but I want it to look like this.
**
***
****
****
***
**
1) Make a function called : printStar(int num);
Where it prints num of stars :
For example a call to printStar(4) would produce :
****
or a call to printStar(2) would produce : ***
After you make that function you can make your loop start at
2 end at 4 then decrease to 2.
So
for(int i = 2; i <= 4; i++)
printStars(i); //prints i amount of stars with a newline
for(int j = 4; j >= 2; --j)
printStars(j); //prints j amount of starts with a newline
Then thats it!
Thanks for your help..:) If I post my code, someone who studies in my university can find the code and copy it. Because we like research on internet and copy it:D So it become plagiarism and I can go to discipline. I am frightened about this issue.:D
Ok then.
Here are some tips.
1) Whenever you have "new" keyword used, match it with a "delete"
keyword. Make sure there is a 1 to 1 relationship there.
2) Instead of raw pointers, use smart pointers or auto_ptr.
They will destroy the pointer for you.
3) Or PM someone and they might help you out a bit more, if you want
I have to creat a program where the user inputs two large ints, and they are converted into string in order to add them together (assuming they are larger than 20 characters). One thing, is that it tells me to convert the numbers to a string and store it in reverse order....how do I do this?
Thats not smart. How about just getting the inputs as a string and
avoid the conversion? Try looking at the code snippet here.
#include<iostream> /**/
#include<string>
using std::cout; using std::string; std::ostream& _H_A_P_P_Y_T_H_A_N_K_S_G_I_V_I_N_G = cout;
/******************************************************************//**/
string _____("H H A P P P P P P P P Y Y\n");
string _______________(" T G G G I I I V I I I N N \n\n\n");
string ______("H H A A P P P P Y Y\n");
string ______________(" T G G G I V V I N N N \n");
string ________("H H A A P P Y\n");
string _____________(" T G G G I V V I N N N \n");
string _________("H H A A P P Y\n\n\n\n");
string _______("H H H H H A A A P P P P P P P P Y\n");
string __________("T T T T G G G G I I I V V I I I N N \n");
string ___________(" T G I V V I N N N \n");
string ____________(" T --------- G G I V V I N N N \n");
/******************************************************************/
int main()/**/
{
_H_A_P_P_Y_T_H_A_N_K_S_G_I_V_I_N_G<<_____;
_H_A_P_P_Y_T_H_A_N_K_S_G_I_V_I_N_G<<______;
_H_A_P_P_Y_T_H_A_N_K_S_G_I_V_I_N_G<<_______;_H_A_P_P_Y_T_H_A_N_K_S_G_I_V_I_N_G<<________;
_H_A_P_P_Y_T_H_A_N_K_S_G_I_V_I_N_G<<_________;_H_A_P_P_Y_T_H_A_N_K_S_G_I_V_I_N_G<<__________;
_H_A_P_P_Y_T_H_A_N_K_S_G_I_V_I_N_G<<___________;_H_A_P_P_Y_T_H_A_N_K_S_G_I_V_I_N_G<<____________;
_H_A_P_P_Y_T_H_A_N_K_S_G_I_V_I_N_G<<_____________;_H_A_P_P_Y_T_H_A_N_K_S_G_I_V_I_N_G<<______________;
_H_A_P_P_Y_T_H_A_N_K_S_G_I_V_I_N_G<<_______________;
}
Int this class :
//This is the header file figure.h.
using std::cout;
class figure
{
public:
virtual void center();
void draw();
void erase();
};
void figure::center()
{
cout << "Centering the Figure";
cout << "\n";
cout << "\n";
You should make draw a virtual function because you each object that
derives from it, will have a different draw method. For example,
a rectangle that derives from figure will have a different draw method
than a circle or a sphere.
post your code and you will get more help
your function prototype :
void Start(long remainder,long& countZero, long& countOdd, long& countEven);
your function defintion :
void start(long remainder,long& countZero, long& countOdd, long& countEven)
The 's' is not capitalize in the second one. Also I do not see any point
for makeing this function. Also you forgot '&' before the remainder variable.
In what sense of "Marketing"?
using structs or classes would be easier and more elegant. What do
you think?
Disregarding the header and the bottom of the table and just
considering the inside of the table you can simply just do this :
for(int i = Max; i >= Min; --i){
//print i
//print '!'
//print \t
//prints (i)*(i-1)*(i-2)*...(1)
//print factorial of i
//print new line
}
What part of them is troubling you?
You will only need this :
struct Letter
{
//variables
char representiveLetter;
int numberOfOccurance;
//constructor.
Letter() {
representiveLetter = 0;
numberOfOccurance = 0;
}
};
From there you can do the program easy.
Would you mind using structs?
>With that in mind generating a random character is easy:
>char randomUpperCase= 'A' + rand() % 26;
>char randomLowerCase= 'a' + rand() % 26;
Easy if you ignore the portability issue. The only characters that are guaranteed to be consecutive in C++ are the decimal digits '0'-'9'. Your code in a different character set (EBCDIC, for example), would not work as expected. Compare to a portable solution that specifies the set to extract from:char ruc = "abcdefghijklmnopqrstuvwxyz"[rand() % 26]; char rlc = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[rand() % 26];
Ok, didn't know that. Learn something new everyday.
In all of your program you have never initialized the Size variable!
I didn't know that the array has to be sorted from the number of occurrence, sorry.
Edit : would you mind using something like map. It would be
easy. Or actually using struct would be easy too. And you can use the
std::sort, so you don't have to sort it. Or we can make another
array and goon from there.
I wonder if there is any function that returns the difference in minutes for examples like this:
1300-1515 (135 minutes)
2350-0100 (70 minutes)
Is there any timefunction that can have the ability to return the minutedifference ?
Are you sure those calculations are correct?
Since thanksgiving is soon here, I thought we would have our
own daniweb feast, specifically an obscure feast. Remember that
only obscure code is valid in our obscure table.
I'll start :
#include<iostream>
#include<string>
using namespace std; ostream& ____ = cout;
string _____ = "hello";string
______ ("world"); string
_______
("obscure");char _
(' '); char __('\n');
int main()
{
____<<
_____<< _ <<
_______<< _<<
______<< __;
}
When I just list it as
sortStrategy* strategy;
the compiler says that I must specify a type. I'm trying to set a private variable of class sortStrategy.
You paid no attention to my last post.
This is you sortStrategy class :
class sortStrategy {
public:
virtual sortStrategyOption sort(string students[100]) = 0;
};
It uses pure virtual function, ( the " = 0" part and the virtual part makes it pure virtual function). If a class has a pure virtual function,
it cannot instantiate an object of it! Remember that.
When you do this :
sortStrategy * strategy;
It is wrong. First that code does not instantiate an object yet,
because its a pointer to strategy. And when it does, it will be
an error because the sortStrategy class is an Abstract base class,
and that means no one can make on object of it. If you want
to make an object of it, then take out the " = 0 " part in your
sortStrategyOption function.
The function uses the & operator. That operator makes a variable
synonym.
For example :
int num = 10 ;
int &ref_num = num;
ref_num = 4; //same as doing num = 4
So similarly, since this function :
istream& read(istream& is, Student_info& s)
Take a look at this part :
istream& is, Student_info& s
What ever we pass to that function ( assuming its acceptable),
is becomes a synonym, and s becomes a synonym.
So say this is how we call the that function
read( cin, anStudentObject ); //function call
Since the prototype is :
istream& read(istream& is, Student_info& s)
and since cin is a istream object, and anStudentObject is a Student_info object, that function call is acceptable.
You remember what the & operator does right? Passing in , cin and
Student_info makes the variable, "is" and "s" synonym to cin and anStudentObject , respectively. So using the "is" variable is like
using the cin variable, its just a different name. Ok?
The reason it returns a istream object is to show you that it can.
And when you get to operator overloading you will see the significance
of it.
But know that you can do this :
Student_info& student;
//...insert info into s
//call your read function and since it returns an object, we can use it cin again
read(cin , student).clear()
Before you open it, check if the file is already opened at your save function.
firstPerson, I noticed the 4 about 10 minutes after my last post. lol!! Anyway, I had already changed that and I also had initialized my 2nd array...still the same result. I thought it was a waste also, but I have a selection sort I want to apply and I'm afraid I might mess something up by tinkering with the original array.
Do a test run.
Don't use that program. In fact comment out the whole program.
Then at the top, start a new program that tries to get the insertion
sort to work, with some random char arrays. After you get that to
work, then copy that function. Delete this program you just started,
and uncomment the old program. Then just add the sorting function
in there.
You cannot instantiate an abstract class. You cannot instantiate an abstract class. You cannot instantiate an abstract class. You cannot instantiate an abstract class. You cannot instantiate an abstract class. You cannot instantiate an abstract class. You cannot instantiate an abstract class. You cannot instantiate an abstract class. You cannot instantiate an abstract class. You cannot instantiate an abstract class. You cannot instantiate an abstract class. You cannot instantiate an abstract class. You cannot instantiate an abstract class. You cannot instantiate an abstract class. You cannot instantiate an abstract class. You cannot instantiate an abstract class.
You should know that if you are using pure virtual functions.
Also I am query about your inheritance. I think using class composition is a better idea. Let sortStrategy compose all
of the sorting methods and don't let it be an abstract base class.
And why do you have the class word here anyway :
class sortStrategy* strategy;
Thats not doing what you think its doing.
This is when you can use a pointer that takes an refrence.
Try adding this :
bool list_add(int (&list)[], int& space_used, int max_size, int value)
Now list is an reference variable which happens to be an array.
Also only incrementing max_size by 1 is a bad idea. Try doubling it.
In fact do a test and see how much faster doubling the max_size is.
The STL vectors uses this idea.
Just make a function that returns a random lowercase or a random uppercase depending on the parameter.
Do you know how to generate random values ?
srand( time(0) ); //#include<ctime> needed for time function
int randomNum = rand();
With that in mind generating a random character is easy :
char randomUpperCase= 'A' + rand() % 26;
char randomLowerCase= 'a' + rand() % 26;
Your copygetChar function is wrong. First you want to go through
the array from 'A' to 'Z' to check for its occurance. You are only going through 0 to 4.
Second initialize your variables. In this case, in your copygetChar function, initialize copyallCount[256] = {0};
Third why do you need that function. You can show the letters
that aren't recorded 0 times in you main function. It seems to me like
its a waste.
You have 1 extra comma in your array initialize list.
And this code :
char i = rand(letters[i]);
is wrong. rand does not take anything it its parameter.
This is how to use it.
int randomNumber = rand();
Also there is a subtle bug in your program.
You need to set every element in that array from junk to 0.
size_t allCount[256] = {0};
And take out that cin.ignore. You are ignoring the characters that are left in the buffer when you need to read them
and see if there is a '.'
Also try making a function to print the stats like so :
void printStat(size_t Array[], const size_t Size)
{
//error check if you want
cout<<"\n\nUpper character stats : \n\n";
for(char i = 'A'; i <= 'Z' && i < Size; i++){
cout<< i <<" count = " << Array[i] << endl;
}
}
It's probably reading the extra newline at the end of your file.
Yes, look into vectors, not the STL ones but the mathematical ones.
how about you give it some thought, first?
Ok, I see what you are trying to do. Here is an idea.
You know there are 256 different character that char can hold.
so create an array of 256
size_t allCount[256];
Now you need to read in character by character.
char ch = 0;
char end = '.';
while( cin.get(ch) && ch != end ) continue;
But when you read the character you can also increment its count at
the same count.
size_t allCount[256]
char ch = 0;
char end = '.';
while( cin.get(ch) && ch != end ){
allCount[ch] += 1;
}
//print out result
what you can also do inside the loop is check if ch is a valid character
to count, if so then increment it, otherwise skip it.
Tell me how that goes so far.