[QUOTE=ShaunOfTheLive;37789390]Well first of all, you're doing comparison when you should be doing assignment, for example:
firstNames[n] == fNameTest[n];
should be
firstNames[n] = fNameTest[n];[/QUOTE]
i want to copy the contents of fNameTest into firstNames
[editline]24th September 2012[/editline]
oh i see
[editline]24th September 2012[/editline]
THANK YOU ITS WORKS FLAWLESSLY NOW
Hi, i'm trying to make a Roguelike "engine" sort of thing in C#, and i'm making a console for it. Now, I want to be able to load maps from this console by typing in "map mapname." I've managed to get a thing that just adds all the maps to a list of strings, and I figured i'd be able to do something with that, but I don't know what to do. Can anyone help?
[QUOTE=Killowatt;37789804]Hi, i'm trying to make a Roguelike "engine" sort of thing in C#, and i'm making a console for it. Now, I want to be able to load maps from this console by typing in "map mapname." I've managed to get a thing that just adds all the maps to a list of strings, and I figured i'd be able to do something with that, but I don't know what to do. Can anyone help?[/QUOTE]
Not sure what you want but you can open a file with the filename "mapname" using StreamReader or something. Make sure that the file exist using File.Exists() first.
Some silly homework questions, i wanna make sure my answers are right.
Question 1:
What is the result of ‘10’ – 10? [‘10’ stands for the ASCII digits 10]
My reply:
[code]
Firstly, we note that the ASCII digits '1' and '0' are 0x31 and 0x30 in hexadecimal, respectively. The string '10' translates to binary as such:
0011 0001 0011 0000.
The decimal number 10 translates to 0000 0000 0000 1010 in binary.
We subtract:
1 212
0011 0001 0011 0000
0000 0000 0000 1010 (-)
…......................
0011 0001 0001 1110
Our result, translated back to hex is 0x31, 0x1E.[/code]
How did i do?
Also, here's an easier question, i just wanna make sure i didn't miss something since it seems... too easy.
Suppose a 32-bit word on a computer contains the hexadecimal data 301B7C0A. This word can also be interpreted as two half-words, 301B and 7C0A respectively. If the data is 8-bit ASCII character string, what is the actual string?
My answer:
[code]0x301B7C0A represented as an 8-bit ASCII character string would be '0[ESC]|[LF]' where [ESC] and [LF] are control characters.[/code]
so i'm supposed to make a program in c++ that asks the user to input a number and then the program will tell the user the prime numbers less than or equal to the input
the previous question had me write a program that only told the user if the number they inputted was prime or not
this was the code i made for the previous question
[CODE]#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
int a, b;
a = 0;
b = 2;
cout<<"Enter a number."<<endl;
cin>>a;
if (a == 2)
{cout<<"The number is prime."<<endl;}
while (a % b != 0)
{
b++;
if (a == b)
{cout<<"The number is prime."<<endl;}
}
if (a % b == 0 && a != b)
{
cout<<"The number is not prime."<<endl;
}
system("PAUSE");
return EXIT_SUCCESS;
}
[/CODE]
whenever i declare the integer c, i am unsure of how to put it in a loop that checks all the prime numbers less than or equal to a
never mind get money get paid i figured it out
so I have this polynomial code:
[cpp]polynomial operator +( polynomial& b) {
polynomial a = *this;
polynomial c;
for (int i = 0; i <= a.deg; i++) c.c[i] += a.c[i];
for (int i = 0; i <= b.deg; i++) c.c[i] += b.c[i];
c.deg = c.c.size() + 1;
return c;
}[/cpp]
I get this error on compile once it hits this function and returns.
[QUOTE]/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/stl_vector.h:(.text$_ZN10polynomialC1ERKS_[polynomial::polynomial(polynomial const&)]+0x14): undefined reference to `bag::bag(bag const&)'[/QUOTE]
Member variable c is a dynamic array (class name bag) and I'm thinking my problem is that I don't have overloaded polynomial copy ctors or assignment operators. Second opinion before I have an aneurysm?
[QUOTE=twoski;37802169]Also, here's an easier question, i just wanna make sure i didn't miss something since it seems... too easy.
Suppose a 32-bit word on a computer contains the hexadecimal data 301B7C0A. This word can also be interpreted as two half-words, 301B and 7C0A respectively. If the data is 8-bit ASCII character string, what is the actual string?
My answer:
[code]0x301B7C0A represented as an 8-bit ASCII character string would be '0[ESC]|[LF]' where [ESC] and [LF] are control characters.[/code][/QUOTE]
It depends on the processor architecture but in most cases assigning that hexadecimal to a 32-bit word would result with the bytes being in the order 0x0A, 0x7C, 0x1B, 0x30.
[QUOTE=Protocol7;37803068]so I have this polynomial code:
[cpp]polynomial operator +( polynomial& b) {
polynomial a = *this;
polynomial c;
for (int i = 0; i <= a.deg; i++) c.c[i] += a.c[i];
for (int i = 0; i <= b.deg; i++) c.c[i] += b.c[i];
c.deg = c.c.size() + 1;
return c;
}[/cpp]
I get this error on compile once it hits this function and returns.
Member variable c is a dynamic array (class name bag) and I'm thinking my problem is that I don't have overloaded polynomial copy ctors or assignment operators. Second opinion before I have an aneurysm?[/QUOTE]
I had no overloaded assignment operator so I got rid of it and replaced my a's with this-> and it worked
[QUOTE=ThePuska;37803108]It depends on the processor architecture but in most cases assigning that hexadecimal to a 32-bit word would result with the bytes being in the order 0x0A, 0x7C, 0x1B, 0x30.[/QUOTE]
It's a really general question, there's no mention of what processor. Just that it's a 32 bit word.
I take it my conversion to ASCII was right? It just seems weird that the string is jibberish with control characters. My prof is a bit of a shitbird so it could be correct though.
I'm doing an assignment using the Win32 API and am having a problem which is probably really amateur.The problem is in my program unused characters in a TextOut function appear as rectangles. So, for example, if I tell TextOut that there the string is 20 characters long when the string is only 15 there will be 5 rectangles when the text is drawn.
Here is a screenshot to further illustrate the issue:
[IMG]http://i.imgur.com/wFk1J.png[/IMG]
Should be pretty obvious but if you don't understand the issue it is where there is all the rectangles tailing "Player 4 takes 1 sticks."
Edit:I feel I should mention that a couple of other people doing the same thing did not encounter this issue.
As a last resort I may just try count the numbers of characters in the string and make that a variable for the TextOut.
[QUOTE=Black0ut;37803622]I'm doing an assignment using the Win32 API and am having a problem which is probably really amateur.The problem is in my program unused characters in a TextOut function appear as rectangles. So, for example, if I tell TextOut that there the string is 20 characters long when the string is only 15 there will be 5 rectangles when the text is drawn.
Here is a screenshot to further illustrate the issue:
[IMG]http://i.imgur.com/wFk1J.png[/IMG]
Should be pretty obvious but if you don't understand the issue it is where there is all the rectangles tailing "Player 4 takes 1 sticks."
Edit:I feel I should mention that a couple of other people doing the same thing did not encounter this issue.
As a last resort I may just try count the numbers of characters in the string and make that a variable for the TextOut.[/QUOTE]
The [url=http://msdn.microsoft.com/en-us/library/windows/desktop/dd145133(v=vs.85).aspx]MSDN page[/url] for TextOut says that the last parameter specifies the length of the string to print out. You want to measure your string using something like _tcslen(), as far as I can tell.
[QUOTE=Chris220;37804853]The [url=http://msdn.microsoft.com/en-us/library/windows/desktop/dd145133(v=vs.85).aspx]MSDN page[/url] for TextOut says that the last parameter specifies the length of the string to print out. You want to measure your string using something like _tcslen(), as far as I can tell.[/QUOTE]
While I am sure it would work I don't believe it is necessary as I others are not using it as far as I am aware. I will look into it though.
[QUOTE=Black0ut;37804881]While I am sure it would work I don't believe it is necessary as I others are not using it as far as I am aware. I will look into it though.[/QUOTE]
The only other way the function could work is for the string to be null-terminated, but the MSDN article specifically states that this is not how the function works.
You can try setting cchCount to -1 if your string is null-terminated, but it's not guaranteed to work.
Unfortunately setting it to -1 just causes it not to draw. I'll probably have a try at getting the strings length after I get another assignment out of the way.
[editline]26th September 2012[/editline]
Fixed it in 2 seconds using strlen(). I feel like an idiot now, thanks for the help though.
I totally blow at math, so I need a little help with a simple formula.
What I'm trying to do is randomized exponential distribution between [0,1] (the closer to 1, the more unlikely)
I've done something like this:
[cpp]
float expdrand()
{
return -1 * math.log(1-math.random()); // math.random being a random real [0,1]
}
[/cpp]
It does something very similar to what I want, but not to my expectation. (It sometimes generates numbers >= 1! D: )
math.pow(math.random(), a)
where a > 1
It might just be that I didn't get enough sleep last night, but I don't think that's what I need.
I'm looking for something like a regular random() [0,1] function, but it's more likely to generate a number closer to zero than one.
[QUOTE=ief014;37807382]It might just be that I didn't get enough sleep last night, but I don't think that's what I need.
I'm looking for something like a regular random() [0,1] function, but it's more likely to generate a number closer to zero than one.[/QUOTE]
That's what you get if you divide his formula by the max random number.
If math.random() gives a number between inclusive [0, 1], raising it to any power a > 1 doesn't change the codomain but will increase the probability of lower numbers.
[QUOTE=ief014;37807382]It might just be that I didn't get enough sleep last night, but I don't think that's what I need.
I'm looking for something like a regular random() [0,1] function, but it's more likely to generate a number closer to zero than one.[/QUOTE]
Using the formula that ThePuska posted does this; As a increases, the chance that a number is generated above 0.5 decreases (ie, they are more likely to be closer to zero):
[img]https://dl.dropbox.com/u/13368050/exprand.png[/img]
Ah, got it :)
Thanks guys
I am taking a class in data structures. The teacher that is teaching it, is literally the worst teacher I have ever had. I haven't learned a thing with him. It would be awesome if someone could push me in the right direction on this homework assignment.
There will be two .txt files each containing a matrix. We have to store each matrix as a linked list of rows or columns and multiply the two matrices. What I am having trouble with is reading each matrix.
[cpp]
#example 1
#Matrix A, I matrix, notice zero entries are omitted
#i j value
1 1 2
2 2 2
#Matrix B
1 1 2
2 1 4
#Matrix C, result
1 1 4
2 1 8
[/cpp]
Through help from another website I found this. The problem is I don't know how to make it go to the next line, and on top of that filling in the zeros where they need be.
[code]
void matrix::read_file(char fn[LGMAX+1])
{
int n,m,i,j,k;
ifstream a(fn,ios::in);
a>>m; //rows
a>>n; //cols
while (a)
{
a>>i;
a>>j;
a>>k;
insert_remove(i,j,k);
}
a.close();
}
[/code]
I am really lost in this class, so ANY help would be awesome.
Thanks!
Hey there guys, could you help me out with this one?
I've got to do exponentiation with repeated squaring, and I'm [I]lost on where to start[/I], our teacher wants the least amount of multiplications possible to reduce 'strain' when calculating big numbers.
This is what I have so far, just a base really...
[cpp]
import java.util.*;
public class Exponentiation
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.println("Enter the number you wish to raise: ");
double x = input.nextDouble();
System.out.println("Enter the power to raise to: ");
double y = input.nextDouble();
raise(x,y);
}
public static void raise(double x,double y)
{
double sum = x;
if(y < 0)
{
}
if(y == 0)
{
}
if(y % 2 == 0)
{
}
if(y % 2 != 0 && y > 0)
{
}
/*
* x * x = x^2
* x^2 * x^2 = x^4
* x^4 * x^4 = x^8
* x^8 * x^8 = x^16
*/
System.out.println("Answer: " + sum);
}
}
[/cpp]
The first time I did it, I did something similar to a for loop and then multiplying sum by itself, and storing it within sum. However, that is the 'inefficient' way to do it, and I'm looking for some conceptual help and maybe a little bit of example code. I don't want the straight answer, though.
E: Oh yeah, and no pre-made classes like Math.*
Thanks for any help you can give me.
[QUOTE=mr hobo;37809553]I am taking a class in data structures. The teacher that is teaching it, is literally the worst teacher I have ever had. I haven't learned a thing with him. It would be awesome if someone could push me in the right direction on this homework assignment.
There will be two .txt files each containing a matrix. We have to store each matrix as a linked list of rows or columns and multiply the two matrices. What I am having trouble with is reading each matrix.
[cpp]
#example 1
#Matrix A, I matrix, notice zero entries are omitted
#i j value
1 1 2
2 2 2
#Matrix B
1 1 2
2 1 4
#Matrix C, result
1 1 4
2 1 8
[/cpp]
Through help from another website I found this. The problem is I don't know how to make it go to the next line, and on top of that filling in the zeros where they need be.
[code]
void matrix::read_file(char fn[LGMAX+1])
{
int n,m,i,j,k;
ifstream a(fn,ios::in);
a>>m; //rows
a>>n; //cols
while (a)
{
a>>i;
a>>j;
a>>k;
insert_remove(i,j,k);
}
a.close();
}
[/code]
I am really lost in this class, so ANY help would be awesome.
Thanks![/QUOTE]
I believe the ifstream input reads until the newline - This is how it gets text from the console only after pressing enter. You could specify that it should read until the hash or the end-of-file, then split the rows by newlines, or get() each character, then split by spaces and newlines.
[QUOTE=Mike42012;37809962]Hey there guys, could you help me out with this one?
I've got to do exponentiation with repeated squaring, and I'm [I]lost on where to start[/I], our teacher wants the least amount of multiplications possible to reduce 'strain' when calculating big numbers.
This is what I have so far, just a base really...
[cpp]
import java.util.*;
public class Exponentiation
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.println("Enter the number you wish to raise: ");
double x = input.nextDouble();
System.out.println("Enter the power to raise to: ");
double y = input.nextDouble();
raise(x,y);
}
public static void raise(double x,double y)
{
double sum = x;
if(y < 0)
{
}
if(y == 0)
{
}
if(y % 2 == 0)
{
}
if(y % 2 != 0 && y > 0)
{
}
/*
* x * x = x^2
* x^2 * x^2 = x^4
* x^4 * x^4 = x^8
* x^8 * x^8 = x^16
*/
System.out.println("Answer: " + sum);
}
}
[/cpp]
The first time I did it, I did something similar to a for loop and then multiplying sum by itself, and storing it within sum. However, that is the 'inefficient' way to do it, and I'm looking for some conceptual help and maybe a little bit of example code. I don't want the straight answer, though.
E: Oh yeah, and no pre-made classes like Math.*
Thanks for any help you can give me.[/QUOTE]
[cpp]double int_power(double base, unsigned int e)
{
if (e == 0)
return 1.0;
if (e == 1)
return base;
if (e % 2 == 0)
{
/* b^(2e) = (b^2)^e */
return int_power(base * base, e / 2);
}
else
{
/* b^(2e + 1) = b * (b^2)^e */
return base * int_power(base * base, (e - 1) / 2);
}
}[/cpp]
There are some things I'd like to note about exponentiation by squaring:
It's not useful for non-integer exponents, and most of the time it does more harm than good. While it's an obvious and good optimization for stuff like "pow(x, 4)", if you need to write a function that calculates generic exponentiation through squaring, it's likely you won't gain anything out of it. Using a recursive definition like this one is also suboptimal; you're better off looping.
It won't give you the most optimal way of achieving a specific exponent through repeated multiplication. x^27, for example, requires 7 multiplications when using multiplication by squaring, while it could be done in 6 multiplications by repeatedly raising to a power of 3.
I'm learning about Big O, little O, Big Omega and little Omega notation in my class. This shit is so confusing. I think I understand Big O notation, but I don't fully understand the others.
Can anyone explain them do my like they are explaining it to a 5 year old. Or any links to resources would be helpful.
How do I go about using OpenGL in C++? I need the libraries right? Where do I get them, and how would I set up a bare bones OpenGL program?
[QUOTE=Eudoxia;37810081]I believe the ifstream input reads until the newline - This is how it gets text from the console only after pressing enter. You could specify that it should read until the hash or the end-of-file, then split the rows by newlines, or get() each character, then split by spaces and newlines.[/QUOTE]
I made a very simple code to try to get the input of the .txt file.
[code]#include <iostream>
#include <fstream>
using namespace std;
void main()
{
fstream a("a.txt", ifstream::in);
int i, j;
float k;
while(!a.eof()) //This should loop until it hits the End of File
{
a>>i;
a>>j;
a>>k;
cout<<i<<j<<k<<endl;
}
}
[/code]
The problem is that it is printing the last line of the .txt file twice for some reason.
so if A was
[code]
1 2 1
2 2 1
[/code]The output is[code]
1 2 1
2 2 1
2 2 1
[/code]
Is it printing the line again when it hits the end of file or something?
Works fine for me, what is in your a.txt file?
Sorry, you need to Log In to post a reply to this thread.