necrolin 94 Posting Whiz in Training

Here's a partial program to help you out. Read it, try to understand it, and see if you can finish your assignment.

#include <iostream>
#include <cstdlib>
#include <string>

using namespace std;

class Employee
{
public:
    Employee();  //Default with no name and no salary
    Employee(string eName, int eSalary); //create with name...

    void input();
    void output() const;
    void computeNewSalary(int raisepercentage);
private:
    string _name;
    int _salary;
};

//Default constructor
Employee::Employee()
{
    _name = "";
    _salary = 0;
}

//Constructor with name/salary
Employee::Employee(string eName, int eSalary)
{
    _name = eName;
    _salary = eSalary;
}

//Set name and salary
void Employee::input()
{
    cout << "Enter name and salary: ";
    cin >> _name >> _salary;
}

//output, should be "const" as it is not changing any variables
void Employee::output() const
{
    cout << "Name: " << _name << endl << "Salary: " << _salary << endl;
}

//Raise salary within your object
void Employee::computeNewSalary(int raisepercentage)
{
    _salary = _salary * (raisepercentage/100.0);
}

int main()
{
    //Create default object
    Employee me;
    //Set name and salary
    me.input();
    //Print out name and salary
    me.output();
    //Raise salary
    me.computeNewSalary(150);
    me.output();
    return EXIT_SUCCESS;
}
necrolin 94 Posting Whiz in Training
int main(int argc, char** argv)
{
 int i;
 Employee;
 for(i=0; i<3;, ++i);
{
  employee.input();
  employee.set(_name,_salary);
  cout<<"Employee"<<i<<""<<Employee.get_name()<<"Salary;"  <<Employee.get_salary()<<endl;
}

_name and _salary are private in the class and are not accessible in main. You will have to declare them in main one more time. Plus, they haven't been initialized. When you set the name you're passing values to the class. This is just the same as if you were using a plain old function.

string _name = "Bill";
int _salary = 9999;
Employee person;
person.set(_name, _salary);

necrolin 94 Posting Whiz in Training

for(i=0; i<3;, ++i);

Delete the ";" at the end and the comma in the middle

For (i = 0; i < 3; ++i)
{

}

necrolin 94 Posting Whiz in Training

Employee;

Should be something like:

Employee default;

Then use:

default.input();

necrolin 94 Posting Whiz in Training

void Employee:input()

Should be:

void Employee::input()

necrolin 94 Posting Whiz in Training

Where's your constructor?

Employee();

necrolin 94 Posting Whiz in Training
void person::input()
{
    cout<<"Enter name and age"<<endl;
    cin>>name>>age;
}

I did this part differently. What I did for a similar assignment was to have something like:

void setName(string pName);

in the public section of your object. Then I would use:

void Person::setName(string pName)
{
    name = pName;
}

to set the name. You can set both name and salary at the same time if you edit the code. Then, in main you can:

Person me;
me.setName("Necrolin");

necrolin 94 Posting Whiz in Training
class Person
{
  public:
    Person();
    Person(string pName, int pSalary);
    void setName(string pName);
    void setSalary(int pSalary);
    void printAll() const;
  private:
    string name;
    int salary;
};

I had the exact same assignment as you. OMG, brings back memories. Here's a snippet of what I did. It's not everything, but if you look at the code it'll give you an idea of how to proceed.

necrolin 94 Posting Whiz in Training

Deleted.... post has been updated in the meantime.

necrolin 94 Posting Whiz in Training

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

necrolin 94 Posting Whiz in Training

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.

necrolin 94 Posting Whiz in Training

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.

necrolin 94 Posting Whiz in Training

It depends on what you really need to do. If you need something very basic then there is Bluefish, which I can describe as a text editor on steroids.

If you need more full featured there's always Aptana Studio. This one is meant to be a full IDE with support for (X)HTML, PHP, JavaScript, Python, Ruby etc.

necrolin 94 Posting Whiz in Training

Do you specifically need to use the base class instead of the derived class? I was taught that you derive classes to add functionality to a base class. After which you use the derived class instead of the base class whenever you know that you will need the extra methods in the derived class. You can call the methods in the base class from the derived class using: Base::method().

necrolin 94 Posting Whiz in Training

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.

necrolin 94 Posting Whiz in Training

I wrote a few "Leap Year" programs in school. I always used tests like (year % 4).... which checks if the year is divisible by 4, and considering that leap years occur every 4 years then this is a good starting point. The exact definition that I used was from "Computing Concepts with C++ Essentials" which stated that a leap year is:

a) divisible by 4
b) Not divisible by 100 but divisible by 400
c) no exceptions to the 4 year rule before the introduction of the Gregorian calendar in Oct. 1582

As far as compiling a few separate files into one program you can do something like:

g++ prog1.cpp prog2.cpp prog3.cpp -o calendarProgram

You'll have to modify this to match your compiler and file names but the gist is:

compiler programs.cpp .... -o choseAnOutputName

necrolin 94 Posting Whiz in Training

cout << "Paused...." << endl;
cin.get();

This will wait until the user hits "enter".

necrolin 94 Posting Whiz in Training

You intended it the good way, but this is wrong.
string.h is not the same as string.
string.h is a header file which contains string functions for character strings (C-style strings), such as strcat or strcpy or ...(link) .
So to convert it the correct way: change #include <string.h> to #include <[B]c[/B]string> .

Thanks for the correction. You're absolutely correct. I'm new to C++ but I can recall reading about this a while back.... my bad. Innocent mistake. Sorry.

necrolin 94 Posting Whiz in Training

please can you help me to translate this code from c to c++
/***************************************************************
Program describtion :
=====================
This program is for creating a Lexical Analyzer in c

Created by :
=============
CoMPuTeRQ8

kuwait university
Major : COMPuTeR-SCIeNCe

Are you asking us to do your homework for you??!! :-O Bad boy. Hehehehehe.....

Looks like you'll have to:

1) Change the headers:

#include <string.h> to #include <string> for example

2) Update the way you open the file: fstream (ifstream/ofstream...)

3) Change printf to cout

4) Change char arrays to strings

necrolin 94 Posting Whiz in Training

read some string that containes 'a' from excel and store in b

Dim b As String
b = Cells(1, 1)

now i want to use b variable to access whatever i put in the excel. so 'for example if i changed excel data to myvar2 and rerun my program 'then data stored in b variable will be "myvar2"

b = Cells(1, 1) just grabs whatever is in that cell, if you change it and rerun the program it will have the current value of cell(1,1), if the contents is "myvar2" then b will be that value as well

now i want to access myvar2 in my prog throw b's.:icon_sad: i don't know hot to explain any more

I'm not sure what you mean here, but you have the string "myvar2" in the variable b so you can use it as you would any other string. I'm sorry if I'm no help at all. I'm trying my best to answer as I can.

necrolin 94 Posting Whiz in Training

Do you mean something like this (VBA)?

Sub HelloWorld()
   Dim a As String
   Dim b As String
      
   a = "Hello World"
   b = a
   
   ActiveCell.FormulaR1C1 = b
End Sub

You can also use your string variable in a MsgBox. The simplest example being: MsgBox(b)
Of course you can modify this as you like. I'm just giving the simplest example I can think of...

necrolin 94 Posting Whiz in Training

Here's another example. Almost the same as Ancient Dragon's.

#include <iostream>
#include <cstdlib>
#include <sstream>
#include <fstream>

using namespace std;

int main()
{
   ofstream outputFile;
   string filePrefix = "file";
   string fileSuffix;
   string fileName;
   stringstream convert;

   for (int i = 1; i < 5; i++)
   {
	 //Convert integer to string and append to filename
     convert << i;
     fileSuffix = convert.str();
     fileName = filePrefix + fileSuffix;

     //Open file using *.c_str()
     outputFile.open(fileName.c_str());

     outputFile << "Hello There" << endl;
     outputFile.close();

     //Reset convert
     convert.str("");
   }
   return EXIT_SUCCESS;
}
necrolin 94 Posting Whiz in Training

He all ready said he can log on using a Guest Account. He can attempt this using that.

Sorry, missed that part. :$

necrolin 94 Posting Whiz in Training

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;
}

necrolin 94 Posting Whiz in Training

You should have waited for an answer in this thread rather than making another thread. I posted the answer THERE

If this helps then please come back to this thread and continue with your problem. Don't post back in that one.

How can he navigate to the control panel if he can't boot his computer?:-/

I think that the obvious answer would be that your antimalware program deleted or corrupted a file that windows needs to boot/run. Some possible answers:

1) If you're running on a laptop then you may have a "rescue utility" that will restore your Windows to a healthy state with or without deleting your files. I know the HP utility can be run without overwriting your personal files.

2) Between the error message and error number (0x......) you may be able to get enough information to recover what is wrong from your original Windows CD. Google the error number. There's also an article you can read here that offers some tips on troubleshooting blue screens of death.

3) Unless you have some really valuable data on the computer it may save you time and stress to simply reinstall. Even if you spend the time rescuing your PC you'll probably just end up with a virus infected PC at the end of the day anyway. Why not just start fresh?