It's your copy constructor.... remove it and it will work.
necrolin 94 Posting Whiz in Training
It's your copy constructor.... remove it and it will work.
Thanks I have tried that before, however I am looking for the stylus, pen support by linux so I can draw, write on the screen in linux programs, I don't think that is widely support or has software for it. See: http://en.wikipedia.org/wiki/Tablet_pc#Linux
I think there is no support by open office so I may still need to use windows office. What else could I do? Can someone build a os that will work or develop one?
The report that I read clearly stated that the stylus was automatically detected and configured by the latest version of Ubuntu. Can't help you much more than that though, sorry. I don't use a stylus, but I have seen them used with Linux. I don't think that Ubuntu includes the program for inputing your writing by default so it's something that you may need to search for it in the repositories. Wish I could be more helpful.
According to the book "Thinking in C++" the second example is the "old" way of doing things while static_cast<> is the "new" way. So, the old way would be the kind of code you'd see in C while the static cast would be the C++ way of doing things. (From pg 169)
It's because the packages would have been updated since the official release. You should update your software listing before installing new software. This way you ensure that what your package manager has listed as available software is in sync with what's on the servers.
Another way to look at it is imagine that locally your computer thinks that it should install Apache-2.0.deb (version 2.0), but the servers have been updated to Apache-2.5.deb (version 2.5). The package manager should indicate that something's wrong in this case because it can't install the version that it thinks it should install.
I don't have this tablet PC, but I did do a Google search for you. Users are reporting that all is working fine with Ubuntu. One thing to keep in mind is that Ubuntu is distributed as a live CD so you can try it out before installing it just to make sure that everything works for you.
As far as "as good or better" is concerned I suppose that it depends on what you do. Windows is better suited for some tasks while Linux is better suited, in my opinion at least, for others. I recommend downloading Ubuntu and giving it a test run. All it will cost you is some bandwidth and a blank CD. If you like it then install it. If you don't then give the CD away and your Windows install machine will still be just the way you left it.
"apt-get update" updates the list of available packages so your system knows what can actually be installed.
Did the solution work for you?
YEah I thought that might be it.
is there any way to make those map_width and map_height variables into constants under the private: thing?Thanks
Sure, you can have constants in a class like so:
static const int width = 100;
Or if you just want some numbers to put into the array you could also do something like this:
enum { width = 100 };
Both work fine.
What I did was this:
a) Create a new array that was larger than the first array.
int newSize = size + 3;
int* newPtr = new int[newSize];
b) Copy the old array into the new array
memcpy(newPtr, ptr, size * sizeof(int));
Basically it's just memcpy(Destination, Original, sizeInBytes)
Since an int is 4 bytes then we need to set it to (# of int * sizeof(int)) to get the right size data to copy.
c) Delete the original ptr and copy the newPtr to ptr
delete []ptr;
ptr = newPtr;
Now ptr is larger by 3 int (because newSize = size + 3). Then I just add 3 random digits to the end. The reason I used size, size + 1, and size + 2 was because I couldn't be sure what size would be originally. You could have chosen to enter 6 digits or 10 digits, right? So, I just did the lazy thing by saying is the first new position in the array, is the next free position, etc. If it were a longer example I would have done this part differently or it would get tedious very quickly.
#include <iostream>
using namespace std;
int main(){
int size;
cout << "How big is your array going to be?";
cin >> size;
int* ptr = new int[size];
// Enter numbers into array.
for(int i = 0; i < size; i++)
{
cout << "Enter Number: ";
cin >> ptr[i];
}
cout << "Numbers entered into array are: " << endl;
for(int i = 0; i < size; i++){
cout << ptr[i] << endl;
}
// Now i want to add more number to this array.
int newSize = size + 3;
int* newPtr = new int[newSize];
memcpy(newPtr, ptr, size * sizeof(int));
delete []ptr;
ptr = newPtr;
ptr[size] = 99;
ptr[size + 1] = 100;
ptr[size + 2] = 199;
cout << "New array looks like:"<<endl;
for(int i = 0; i < newSize; i++){
cout << ptr[i] << endl;
}
delete []ptr;
return 0;
}
Make a new array of larger size and copy the contents from one to another will do the job.
...nevermind...
There I am trying to display the random generators and the contents of the array next to each other... Is it incorrect to do it that way?
Thanks a lot
P.S I am still a beginner in C programming
x is your random number. So if x is 500 for example (I do realize that you've got it generating random numbers up to 6 so take this as as example) then you'll be trying to access A[500], but the array ends at A[4] so you'll get garbage output. What you want is to output from A[0] to A[4] so use the variable i and you'll find your program works just fine.
A[0] = random number 1
A[1] = random number 2, etc
while
A[random number] = ? (Who knows) ;)
printf("%10d%10d",x,A[x]);
Don't you mean A?
This line:
file.write((char*)&age,sizeof(age));
produces 4 blank spaces.
Well, I'm using Windows and it gives me an error when I try to compile your program. Hence, no file is created because the program is never run.
main MUST return an int in C++.
As soon as you change void to int and run the program you will notice that it does in fact create a file. If it matters I compiled it under both VC++ and GCC and both compilers created a file under Windows.
If you want to make it really easy then just replace char aData with string aData and you'll be done. If you need to use a char array then you need to use a function like strcmp(charArray1, charArray2). There's a nice little reference on the function...
http://www.cplusplus.com/reference/clibrary/cstring/strcmp/
Look at the examples on that page. They're very simple and match exactly what you are doing. If you follow the example then you'll be done.
A character is a single character and not a string. 'a' is a character. 'Exit' is 4 characters 'E', 'x', 'i', 't'.
I guess you can do 3 things.
a) Compare 2 character arrays
b) Use a string
c) Use a single letter like, press 'E' to exit.
You can use the editor "edit" if you like. Again, it won't be nearly as convenient as something designed specifically for programming, like Code::Blocks, but that's your choice.
As far as directories go I suppose there is nothing stopping you from using the tc directory. However, I believe that the best place for your files is to place everything in "My Documents". You can always place a directory like "Programs" or something in your documents folder and just compile everything from there.
Not sure if you have a compiler installed on your computer. If not, you'll need one to convert your code into an actual runnable program. The GCC compiler can always be downloaded from http://www.mingw.org/ if need be.
You don't "open" c++ in the command line. You edit your programs in a text editor like WordPad/Notepad or in an IDE (much better choice due to syntax highlighting and automatic indentation).
Try this IDE if you're just starting out: codeblocks
Just remember that you'll need to have not just the IDE, but also a compiler. You can download codeblocks with the compiler included. It's the option labelled: "codeblocks-8.02mingw-setup.exe" (where mingw is the Windows port of the gcc compiler).
You can then compile your programs right within the IDE or you can do so from the command line (so long as gcc is in your PATH) using: g++ myProgram.cpp -o myProgram.exe
Hope this helps.
You have one of a few choices:
1. Convert your function from returning an int to returning a string
2. Convert MyName to an integer.... maybe something like MyID
3. Convert your function to return a void* and then cast it to a string...
Of these choices, option 1 is the best. You cannot return a string when you are specifically telling the program that it must return an int.
My ideas in code:
#include <iostream>
#include <string>
using namespace std;
string MyName()
{
return "Hubba Bubba";
}
int MyID()
{
return 1234;
}
void* MyName2()
{
static string name = "Hubba Bubba Jr.";
void* temp = &name;
return temp;
}
int main()
{
string name1 = MyName();
void* name2 = MyName2();
int ID = MyID();
cout << name1 << endl;
cout << *(string*)name2 << endl;
cout << ID << endl;
return 0;
}
You had several problems with your code. I got it to compile though.
A) void main() ... in C++ it's ALWAYS int main()
B) Check your opening & closing braces {}, that's where your mistake is. You have an unbalanced number of opening and closing braces so I believe that one of your functions is not ending where it should. To avoid this problem always use opening and closing braces like this:
for ()
{
for ()
{
for ()
{
....
}
}
}
C) BREAK; should be break;
D) exit() requires <cstdlib>. I changed your includes a bit to:
#include <iostream>
#include <cstdlib>
That's all you seem to need in this program.
Here's the code that compiles.... Note that you will want to double check it. I put braces where I "thought" you wanted to put them, ... aka verify that everything works right.
#include <iostream>
#include <cstdlib>
using namespace std;
int i, j;
int c[3][3];
void add(int a[3][3], int b[3][3]) {
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++)
c[i][j] = (a[i][j] + b[i][j]); //Addition of two matrices.
}
cout << "THE RESULTANT MATRIX IS:" << "\n";
for (i = 0; i < 3; i++) {
cout << "\n";
for (j = 0; j < 3; j++)
cout << " " << c[i][j];
}
}
void subt(int a[3][3], int b[3][3]) {
for (i = 0; i < 3; ++i) …
I got this to compile just fine by declaring the variables that I mentioned above.
For one, i & j aren't declared, unless they are global variables.... but my C++ teacher would kill you for doing that. Take a look yourself:
for (i=0;i<3;++i)
{
for(j=0;j<3;++j)
Should be: for (int i = 0 .....)
Also, where is c[][] coming from? It just appears in the middle of the function out of nowhere.
You do realize that == compares two values whereas = assigns a value. Therefore, it's...
t = a;
a = b;
b = t;
You'll need 2 for loops (nested). 1 will be for the width and one for the height.
for (int column = 1; column < n; column++) {
for (int row = 1; row < n; row++){}
}
Inside the second for loop (rows) you'll have to implement the formulas they gave you in the book/assignment. Use something like if statements to calculate whether it should print a ^ or a #.
The only error in this file is horrible formatting. The program compiles and runs just fine.
I have a problem with this post. When I started reading the post I saw something to the effect of IE opening itself up hundreds of times. This does sound like a virus. However, the poster mentions multiple formats. This is a problem.
A format deletes everything on the machine including viruses. If you had the machine formatted then when you booted it up it was clean. This means that either:
a) You're installing the virus after it's been formatted. It's possible. I had a client of mine who had a Windows "driver" which he downloaded from somewhere on the net for his hardware. It was a trojan that installed loads of poop onto his computer. So, to me if this is a virus then you need to take a really hard look at the software that you're using. Where are you getting the virus from? If it's survived multiple formats then YOU are putting it back on your computer. Even if you fix it there's a good chance it will come right back.
b) I haven't gone through the logs, but a few people have mentioned that your logs look clean. Reformatting would have cleaned up the viruses..... so what's left? Does your keyboard have a little button for launching a web browser? Someone else suggested that it could be a keyboard problem. If it's the keyboard then no amount of formatting will help you and/or virus hunting will kill you.
Just a few thoughts.
Do you mean you want to execute commands such as dir from within your C/C++ program? Sure.
system("dir");
Just change dir to the name/location of any program you want. The output will go to the screen though, not back to your program.
Well, doing a little extra work on an assignment is almost always a good thing. On the other hand the assignment specifies:
Demonstrate the class in a program that creates a Car object and then calls the accelerate function five times.
You're solution doesn't do this so you could possibly lose marks. Make sure you read the requirements carefully, ensure that they are all met, and then add something extra like the menu driven options.
class.function()
So it's:
first.Accelerate();
If you only pass one parameter to the function then what's the program supposed to do with the other 8?? Besides, regardless of the name of the variable that you're sending the data will go to the first parameter in the function. So basically you're sending row1col2 to row1col1... which is not what you want to do. Why can't you pass all 8 parameters at the same time? You can have the function enterdata1() just return the value to main and have main call the displaydata() function with all 8 parameters.
what if the file i am writing and reading to does not exist? this is what i am try solve or asking for help.
ifstream is for reading from a file (input)
ofstream is for writing to a file (output)
fstream is for reading & writing from a file, however it will not create a file that doesn't exist, whereas ofstream will.
Therefore, what I try to do is to open a file first. If it fails then I create the file and then try to open it again.
fstream file;
//Try to open file for both read/write
file.open("data.txt");
//If the file doesn't exist it will fail
if (file.fail())
{
cout << "Creating data file...\n";
ofstream out;
out.open("data.txt"); //create the file
out.close(); //we want read/write so close it
file.open("data.txt"); //open with read/write
}
So to answer your question of how to open a file that doesn't exist.... just create it with ofsteam.
a) Ubuntu Server does not come with a GUI by default. You can enable one via the command:
sudo apt-get install ubuntu-desktop
sudo: run an application with root privileges (or other user's privileges is possible as well)
apt-get install: install an application (requires internet connection)
ubuntu-desktop: Gnome and all default desktop apps
(If you wanted a GUI you could have installed the Desktop edition of Ubuntu instead... but no worries)
b) Ubuntu doesn't allow you to login as root by default for security reasons. Use: "sudo command" instead. You really don't need to log in as root, sudo is safer and it leaves a log of what you did so it's easier to undo actions later on if you need to.
c) If you decide to go with a different version of Linux there is no need to format from Windows. The installer will format during the installation. If you format from Windows and then reboot you won't be able to boot into Windows until you install Linux again or remove grub (the boot loader) so do be careful. The reason for this is because grub uses data that's located on your Linux partition in order for it to work. If you decide to delete Linux make sure you delete grub before rebooting. There's some tool you can download for this but for the life of me I can't remember what it's called. Sorry.
You can only have a maximum of 4 primary partitions. If the partitioning program is crashing then I'm assuming that you've reached this limit. Try moving all of your data off of one of these partitions and then using that partition for Linux.
Pop the RedHat disk back into the drive and there should be a "rescue" mode somewhere in the setup. This will bring you to a command prompt (looks like DOS). You'll want to do the following:
Type "grub" to enter a utility where you can repair/install grub then...
a) type "find /boot/grub/stage1" (no quotes), this will output where your root is. You'll need this info for step b.
b) "root (hd0,1)" (obviously update with the results of step a.
c) setup (hd0)
d) quit
e) reboot
If you want to read in more detail you can check out:
How to Restore Grub
Repairing Grub
Hi all
I want to write program in linux about
first come first served algoriyhm by using C++
but I don't know how to start???????????????
I know how to write the code in XP system.
what is the difference between programming in linux and xp?
Can anyone help?
If you know C++ on Windows then you know C++ on Linux. There are system specific options of course, but that would be better covered in a book on Linux programming than a forum post.
The main difference from a programmers point of view would be the tools that you have available to you. Under Linux you have many of the same IDEs as Windows has: Eclipse, Sun Studio, NetBeans... I would suggest going into the "Add/Remove Programs" tool in your Linux distro and check out what they offer. You're no more than a few clicks away from a ton of different IDEs, compilers, and other programming tools.
If you want to queue your processes as they arrive you can use the fork() to create threads for each process.
Correct me if I'm wrong but I was under the impression that fork() creates a child process, not a thread. It basically creates a duplicate or clone of the parent process. You can then change the child process into any other process via an exec() command. If you want to create a multi-threaded program under Linux you would use posix threads. The difference between a thread and a process being, among other things, that threads share data (such as open files) and are much lighter on system resources in their use/creation.
My advice would be to get an introductory level book. Then download code::blocks (an application that helps you write programs) and start working on code. Do the exercises in the book you get and try to come up with your own interesting programs. In programming you definitely learn by doing.
cout << "Paused...." << endl;
cin.get();
This will wait until the user hits "enter".
To make your assignment work you need to be able to pass data between your functions and the main program. To do so requires one of two things:
a) A return statement... meaning the functions can't be void. That's not part of the assignment so let's forget about this.
b) To use the "&" symbol with your functions. If you use the & then any variables that you change in the function will also be changed in the main program. So something like this:
void calcBonus(double &variable1, double variable2)
{
/* Swap in the correct calculation of course */
variable1 += variable2;
}