necrolin 94 Posting Whiz in Training

Mac/Darwin is a modified FreeBSD, not linux. I hope that helps you some -- I would start looking at BSD options.

Actually it's a hybrid of the FreeBSD kernel and the Mach microkernel.

You're better off getting Mac packages for a Mac. However, if you really need to install Linux/Unix packages then you can follow this tutorial:

http://www.simplehelp.net/2007/05/09/how-to-install-linux-applications-in-os-x-a-complete-walkthrough/

necrolin 94 Posting Whiz in Training

If I only have Ubuntu on my computer and nothing else does that mean I even have a partition? Because I've never resized the hard drive or partitioned the hard drive or anything like that on that computer.

Of course you have a partition. You installed Ubuntu into one or more partitions... actually, probably more because Linux usually also creates a swap partition.

I love to mess with different operating systems and I happen to have an extra computer to mess around with. On this computer I've installed, reinstalled all kinds of systems over each other (dozens of times) including installing Windows XP over Linux and vice versa. I have never, ever, had to do anything like formatting the mbr or removing the hard drive. If you're getting an error then you are most likely doing something wrong.

1) Throw the Windows XP CD into the drive.
2) Delete all the partitions that Windows displays.
3) Create a new partition on for Windows, you can use the entire disk if you want.
4) Format with NTFS and let Windows install.

There's nothing more to it.

necrolin 94 Posting Whiz in Training

An integer (int) has no decimals. It will never have any decimals no matter what you do with it. Instead of converting to a double start with a double because you will be able to convert doubles to floats (if you so desire), but not the other way around.

necrolin 94 Posting Whiz in Training

Why does it matter. I hope you are not worried about the program
size at 10 lines.

I'm guessing that he thought that compiling the program would alter his source code instead of creating a separate output file (executable). When it didn't he was wondering why. Sounds like his first C++ program so I don't think we should be too harsh. We all started out asking questions that probably sounded silly to the pros.

necrolin 94 Posting Whiz in Training

i wanna know that if a program consists of 10 lines
n if we compile it , it shows increased no of lines compiled why:icon_question:

Because you're not editing your program you're compiling it. The result of a compilation is an executable program (unless there are errors and you just get an error message). You're source code is left unchanged.

When you write things like "i wanna... n if..." it makes you sound 10 years old. Please write English... or at least your best effort if it's not your first language.

necrolin 94 Posting Whiz in Training

How big is this array?

int marks[student][subject];

Neither student nor subject are not initialized. You initialize them after you create your array.

necrolin 94 Posting Whiz in Training

As inconvenient as it may be.... that's the way to do it.

necrolin 94 Posting Whiz in Training

Take a look into:

#include <iomanip>

This allows you to manipulate your output. For example you can set the width of your output by using:

cout << setw(8) << variable;

Here the "variable" will be given a width of 8 characters. So, you can effectively make columns using setw().

You can also align left/right by using std::left or std::right. Use it the same way that I used setw() in my previous example.

Keep in mind that you have to do setw() for every single output, not just once.

cout << setw(8) "Hello" << setw(8) << "World" << endl;

However, std::right/left need only be done once.

necrolin 94 Posting Whiz in Training

Hi

Can anyone tell me please How i can make program in C++.


Thanks.

I don't think that we can teach you how to program in a forum. However, there is an excellent list of good C++ books/tutorials listed at the beginning of this forum. That would be your best place to start. Read, learn, practice, and we'll help you whenever you get stuck and go "Huh?"... ;)

necrolin 94 Posting Whiz in Training

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.

necrolin 94 Posting Whiz in Training

By the way, I tried it in Code::Blocks (GCC compiler) on Windows XP and it worked as well. Have you got it working yet?

necrolin 94 Posting Whiz in Training

I compiled this on my computer:

int main()
{
    string cFolder;
    cout << "Enter a folder path to browse:" << endl;
    getline(cin, cFolder);
    chdir(cFolder.c_str());
    opendir(cFolder.c_str());
    system("ls");
    
    return 0;
}

It works just fine..... with or without spaces in the directory names.

Note that I'm using "ls" because I'm on OpenSolaris. This is the UNIX equivalent of dir. Everything else should be OK and exactly the same as mine.

Double check your code. If you can't find anything wrong then post your entire program so I can take a look at it.

necrolin 94 Posting Whiz in Training

OH!

I see what I did thar....

Sorry for wasting your time. Haha.

Don't worry. Glad it's working for you.

You may want to read up on the differences between cin and getline() because they handle the newline character differently..... which can give you strange output if you mix the two together in sequence.

necrolin 94 Posting Whiz in Training
string cFolder;
  cout << "Enter a folder path to browse:" << endl;
  getline(cin,cFolder);
  chdir(cFolder.c_str());
  opendir(cFolder.c_str());
  system("DIR");

getline() is like cin except that it accepts the whole line instead of the first word on the line....

necrolin 94 Posting Whiz in Training

Wow... what a bad community...

I'll be sure to spread the word about this.

I actually like this community. You can get a lot of good answers here and the posters seem to really know what they are talking about. As far as not liking the format of the help.... well, let's just say that it takes all kinds to make the world go round. You get an explanation and an example from me. You also got a google link from iamthwee. That should be more than enough to get your program working...... which was the point of your question in the first place. Right?? ;)

necrolin 94 Posting Whiz in Training

Uh... pardon?

You used: cin >> cFolder;

If you type: "my folder name" then the value stored in cFolder will only be "my". The words "folder name" will be in the buffer. If you want to read the entire line then use getline instead:

getline(cin, cFolder);

Which is what "iamthwee" suggested.

necrolin 94 Posting Whiz in Training

conio.h isn't a part of the C/C++ standard. It was included with about 3 compilers and was implemented differently between each. I would recommend:

a) Getting a newer compiler. Turbo C++ was made for DOS/Win 3.1. Something that was made for Win 3.1 just doesn't cut it. If your machine is running XP then Code::Blocks is a great IDE which comes with a the GCC compiler. http://www.codeblocks.org/

b) Stick to standard C/C++ if you're learning the language. Once you learn C++ you can experiment with non-standard code if you want.

necrolin 94 Posting Whiz in Training

It won't work on any computer that doesn't have the .Net framework installed. That's an easy download from microsoft.com.

necrolin 94 Posting Whiz in Training

Linux isn't a great platform for gaming. There are few commercial games for Linux so unless you're talking about Flash based games chances are your games won't work. If you want games go Windows.

necrolin 94 Posting Whiz in Training

That's not how you compile it at all. Not even close. Did you bother to even look at the tutorials I listed above? I'd give you a whole set of instructions but there's no point re-doing work that's already been done by somebody else. Read the tutorials and then come back here if you still have questions.

necrolin 94 Posting Whiz in Training

You're program is fine. Just run a loop to run accelerate 5 times before showing your menu.

necrolin 94 Posting Whiz in Training

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.

necrolin 94 Posting Whiz in Training

You're trying to use 2 arrays num[] and num2[] that you never created. Also, where are the values for num[] supposed to come from?

Array Example:

//Create an array
int salary[10];

//Assign values to the array
//You can do this as part of a loop or whatever you want
salary[0] = 1;
salary[1] = 2;
etc....

If you're creating your array in main then you must pass it to your functions as the array will be local to main and will not exist in your functions.

Example:

int maximumNumber(int a[], int b[])
{
//body of function
}

necrolin 94 Posting Whiz in Training

1. You have a function prototype
2. You have a main function that only prompts for an integer, you never call on the function so it's never executed
3. You have a function that never gets run.

You need to call the function, for example:

num = reverseDigit(98);

Here num gets assigned the return value. Remember that you need to pass a digit to the function as well. I'm passing the digit 98, but you could always pass a variable if you want.

necrolin 94 Posting Whiz in Training

class.function()

So it's:

first.Accelerate();

necrolin 94 Posting Whiz in Training

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.

necrolin 94 Posting Whiz in Training

C++ executables can't be executed on "another" OS. So an executable that you compiled in Linux won't run in Windows and vice versa. This is widely advertised as one of the strong points of Java... compile once run anywhere with a JVM. Also, if I remember correctly then some processor/hardware specific optimizations may prevent an executable from running on a different system.

necrolin 94 Posting Whiz in Training

Aafter I run the file, only the black window appeared, the notepad didn't appeared and btw, very thank you for those who have helped me. But I am afraid may need more help in future to clearly understand these things:)

That's what I said. It's writing to a file not to the screen. So all you'll see is a DOS like screen with no output to it at all. Also, read the comments in the program. They tell you exactly what it's doing. If you need more help then try to make your own program and let us see your code. We can help you more when we see what you are trying to do. Maybe you're just trying to tackle a program that's too difficult for you right now. Remember that programming, like any other skill, is developed over time. Practice some easy programs and work your way up.

necrolin 94 Posting Whiz in Training

I don't mind helping you out but you're not asking for help. You're asking someone to do your homework for you. Try it out on your own. Show us the source code you have and we'll help you fix the mistakes.

Salem commented: Well said +36
necrolin 94 Posting Whiz in Training
#include <iostream>
#include <fstream>

using namespace std;

int main()
{
    ofstream outputFile;

    //Open a file for "Output only"
    //AKA you can only write to this file
    //Create it if it doesn't exist
    outputFile.open("somefile.txt");

    //Write to the file
    outputFile << "Hello World\n";

    //Close the file
    outputFile.close();
    
    return 0;
}

This example only opens a file and writes to it. Reading a file is much the same, except instead of using ofstream you use ifstream.... and the arrows go the other way inputFile >> myVariable;

Now I realize that the program that you're trying to do is more complicated than this, but my simple example gives you a start. If you want more help then show me your source code (well documented preferably so I don't have to guess what you're trying to do).

Also, note that here we're working with files. Therefore, nothing will display to your screen. All the output goes straight to the file.

necrolin 94 Posting Whiz in Training

You can always change:

ifstream myFile("c:\\data.txt");
while (___________)
{
myFile >> num;
total += num;
}

to

ifstream myFile("c:\\data.txt");

while (myFile >> num)
{
     total += num;
}

Which would continue while there is data in your file.

necrolin 94 Posting Whiz in Training

While loops wait until a condition becomes false.

int a = 0;
while (a < 10)
{
   a++;
}

The main idea of the while loop is to keep on executing while some condition is true. You can use it when you don't know exactly how many times you need to run a loop such as if you ask the user if he/she wants to continue or quit.

A for loop is used to run an exact number of times.

for (int i = 0; i < 10; i++)
{

}

Here it runs so long as i is smaller than 10 and adds 1 for ever loop.

necrolin 94 Posting Whiz in Training

There are 2 obvious errors:

a) You have an extra "}" at the bottom that doesn't have an opening brace

b) "using namespace std;" goes after your includes

#include <iostream>
#include <fstream>

using namespace std;
necrolin 94 Posting Whiz in Training

There's a few issues with your file.

void main

If you're using C++ then main has a return of int not void. Also, you forgot the "()" at the end. So it should be:

int main()

The following compiles and works fine on my system:

#include <fstream>

using namespace std;

int main()
{
    ofstream file;

    file.open("file.txt"); //open a file

    file << "Hello file\n" << 75; //write to it

    file.close(); //close it
    
    return 0;
}
necrolin 94 Posting Whiz in Training

You'll have to compile the kernel on your machine. It takes about an hour on my laptop. On top of that you may have to rebuild some things like the nvidia driver, etc. It's a bit of a pain in my opinion. But, if you really want/need to do it then here's a decent tutorial:

http://www.howtoforge.com/kernel_compilation_ubuntu

And another tutorial on Ubuntu.com
https://wiki.ubuntu.com/KernelTeam/GitKernelBuild

necrolin 94 Posting Whiz in Training

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.

necrolin 94 Posting Whiz in Training

Try to play your MP3 files with Totem. It should automatically suggest installing the plugin and install it for you. If this isn't happening then do the following:

a) Under the menu: System -> Administration, find the program labeled "Software Sources" and enable "Software restricted by copyright or legal issues (multiverse)"

b) Under the same menu look up "Synaptic" and run it. Run a search on "Ubuntu-Restricted-Extras" and install it. This will enable you to play MP3's (among other things as many more codecs will be installed) and also give you some extra packages (which are sometimes useful) like Microsoft Fonts. This should be all you need.

By the way, all the codecs that are run under Ubuntu start with the name "gstreamer". If you run a search on them in Synaptic you'll have an idea of what's available. They have names like: gstreamer0.10-ffmpeg (AVI playback and another 90 formats).

necrolin 94 Posting Whiz in Training

can you please help me how to use function and about function calling?please give me some easy tip! thank you very much!

Functions can be called anything you want. Your question usually takes up a 50 page chapter in an average book though... so it makes it difficult to answer in a forum. check out the book "Thinking in C++". It's a free download from the author's website. It'll give you more detail that what most people are probably willing to do here.

http://mindview.net/Books/TICPP/ThinkingInCPP2e.html

If you have a specific question about functions then please do ask. Then lot's of people here will jump to the occasion to help you out.

necrolin 94 Posting Whiz in Training

There is no code, I'm just wondering why it does this sometimes? Is it because my float values are too big? Is it something with the math?

What does it actually mean anyway?

In my number, -4.49255e+013, does the "e+" mean the actual value is to the 13th place?

It's exponential notation.

2000 = 2e+3 = 2 * 10 to the power of 3

If you don't want to see exponential notation then just use fixed like Tom Gunn demonstrated. Of course it is possible that you're seeing exponential notation due to an error, but if your number gets large or small enough it simply defaults to exponential notation.

necrolin 94 Posting Whiz in Training

You say that you have found out how to download a file, but that this isn't what you need. I would argue that downloading the file would be a good start. Once the file is on your computer you can read/write to the file very easily using ifstream and get. Then you can delete the file when you don't need it. Think about your web browser. Whenever it wants to use a file (pdf/jpg/etc) it downloads it into a temporary cache and then opens the file(s) from there.

So download it into a temp file and then you can:

#include <fstream>

using namespace std;

int main()
{
   ifstream mydata;
   //Change the pathname to wherever the file is of course
   mydata.open("/home/user/tempfile"); 
  
   //Now you can use a loop enter your data into an array, vector, string, whatever
   //Example
   char a;
    mydata.get(a); //Grab a single character from the file
    string b;
    mydata >> b; //Grab a string from the file

   ....
}
necrolin 94 Posting Whiz in Training

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.

necrolin 94 Posting Whiz in Training

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.

necrolin 94 Posting Whiz in Training

I missed the C++ part... :icon_redface: Well, if you have SSH set up to run without having to type a password (I gave a link in my previous post) then I would assume that you could use "system()" to execute scp or ssh commands. You can use a string variable inside system() so that you can manipulate the command and add flexibility.

Also, there is a tool called Expect which is designed for:

...automating interactive applications such as telnet, ftp, passwd, fsck, rlogin, tip, etc. Expect really makes this stuff trivial. Expect is also useful for testing these same applications. And by adding Tk, you can also wrap interactive applications in X11 GUIs.

This sounds perfect for what you've described although I've never actually used it so I can't say much more about it.

http://expect.nist.gov/

necrolin 94 Posting Whiz in Training

So I know I can run a terminal command, ok?


What if I want to run say... a vi command or mkdir command INSIDE ssh?

If I want to make it insert a directory in a server via SSH, possible?

Last time I checked I think when you run commands like cd or run commands from the cd like ./mycommand from inside a C++ file and you run cd /usr first, it still runs the command from the folder the C++ file is in, I want to change the directory to what I want THEN run it.

That's just an example, I'm actually trying to make an auto uploader for SSH to make my job a bit faster.

Help?

OH ALSO, when you ssh it asks for password.... is there a way to submit the password? Same goes for running sudo commands...

Password less SSH? Sure. Here's a How-To:
http://rcsg-gsir.imsb-dsgi.nrc-cnrc.gc.ca/documents/internet/node31.html

You can run any command you want inside SSH. You can even run GUI apps from the SSH server if you really want. I'm a little confused as to what exactly you want to do though, but to answer a few of your questions:

a) If you want to run VI or mkdir then just run then just as if they were local. You are logged into the remote machine and the output of all commands like mkdir is on that machine.

b) You want to make an uploader? Why don't you just …

necrolin 94 Posting Whiz in Training

This does not require rebooting. Did you not read what i wrote?Or are you not to keen on that option too even though its not a VM?

Actually Portable Ubuntu uses CoLinux to make it work. And here I quote the CoLinux website...

The memory settings currently suggested for the coLinux virtual machine range from 64 Mb (Windows machines with 160 Mb of RAM or more) to 128 Mo (Windows machines with 256 Mb of RAM or more), or even more.

So, yes it IS a type of virtual machine. ;)

necrolin 94 Posting Whiz in Training

To further explain what I meant above this is a snippet of your code corrected:

if (gender == 'M' || 'm')
{
  if (currentAge < 16)
    rate = MALE_AGE_14_16;
  else if ((currentAge > 17) && (currentAge <= 21))
    rate = MALE_AGE_17_21;
  else if ((currentAge > 22) && (currentAge <= 26))
    rate = MALE_AGE_22_26;
  else if ((currentAge > 27) && (currentAge <= 30))
    rate = MALE_AGE_27_30;
}
necrolin 94 Posting Whiz in Training

You need braces.

if (gender == 'M' || 'm')
{
    if (...)
        do something
    else if(...)
        do something
    else
        do something else
}

The problem is that if (with no braces) only sees the next line that follows it. So if you do this....

if (you == "boy")
if (age < 20)

Then it tests if you're a boy. Then it tests if you're less than 20. But this doesn't test for "you're a boy that's less than 20". If you use braces around everything you want included with your if statement then it does. So, it should be...

if (you == "boy")
{
    if (age < 20)
}
necrolin 94 Posting Whiz in Training

VirtualBox

You can create a virtual machine and install Ubuntu inside Windows or vice versa. This way you can run 2 systems at the same time. What I did was I used OpenSolaris for the entire drive, installed Windows inside VirtualBox and never need to reboot. Note that this will not be running Ubuntu off of your second partition. You will have to actually do a fresh install inside Windows where it will appear as a really big file.

Salem commented: Yay :) +36
necrolin 94 Posting Whiz in Training

Why don't you make both your max and min equal to the first value in the array? Originally you initialized them to zero. Well, how about when all numbers are less than zero?? Doesn't work. If you initialize them to the first value in the array then your program will work because then your starting value is part of the array and not just some made up number which may in fact be larger or smaller than all the numbers in your array. Sorry, I'm really tired so maybe my explanation sounds a little confusing but I think you can understand what I mean.

necrolin 94 Posting Whiz in Training

Is anyone have an idea of how to create a main function?

Why don't you just use a few for loops and an Employee array. Here's a really rough example (it compiles & works, but it's not pretty) =)

int main()
{
    Employee employees[10];
    int percent;
    
    for (int i = 0; i < 10; ++i)
    {
        employees[i] = Employee();
        employees[i].input();
        cout << "How much to raise salary: ";
        cin >> percent;
        employees[i].computeNewSalary(percent);
        employees[i].output();
    }
    
    return EXIT_SUCCESS;
}

Note: Obviously I compiled this with the object that I posted previously.... It works, but it doesn't meet a lot of your requirements. You'll have to go over your assignment carefully and tweak anything I wrote before you use it to make sure you get points. For example, I didn't verify that percent is greater than zero, etc. But at least you have an example that works.