jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

how i made the 2 others, update() and delete()?

Well delete is easy but you can't use foreach since you are modifying the list during the process.
So for both processes (update and delete) make a search function as you suggested which returns the index of a matching criterion for example (employeeList.lastName == "Smith"), return i if this is true. Do this search using a regular for loop with i<employeeList.Count as your loop condition.
Then use employeeList.RemoveAt(i) to get rid of that one. I'll leave the Update() method to you, but suffice to say use that search function and return the index, then make the changes accordingly.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

and why when i set more than one employe i get list of only one in the print() method when i chose '4' in the menu? i mean, i need to show all of the employes i have stored...

Take out the Console.clear() call that you have in your Print() statement, you are clearing the screen in between each output. I'll leave it up to your creativity to get it so that it only prints the banner once and the rest with just the names.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

you mean put the set() methods in the employe class? but how can do that? by not using constructors?

Well, what you should do is have your secretary inherit from employee and either have the methods of secretary be the ones to get the monthly hours, etc. or call the constructor for secretary which would include the hours per month and then send all the other parameters to the employee constructor (the base).

public Secretary(string name, string lastName, string bDate, float baseSal,float hoursPerMonth)
            : base(name, lastName, bDate,baseSal)
        {
            this.hoursPerMonth = hoursPerMonth;

        }

But in terms of what you are doing, you can add the methods to get the data from the keyboard (set_employe and set_secretary, etc) as methods of the employee class. You would be writing to private members of the class just as if you called the constructor. But in fact nothing is stopping you from having both a setter function and a constructor that takes in the parameters. These are design decisions that may or may not be according to best practices but for your project you should pick one and stick to it.
One thing, though, if one of your menu functions is to edit your data you'll need some way to get access to those private variables.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Move your list declaration and instantiation outside of your do loop.

List<employe> employeeList = new List<employe>();

    do
    {
      Console.WriteLine("chois: add = 1\tupdate = 2\tdelete = 3\tprint employe list = 4\tquit = 5");
       chois1 = int.Parse(Console.ReadLine());
       switch (chois1)
       {
             case 1:
            {
               Console.WriteLine("Chois: secretary = 1\tsellsMan = 2\tManager = 3\tTopManager = 4");
                char chois = char.Parse(Console.ReadLine());
                switch (chois)
                 {
                     case '1':
                              {
                               set_employe(out name, out lastName, out bDate);
                               set_secretary_sall(out sellPerHour, out hoursPerMonth);
                                        //then still do your adding here
                               employeeList.Add(new employe(name, lastName, bDate));
                               employeeList[employeeList.Count-1].setsecretary(sellPerHour, hoursPerMonth);
                                        //get rid of all these things
                                         //count++;

                                        //e = new employe(name, lastName, bDate);
                                        // e.setsecretary(sellPerHour, hoursPerMonth);
                                        break;
                                    }

Change case 4 (of the main menu, to print)

case 4:
{
      foreach (employe emp in employeeList)
      {
          emp.Print();

       }

       break;
 }

And down in the print method, get rid of the for loop

public void Print()
      {
              Console.Clear();
              Console.WriteLine("name\tlast\tbirthdate\tsallary");
              Console.WriteLine("----\t----\t---------\t-------");
              Console.WriteLine("\n\n{0}\t{1}\t{2}\t{3}", name, lastNmae, bDate, sallary);
         
      }

I still remind you though, that your method for setting the employee data that you call probably should be a method of the employee class. Check your assignment and make sure there is not supposed to be inheritance between the employee class and the subtypes.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Post your code in its entirety. Also, please describe what problems you are having with it. What ddanbe was saying was that your declaration (and initialization) of employeeList should be at the level of Main() so that you are not creating it new every time your user selects option 1.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

That's mybad for not taking enough notice of it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Do you initialize count before you try to access that element at EmployeeList[count]? Also, since you seemingly haven't added the first element until after you try to access it, there will be nothing in the container. What you should really do is move the Add() before you try to access the employeeList[] member.
As it is, rather than trying to create your own count variable, you can get employeeList.Count which is a field that will tell you how many objects are in the container (so you'd need to have access the last member as employeeList[employeeList.Count - 1]).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

ok. i made some skitts, and i must say that i still stuked.
the code, now mine :)

This is debatable, but you have put in some effort on your own.

so the qestions is;
1 - how can i return the base menu after i set new employe? i tried the do while loop, but probably i wrote it not correct.

I would put a 5th number in your menu for quit and then have the condition in your do/while be (chois1 !=5). If you're stuck with 4 choices, quit after the printout using a similar (chois1 !=4).

2 - how can i count the employes for later use such as delete, update, print? i used array but i dont know how actualy get to every one of employes for check his data and manipulate this data.

You can make a static variable in your class (which is sort of what you were trying to do but it wasn't declared properly). This is probably not the best way to do it. I would use the List container to hold each new object:
List <employe> employeeList = new List<employe>();
employeeList.Add(new employe( constructor arguments));
then use employeeList[0].setSecretary(method arguments); (and for 1,2,3,4....) or you could make a new employee, set it all up and then add it to the list.
That way you have a count of your employees

3 - why i have some error issues while i run the program? error list is empty...

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I think you understand my questioning your motives when you say (essentially) "this isn't mine but help me change things here and there just enough and turn this into a form which I can turn it in for a grade." Unfair to yourself and your classmates.

Now, we can start this over. You should post further details about your assignment along with an attempt at the employee class. Make a new Console application if you haven't already.

As a hint, you should probably separate your class into its own file. To do this, go to the Solution Explorer on the right side of the IDE (if you can't see it go to View/Solution Explorer). Right click on your project name (in bold). Select Add then select Class... name it and a file will show up in your project.

Also make a separate file for your derived class, the same way you did above except name it for your derived class.

Now layout the class in a skeleton with the methods unfinished and post back with any questions.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

this code is not mine, and i need to write somethink like this but not exactly this way.

That doesn't sound the least bit like you want us to help you cheat.

There's one good way to do what you want to accomplish, try it yourself and come back with questions about your code.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'm surprised it didn't give you grief for pow, as there is no definition that takes 2 ints (http://www.cplusplus.com/reference/clibrary/cmath/pow/)

Look into fmod (http://www.cplusplus.com/reference/clibrary/cmath/fmod/) which is like % but for floats/doubles/etc.

Also, you should include <cmath> instead of math.h and main() should return an int.

I ran the program but I did not check your logic completely. I think you are off by one exponent. Rather than go through all this exponentiation you should look into the >> and << (shift operators for bits, not the operator for iostream).

EDIT: Do a quick search around the site. There are a ton of examples. Most of them take in the binary as a string (which I was going to suggest) and then do the bitshifting.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Line 29 should be chcount[lcv]++; instead of chcount[lcv] = chcount[lcv]++; which can cause weird results.

Ive gotten it so it works after hitting enter then EOF but it counts the enter as a character.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Part of the problem is you want lcv == CHARCOUNT on line 36 -- you've traversed the entire array to the end and the character isn't there. Ignore what I said in my other edit about EOF, but make sure your user knows to hit EOF (ctrl-Z or F6) at the end of the input.

(sorry about all the edits, I had a train of thought but got derailed -- I thought I knew exactly what was wrong with it right off the bat but it needed a closer study)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

For C++ QT is a decent library and it is somewhat portable (it's distributed by Nokia now). There's a free pdf of a decent book(released by the author under Open Publication) at http://www.qtrac.eu/marksummerfield.html (the author's website).
He steps you through (and they are nice manageable steps) making a very small scale spreadsheet program.

There are lots of other options, like wxWidgets (I've never used but a lot of people like). Of course there's the whole gamut of Windows GUI tools -- Win32API (not the best place to start if you haven't done it before), MFC (which is C++ based), .NET (but you need managed C++ and this is a whole different animal).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Hehe. No worries. You're doing pretty darn good for your second day!

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

//first line of the file OL001 bob red 13
myfile>>s1.name; //OL001 so far so good but this is the ID
myfile>>s1.color; //bob still "ok" at least matches in type
myfile>>s1.age; //red not good, what is the number red?
myfile>>s1.id; // 13 okay matches but red already corrupted this

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Ok. I would take string id out of the global scope and just declare it locally in the body of the function. Also, it should be an int since that's what s1.id is. If you really need it elsewhere in the program, declare it in main and pass it in by reference to the function.

You have a mismatch between inData and myfile. There should only be one name for the infile stream used in this case.

Finally, you can substitute cin.get(); for system("pause");for a more portable solution (see this). EDIT: also, substituting using std::cout; using std::endl; etc for using namespace std; keeps your namespace less polluted.

EDIT II: You need to rearrange your input sequence to match your file and take care of the OLs (do you want them or not?).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You can try it with the -> but let me see what the whole thing looks like.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What's the error that you are getting? Are there really only 5 records in the file?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

No no, while is actually preferred. You can use your cin >> s1.name as the condition for the while loop.

Great on the string changes, but now the whole string will be stored in that variable, so you don't need 64 of them in one struct.

Also remember to make an array of structs as each line in the data file will have its own. As it stands you'd overwrite your variables each time.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I would skip over the buffer completely.
Make name and color strings (e.g. string name; )
Create a loop and read:
myfile >> s1.name; //but see below, should be s1.name
myfile >> s1.color;
(get the int)
(get the other int)
then repeat this over and over again for all the lines of your file. So you should make an array of people actually.

Oh yeah, and qualify main() with int (e.g., int main() ).

shishio1014 commented: hes a good programmer +1
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What does that particular segment of your code look like (if you're able to post it)? MathBot sounds interesting -- combing netspace to solve random equations it encounters. ;)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Couple of things right off the bat... #include <iostream> the one with the .h is potentially a prestandard version. main() should return an int (and pop a return 0; at the end of main.

If you can I would include <string> and use that instead of the char array. If you can't we can work around it. That way with the string you can read right into it (you can use getline but with the mixed strings and ints in your data you're probably better of using myfile >> . See this and the related pages about fstream.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Is it possible to use a for loop and compare the user input to the structure like if (userinput = s1.id)?

Yes with == ( if you have a pointer to the struct it would be userinput ==mystruct->id)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Just to clarify, are you reading your data into the program or is the user typing it in? However, in reality your struct should be the same either way you do it. OL# can be a string member of your struct, or you could make it an int member and strip the OL out of the string you read in and turn the remainder into an integer.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Topi is on the right track I think. A portion of it has to do with your preprocessor directives. I've never seen one with a period in it and this is why I suppose. Most people use an underscore in place of the period (the convention is to name it after your header like you had done, but really it could be anything). So change those to NODE_H, DOUBLYLINKEDLIST_H etc.

NULL is something that is defined in a couple of the headers so it has to be in all caps. You need to include <iostream> for the NULL and the couts. Also you need to qualify cout one of 3 ways: either put std:: in front of it, std::cout, or put using std::cout; at the top of your file, or the last option put using namespace std; at the top of your file (which is the least favorable since you have to worry about all the names in that namespace conflicting with the code you've written.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Under the Edit menu, Advanced, (uncheck) View White Space
CTRL-R,CTRL-W (first one, then the other or both at the same time)

(I remembered these from a similar setting in Word -- not the same keystrokes I don't think)

Excizted commented: Thanks for helping :) +1
Ancient Dragon commented: Very helpful -- I couldn't figure it out either. +25
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Firstly, use fgets to obtain your name string from the user. See this for a reference (it's a C++ site but it should be nearly the same).

Next look into ctype.h and there's a function tolower() that will help you if you don't know whether the text is in caps or not (you could test whether or not it was for each character but we can just transform the whole thing to lowercase). If you can't use that library, you can write your own very quickly, just add the correct amount to the char value (see ASCII table)

You can access the character n (0 to size-1) of the string in the ith (0 to size-1) structure as follows:
s1.name[n] so use tolower() on each char
as you compare that to yourstring[n]
where char * yourstring= "yourstringtomatch";
(put any bells, whistles,code to skip spaces etc in there too)
march your loop until you hit the null terminator in the string '\0' count the number of times they match, compare that to the length of the string and you're in business.

Post back if there are any issues.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Thanks for bringing it back! Happy Holidays Dani. :)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I agree with firstPerson. However, I'm confused as to why this function marches along initializing some of the array members and then stops. You are asking it to "get" an element but returning a whole array. Unless you are doing some error checking that isn't evident in your code why wouldn't you use arr[row][col]? I'm just puzzled is all....

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

1.) Select the Form1.h [Design] tab in your project
2.) Click once on Form1 itself
3.) Go to the Properties Window (by default on the right side, but if you can't see it go to View/Other Windows/Properties Window
4.) In the properties window go to the little lightning bolt on the toolstrip (under Form1 System.Windows.Forms.Form
5.) Under behavior, double click the empty cell next to Form closing.

Now you'll have the proper event handler added and you can flesh out the method definition as you see fit.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Well more than likely your program is going to be doing some event driven stuff (reacting from a button getting clicked, text changed in a textbox).
Just to test out the concept put a button from the Toolbox onto your form (or whatever your gui need is),go over to Solution Explorer and there should be a tab saying Properties on the bottom of that window (else go to View/Properties Window). With the Form1.cs [Design] tab active and the button highlighted click on the lightning bolt in the toolbar. Go to the blank cell to the right of where it says click and double click it. You'll get an event handler button1_click (object sender, EventArgs e) placed into your code for you. Put whatever code you want associated with the click of the button in there(and you can call other methods you've written in class Form1 or in other classes and even trigger other events). So for example with the main window you can use a load event to execute code on startup. You could call other methods at the end of InitializeComponent() but I think it's much more practical to use the events to take advantage of the paradigm.
Just my half nickel but I figured it might help you to get your hands dirty since this ain't your first rodeo.

ddanbe commented: Nice explanation +6
roswell67 commented: directly tackled the problem and explained everything. Loved the post. +0
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Take a look at this thread:http://www.daniweb.com/forums/post246417.html#post246417
Substitute ':' for ',' in the delimiter of the second getline call and you should have what you need (minus fixing it to work with your arrays,etc). You can use an N x 3 array for holding the strings or just do your parsing for ints on the fly. See this for more info on the stringstream >> operator.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Wasn't trying to steal your thunder lol.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Try something like this. The true passed to ReadKey() suppresses the output of the character to the screen.

ConsoleKeyInfo a;
            do
            {
                 a= Console.ReadKey(true);
                switch(a.Key)
                {
                    case ConsoleKey.O : Console.WriteLine("You ordered an orange");
                        break;
                    case ConsoleKey.A: Console.WriteLine("You ordered an apple");
                        break;
                       //etc.
                }
            } while(a.Key != ConsoleKey.E);

Since ConsoleKey is an enum it is acceptable input to the switch.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Line 34: It's case sensitive so it needs to be Tests_Weight (or change all the others to match Tests_weight ;) )

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Just into 3 groups, cutting off the count at 7? Just make 3 arrays that are 1/3 the size of the big array (if it doesn't divide evenly you'd have to make a 4th array) and copy the ints over element by element.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
i = 0;
while (fin >> x[i] ) 
{
       i++;
       if( i ==n)   //less than elegant but it's off by 1 if you && it in
            break; //to the loop condition
       
}

What you had was going out of bounds over and over --->fin >> x[n]; (n=20 is the last element of the array)

If you don't know how many data you will be reading in you are better off using a STL vector. They expand in capacity as the need arises.

Otherwise you could either get the total number of points from the user and use int * myarr = new int[numberuserentered]; Failing that you can set an upper limit MAX_SIZE and declare int arr[MAX_SIZE];

I don't quite understand what you are asking on the 2nd question.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Try going to a prompt and compiling it as g++ exercise9.4.cpp exercise9.4main.cpp -o ex94 substitute your own filenames and exe file name. Somehow I think your project in C::B is not set up correctly (I don't use it so I don't know how to remedy it). You may be trying to compile your main.cpp first and it doesn't have the other code to link in.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I just want to ask for comparison's sake, but what compiler are you using?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I am able to get it to compile, minus a total variable that appears out of nowhere and some cin's that had the << operator instead of the >> (I guess I caught your code before you changed it). It was balking about the signature of the setSales function not matching but that resolved. What is the error you are getting now? It could have to do with your namespaces and needing a using statement in main but I didn't test that.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I see. It works now, thanks.

So, whenever I ask a user a question that requires a single variable (like 'Y', or '123'...) I have to use a cin.ignore before using a getline to ignore that \n?

There are other situations in which junk can get stuck in the buffer. At the top of the C++ forum there's a sticky article on flushing the streams, that'll give you some idea of the different situations. 123 isn't a single character, it's a string. I just meant that when cin is expecting one char (as that's all that will fit) and you hit enter after, that's really 2 characters, so the second one sticks around.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Put a cin.ignore(); before each of your getline statements (and get rid of the extra cin for songName). That will get rid of the extra \n character from when you press enter for your cin>>answer; prompt (since answer is only expecting 1 character, the \n is left in the buffer and fouls up your getline). I'm sure you put them in there for testing other options but you don't need to redeclare albumName, etc in this function. In testing this, I again put an extra PrintLibrary() call after I called UpdateRecord(); instead of passing in the ofstream directly.

MrJNV commented: Damn helpful. +1
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Check out the partial keyword:http://msdn.microsoft.com/en-us/library/wa80x488.aspx I think it's exactly what you need.

ddanbe commented: Good thinking! +6
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I made some changes, commented below:

void DelRecord(MyLibrary Library[])  //instead of passing in an output file, just use the 
                                                       //PrintLibrary up above
{
	int i;	
	//MyLibrary songInfo[MAX_SIZE];  don't need to redeclare this here	
	
	cout << "Choose number the corresponds to record you would like to delete." << endl;
	cin >> i;
	i--; //convert users entry into zero-based index
	while(i <MAX_SIZE-1) //since you are moving i+1 to i
	{
		
		Library[i] = Library[i + 1];
		i++;
	}
	
}
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Anytime you are passing in (type a[]) to a method the call is converted into (type *a) where the array is passed in by pointer. I don't believe there is much of a workaround. If you need your original array intact, copy it memberwise into another array and keep that in main().

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Also, I forgot to say in my first post that the ampersand should be included in your function definition as well.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Why do you have an extra set of parentheses on the end of your function prototype? Get rid of those and put a semicolon at the end.

Also, you probably want to pass in ifstream by reference:
void a(ifstream & b) in your prototype, nothing extra required in the function call itself.

Thumb2 commented: Straight to the solution +0
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I had to look this up so I'm not much good on further questions :) String ^ kpath = gcnew String(argv[1]); It makes sense to me but I don't have much experience with the CLI syntax.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

In main, I called PrintLibrary twice once before and once after the addition of the albums, I used a second outfile rather than trying to append with the proper numbering.

int main()
{
	ifstream inFile;
	ofstream outFile;

	inFile.open("MySongLibrary.txt");
	outFile.open("OrganizedLibrary.txt");
	ofstream out2("OrganizedLibraryadded.txt");
	MyLibrary songInfo[MAX_SIZE];

	GetLibrary(inFile, songInfo);
	PrintLibrary(outFile, songInfo);
	//PrintToScreen(outFile, songInfo);
	AddRecord(outFile, songInfo);
	//PrintToScreen(outFile,songInfo);
	PrintLibrary(out2,songInfo);

	inFile.close(); 
	outFile.close(); 

	return 0;


}

Here is a modified version of the method

void AddRecord(ofstream& outFile, MyLibrary Library[])
{
	for(int i =4 /*(MODIFY FOR NUM OF RECORDS PULLED IN)*/; i <MAX_SIZE ; i++)
	{ //if there were 50 records already, it would be #0 to #49 so start with 50

		string genre;
		cout << "Enter Album Name" << endl;
		getline(cin, Library[i].albumName);
		cout << "Enter Song Name" << endl;
		getline(cin, Library[i].songName);
		cout <<"Enter Artist Name"<<endl; //you had forgotten this 
                                                                         //one in this method
		getline(cin, Library[i].artistName);
		cout << "Enter Play Time" << endl;
		getline(cin, Library[i].playTime);
		cout << "Enter Genre" << endl;
		getline(cin, genre);
		
			if(genre == "Rock")
				Library[i].genre = ROCK;
			else if(genre == "Alternative")
				Library[i].genre = ALTERNATIVE;
			else if(genre == "Classical")
				Library[i].genre = CLASSICAL;
			else if(genre == "Soundtrack")
				Library[i].genre = SOUNDTRACK;
			else if(genre == "Children")
				Library[i].genre = CHILDREN;
			else if(genre == "Other")
				Library[i].genre = OTHER;
			else
				Library[i].genre = OTHER; //or reject bad user input
	
		
		cout << "Enter Album Producer" << endl;
		getline(cin,Library[i].albumProducer);
	}
	

}

I'd stick with the getlines to be consistent. I was having some trouble with the cin >> which could have been alleviated with cin.ignore() but I didn't bother.