Murtan 317 Practically a Master Poster

No.

h ends up zero and m ends up being whatever h was * 60

Now that I think about it, why does display1Time even need h and m, aren't the hours and minutes in Mytime?

The tens and ones hint was to do something like this:

int tenmin = t.mins / 10;
int onemin = t.mins % 10;

When the time is less than ten minutes after the hour tenmin will contain zero, but when you print both numbers together you get the type of display you want. If the time is ten or more minutes after the hour, you wouldn't HAVE to split the number like that, but it will still work if you print both numbers together.

Murtan 317 Practically a Master Poster

courses is a member of student.

To what student is cin referring when you want to update courses[0]?

(and courses is PRIVATE data, driver will not be able to update it)

Murtan 317 Practically a Master Poster

(*rats I wasn't first reply :( *) int i,j surname[N],name[N],ID[N],grade[M][N]; Declares all of those variables as integer. Should some of them have character data?

The format in scanf("%s",name,surname,id) will only read one string value. surname and id will be empty. (But as noted above, name, surname and id are all integers anyway.)

This for statement:

for (j=0; j<=M; j++)
printf("give grade for the %d lesson,j+1);

does not have any braces on it and so will loop only the first statement.

You don't have enough matching braces yet, could you try to compile it and post code that compiles?

and when posting c code, please use c code tags
[code=c] /* Your code here */

[/code]

Murtan 317 Practically a Master Poster

I agree that Vortex * Vortex is the maximum number you could have, but you know how many you had, why not use that number instead of looping beyond what really makes any sense.

Is there another criteria (besides not zero) that you want to use to select which ones print?

The lowest value? All nodes having the lowest value?

The highest value? All nodes having the highest value?

The lowest 3 values and the nodes that have any of those values?

You mentioned sorting the array from the highest to the lowest value. Are we looping through the sorted array?

If we are in the sorted array and want low values or high values, why not start on the right end of the array and stop looping when we've gone far enough?

Are you wanting something more like where we print all the '1's first, then the '2's, then the '3's?

If so, you could use brute force (**this is NOT a good idea, but it would work**) with something like:

for (match = '1'; match < '9'; match++) {
    for (y = 0; y < Vortex * Vortex; y++) {
        if (Input[2][y] == match) {
            printf("Node %c found at %d\n", match, y);
        }
    }
}

But sorting the array into the order you want to print it makes a lot more sense.

If you (for some reason) need to be able to print which node it was in …

Murtan 317 Practically a Master Poster

You are obviously searching the input array, but you are iterating Vortex * Vortex times. Isn't that more than the array can hold? (or is there another counter for the number of input pairs?)

Your code seems to be specifically skipping '0' nodes, right?

int FindRoute()
{
	for  (y = 0; y <= (Vortex*Vortex); y++)
	{
		if (Input[2][y] >= '1')
		{
			printf("Node %c found at %d\n", Input[2][y], y);
		}
	}

 printf("End");
}
Murtan 317 Practically a Master Poster

Thanks for the better explanation.

Is it possible that you might have an input line like:

F M 24

If so, your current data structure is insufficient to hold your data as the '24' will not fit inside a single character. If this were the first line in your input file, based on your previously posted input routine, you would have:

input[0][0] = 'F'
input[1][0] = 'M'
input[2][0] = '4'

I presume this is NOT the desired effect.

The array represents data to be loaded into a matrix.

Do you actually build and fill the matrix?

(Quick off-topic question, as I'm curious:
Is the matrix reflective?
Does A B 2 imply B A 2?
)

When you sort by the third column, are you sorting the array or the matrix?

When you are searching, are you searching the array or the matrix?

(If you're searching the array -- and I think you are -- there are only Vortex entries.)

As for your print loop, you could rewrite it as:

for (y = 0; y < Vortex; y++)
{
    printf("Node %c found at %d\n", Input[2][y], y);
}

But that's still not what you really want to do is it?

Murtan 317 Practically a Master Poster

First comment...the single character input[0][x] can never be the invalid character constant '10' .

You still haven't stated in english what you're trying to accomplish. Whatever the "Y" is in "Do Y" may play a significant part in coming to an optimal solution.

So, poking in the dark again because you won't turn on the light, do any of the following benefit you in some way?

if (isdigit(input[0][x])){
    // do Y here?
}
if (input[0][x] >= '8' && input[0][x] <= '9'){
    // do Y here?
}
char interestingchars[] = "89.+-";
// some time later
if (strchr(interestingchars, input[0][x]) != NULL) {
    // do Y here?
}
Murtan 317 Practically a Master Poster

thanks your help i will ask the instructor for further clarification while i do know about arrays and loops this is the second lab for the course and hasnt covered that material so i am not sure how advanced he wants this lab to be

Fair enough, I know sometimes they want you to do things "the hard way" so you can appreciate how much easier it is with the other tools.

Murtan 317 Practically a Master Poster

Why did you declare 'CourseInfo classes' inside this case?

If this case is inside a method of Student it can see classes directly.
If this case is not in a method of Student you need to decide how you are going to get the data there.

Presuming that CourseInfo has the mutators you're calling, and if you removed all of the [0] references on classes (because the one you declared in the case is not an array) the input should work to fill the local 'classes'. But then you need to have that update one of the elements in the Student's classes array.

Murtan 317 Practically a Master Poster

You REALLY need to move this to an array...

From the text printed next to answer3 and answer4, what you really need is something more like this:

if (num1 > 0) {
    answer3 += num1;
} else {
    answer4 += num1;
}

and repeat it for the other 9 numbers

but if you can get to an array, you could do something more like the following which does it for all ten numbers:

for (int ii = 0; ii < 10; ii++) {
    if (num[ii] > 0) {
        answer3 += num[ii];
    } else {
        answer4 += num[ii];
    }
}
Murtan 317 Practically a Master Poster

I apologize, it would appear in that context that you can in fact do an argv++.

I expected a compiler error similar to the one this code generates:

int main(int argc, char * argv[])
{
	argv++;
	int foo[] = {1,2,3};
	foo++;

Where I get the following error on the foo++ line:

error C2105: '++' needs l-value
Murtan 317 Practically a Master Poster

Line 58: else if (m > 60) should compare m > 59

You have made no additional effort on display1Time() or elapsed() and I have already given you suggestions for those:

in displayTime() you need to do something so that 5 hours and 5 minutes displays as 05:05 and not 5:5

Maybe you should print the tens digit and the ones digit of each number. If you don't understand that, you could look into "iomanip, setfill and setw".

and

In elapsed(), realize that t1 is the 'start' time and t2 is the 'end' time, and think back to your basic math:

  • How much time has elapsed between 08:45 and 10:15?
  • How did you figure out that it was 01:30?
  • Make the computer do that...
Murtan 317 Practically a Master Poster

That was a nice paragraph, but I still have no idea what you wanted to do with the data from Input[2].

"deduce the '8' from a counter variable"?

Why don't you write (in english) what you need to do with each character (or the set of characters if that's easier).

Murtan 317 Practically a Master Poster

Comment on your first code segment: I would have been tempted to use fgets() but your code should work.

Second and Third code segment: The following will always subtract 65 (which is the ASCII code for 'A'). Is there any time you wouldn't want to do it? (For example, if the character were a '5' you will get a negative number.)

int k;
/* - - - */
k = Input[0][countinc] - 'A';

Fourth code segment: In order to use strcmp() you need to have null terminated strings. You would have to declare both CountMin and k as char[2] and put '\0' in CountMin[1] and k[1]. But if all you want to do is to compare the character '8' and Input[2][y], you can just do that:

if (Input[2][y] == '8')

The code above is equivalent to what I think you were trying to do.

Murtan 317 Practically a Master Poster

There's no real difference in how the symbol is treated other than the fact that the compiler would allow you to modify argv in the second example. (Not that modifying argv is a good idea.)

The first example should complain if you tried to do argv++ but the second example should happily let you do it -- even though its a bad idea.

Murtan 317 Practically a Master Poster

You were right about his number, but that's not really C++, that's just basic logic. You could understand that and correct it. (And just to back you up, if you had posted that code, I would have said something, his code was a suggestion. If you want to post functions that you have completed that you're not sure are correct, I'll review them for you.)

in displayTime() you need to do something so that 5 hours and 5 minutes displays as 05:05 and not 5:5

Maybe you should print the tens digit and the ones digit of each number. If you don't understand that, you could look into "iomanip, setfill and setw".

In elapsed(), realize that t1 is the 'start' time and t2 is the 'end' time, and think back to your basic math:

  • How much time has elapsed between 08:45 and 10:15?
  • How did you figure out that it was 01:30?
  • Make the computer do that...
Murtan 317 Practically a Master Poster

Can you use vector?

If not, you have a little more work cut out for you, but it can still be done. (I am presuming you have a heap and can allocate memory.)

I can fairly easily imagine a class where you can 'add' a C style string to it and it would keep an array of the strings. When you call the 'add' it could allocate enough space to hold the string and copy it in. It would then store the pointer to the new string in an array of character pointers. If you ran out of entries in the array of pointers, you could allocate a new array of pointers (some number of pointers bigger -- think 50 or 100) and copy the old pointers to it and release the old array.

This would provide functionality similar to vector<string> without using "non-native" code.

Once you have assembled all of the trade data, you would return this new object and the calling code could iterate the strings in the object to access all of the compiled data.

Murtan 317 Practically a Master Poster

What about the rest of the post?

Why can't you convert from a string to a number, add one and convert it back?

And if an employee didn't have a mobile, I'd leave the field blank, not fill it with zeros.

Murtan 317 Practically a Master Poster

Ok, so I have the values 0,1,2,3,4,5,6,7,8,9,10 in those positions in the input array...

You caclulate mid as (low + high) /2 so the first mid is 5?

we put 5 at the root and iterate left with (0,4) and right with (6,10)

(0,4): mid=2 we put 2 to the left of 5 [left: (0,1) right: (3,4)]
(0,1): mid=0 we put 0 to the left of 2 [left: none right: (1,1)]
(1,1): mid=1 we put 1 to the right of 0 [none]
(3,4): mid=3 we put 3 to the right of 2 [left:none right: (4,4)]
(4,4): mid=4 we put 4 to the right of 3

(6,10): mid=8 we put 8 to the right of 5 [left: (6,7) right: (9,10)]
(6,7): mid=6 we put 6 to the left of 8 [left: none right: (7,7)]
(7,7): mid=7 we put 7 to the right of 6
(9,10): mid=9 we put 9 to the right of 8 [left:none right: (10,10)]
(10,10): mid=10 we put 10 to the right of 9 [none]

so we built something like:

5
    2      8
 0   3   6   9
z 1 z 4 z 7 z 10

The z's are empty nodes. How much more balanced does that need to be?

Murtan 317 Practically a Master Poster

Ok, so what kind of tree does it build?

How is it sub-optimal?

What would you have to change to make it optimal?

Murtan 317 Practically a Master Poster

Please don't answer each post since your last with the same string, we all have to read through all of them.

I can't imagine any phone system where you can pre-order sequential 7 digit phone numbers, but ignoring that for now...

Why does the 7 digit phone number have to be a string?

Or if it does, why can't you convert it from a string to a number, add one and convert it back?

If you're REALLY desperate, you could convert the last character of the phone number to a number and add 1. If the number is now 10, put a '0' down for the last digit and 'carry' the one to the next-to-the last character. (At least that's how I learned to do manual addition when I was in school.)

Salem commented: Very good, nice simple "string" addition, just like how it's done on paper. +27
Murtan 317 Practically a Master Poster

Is there any chance an OS Design file is human readable?

Murtan 317 Practically a Master Poster

Ok, comments.

Indenting is your friend, feel free to use him consistently.

First, why use doubles for the elements of the square. They should all be integer values, right?

I don't think I'd use a for(i ... for (j ... to fill the box. I would pre-initialize i and j (to be the center top like you propose) and then use a for (m = 1; m <= n * n; m++) as the loop.

Did you intentionally not put any braces on your for statements that starts on lines 15 and 16?

If you want to insist on using the for loops as written, consider removing the i++ and j++ from then ones on line 15 and 16. You went to a lot of work on lines 20 and 22 to set them where you wanted them, why would you want to increment them?

Murtan 317 Practically a Master Poster

I'd like to experiment with the code to try it, but in the interest of a quick answer, try low < mid on line 20 and mid < high on line 25.

Basic translation: If there are values between low and high that are lower than mid, add them to the left. If there are values between low and high that are higher than mid, add them to the right.

Murtan 317 Practically a Master Poster

Do you need to return the whole result in a character buffer?

Could you return a vector of strings with one string per trade?

Murtan 317 Practically a Master Poster

Same result here.

You need #include "person.h" in student.h because Student derives from Person.

Murtan 317 Practically a Master Poster

It's all based on your object model. If you write the model so that you need to set the location, then you need a setLocation.

I'm sure I could come up with (or you could come up with) several examples that require either public access or mutators. For example, your Point class (or struct) very likely has public or mutable members.

In this scanner case (and I don't have any idea what real-word element this represents if any, so take these with a grain of salt) I have a few questions:

Does the scanner NEED to know where it is, or should the position of the scanner be wrapped in a higher-level object?

If the scanner needs the location, how is the location used?

Might you update the scanner position with move() and/or moveTo() instead of setLocation()? (that would presume that the scanner has input or control of where it is)

In the end its all about how you model the object (or objects) in your system, a lot of which can be very personal and involve strong opinions.

I know on one of my larger projects we had fairly in-depth (and sometimes somewhat heated) discussions about what objects should exist, what they should be named, what their job should be, what they needed to know to get their job done and how they would talk to the other objects in the system. People had real opinions about how the system should fit …

Murtan 317 Practically a Master Poster

I built and compiled your code.

I added one debug line:

for(row=0;row<MAXSTUDENTS;row++){

printf("\nEnter First name : ");
scanf("%s",name);

for(col=0;col<EXAMS;col++){
printf("\nExam score : ");
scanf("%d",&grade);

total+=grade[row][col];

printf("grade[row][col]=%d, total=%d", grade[row][col], total);

}

This is the output:

Enter First name : Alice

Exam score : 20
grade[row][col]=20, total=20
Exam score : 20
grade[row][col]=-858993460, total=-858993440
Exam score : 20
grade[row][col]=-858993460, total=-1717986900
Exam score : 20
grade[row][col]=-858993460, total=1717986936A
Murtan 317 Practically a Master Poster

First, this isn't your thread. You aren't supposed to SOLVE the problem for them, THEY are supposed to do most of the work. We only want to help them through the code they don't understand.

The assignment (which I know wasn't yours) was to take 15 students and their exam scores and after all of the input was complete to then produce a report similar to the following:

Name                  E1  E2  E3  E4  Final  Grade
Alice                 90  95  93  92   93      A
...
(repeat for all 15 students)
...
Class average                          75

or something like it.

The names need to be stored (and your sample code does NOT do that). The grades also need to be stored (your code has space for that, but doesn't do it.) The final score is supposed to weight the grades. The program is supposed to calculate the class average final score.

Murtan 317 Practically a Master Poster

Define successfully.
How many grades did it print out?
Were there 15 grades?
Did you attempt to add additional printf's to confirm that the grade array actually got any data in it?

Murtan 317 Practically a Master Poster

name was declared as char name[20]; which is enough space for ONE 20 character name and '%s' is DESIGNED to work with character arrays.

grade was declared as int grade[MAXSTUDENTS][EXAMS] which is enough space for 15 students to have 4 exam scores each and "%d" is not designed to work with arrays, it only works with a single integer.

Feel free to run the code...input 4 grades for all 15 students and then try to print back out the data you entered, it won't be there.

Murtan 317 Practically a Master Poster

Yes, grade is now a two dimensional array.

Do you always want to put the score in grade[0][0]?

Murtan 317 Practically a Master Poster

I have stated it already in my code

for(col=0;col<EXAMS;col++){
printf("\nExam score : ");
scanf("%d",&grade);

That was from your code.

Murtan 317 Practically a Master Poster

It doesn't really matter which side of the comment is on, comments are for us to read, the compiler doesn't care.

Your code

if (h < 0)
{
return 1; // error code +1 = underflow hours
}
else
{
return 2; // error code +2 = overflow hours
}

Will always return 1 or 2 and never get to the rest of the code.

You aren't really testing for overflow.

(The minutes testing has the same problem.)

Murtan 317 Practically a Master Poster

This is heading into what I think the key difference is in a lot of designs.

Are you using C++ and classes and polymorphism or are you writing object oriented programs. There is a distinct difference between a program with classes and a program written around objects.

The difficulty comes in coming up with the right object and the right interfaces to make it all work together.

Murtan 317 Practically a Master Poster

I didn't notice it before, but

printf("\nExam score : ");
scanf("%d",&grade);

isn't correct.

You might be able to scanf("%d",&grade[row][col]);

Murtan 317 Practically a Master Poster

Well...that last example won't work because classes default to private. If you put a public: in front of the int A it would work.

However both of the last examples (directly accessing the member or a reference to the member) are violating the principle of data hiding. Anyone using the class now has to know about how it is implemented. (Granted that for this example there isn't much to know.)

What if in the future, the int value needed to be stored and retrieved from somewhere other than application memory? (Say a database or from another application) The last two examples would require client code to change. But the first example with the accessors (get and set) the clients wouldn't know (or care) where the int came from or went to, the implementation details of where the int is stored belong to the class.

Murtan 317 Practically a Master Poster

As we stated in your previous thread, we will help you if you put in some effort, but we don't solve your problems for you.

When posting c++ code, please use c++ code tags
[code=c++] // Your code here

[/code]

Just pick one function at a time and write them. Lets start with set time...it has some great comments about how it should be implemented, here I'll even implement one case for you, see if you can write the other three and post your code:

int setTime(Mytime& t, int h, int m );   
{
   
// if valid time sets hh and mm to h and m 
// and returns 0
// if invalid returns integer > 0 as error code
// error code +1 = underflow hours
// error code +2 = overflow hours
// error code +4 = underflow mins
    if (m < 0) return 4;
// error code +8 = overflow mins
                                     
    t.hours = h;                         
    t.mins = m;
    return 0;
}
Murtan 317 Practically a Master Poster

It seems as if you have a solution in mind, why don't you try to implement it and if you have any trouble, post your code along with the question. (Something like "I expected it to do ___ but it is doing ___")

Oh, and when posting c code, please use c code tags
[code=c] /* Your code here */

[/code]

Murtan 317 Practically a Master Poster

If I'm reading the assignment right, I suspect what they want you to do is first read all of the data then make a 'report' from the data you read.

You can perform the calculations as you read the data, but then you need to save the results until you're ready to do the report.

Murtan 317 Practically a Master Poster

When posting c code, please use c code tags
[code=c] /* Your code here */

[/code]

Yes, that's where the total=0 goes.

You could simplify the following code by using else:

if (ave>91) printf("A");
if (ave>=81 && ave<=90) printf("B");
if (ave>=71 && ave<=80) printf("C");
if (ave>=61 && ave<=70) printf("D");
if (ave<=60) printf("F");
/* Could be replaced with this code */
if (ave>=91) printf("A");
else if (ave>=81) printf("B");
else if (ave>=71) printf("C");
else if (ave>=61) printf("D");
else printf("F");

Your code (as posted) does not presently meet this requirement:
-store the student names in a two-dimensional array.

You're not 'weighting' the exam scores as directed:
-calculate the final score of each student computed as:
...exam 1 is 20%
...exam 2 is 20%
...exam 3 is 30%
...exam 4 is 30%

and you presently have no code to support calculating a class average.

Murtan 317 Practically a Master Poster

It depends more on the specifics of what you're trying to do, but the top options that come to mind are using external programs (like sed or grep) to do the removal or if it is simple enough, you might be able to use FOR /F is your version of DOS supports it.

Note that most of the above will need to read from the existing file and write to a new file. You could delete the old file and then rename the new file to the old name, but they won't be able to write it "in-place".

Murtan 317 Practically a Master Poster

@Zalezog

Don't quote the whole message if you only want to comment on a few lines.

@AdRock
When posting c++ code, please use c++ code tags
[code=c++] // Your code here

[/code]

(Don't make me tell you again)

With vectors, you don't have to make a 'first pass' to count the number of records and a 'second pass' to read the data. The vectors don't have a size limit.

If you want to confirm that your matrix is rectangular, you could verify the counts after you're done reading.

Murtan 317 Practically a Master Poster

When posting c++ code, please use c++ code tags
[code=c++] // Your code here

[/code]

In the line:

len=(int)log10(num)/log10(base)+1;

the (int) is binding to the log10 call
rewrite the line as follows to get the logs divided before taking the int:

len = (int)(log10((double)num)/log10((double)base))+1;

The casts to double are in there because my compiler (vc++ express) was complaining that it couldn't figure out which overload to use.

Murtan 317 Practically a Master Poster

To help me and you think about it, write down in english what you think the compare function should be doing.

It will help me to understand what you intended and whether or not it will accomplish your goal, along with whether or not the function is doing what you think it does.

Murtan 317 Practically a Master Poster

Yes, functions that take a void * will accept any pointer type as they have no expectations of the pointer.

Murtan 317 Practically a Master Poster

if words[answer] == r

Murtan 317 Practically a Master Poster

Off the top of my head, I suspect that the fscanf is reading too many or not enough bytes.

I recommend that you either treat the whole file as binary or treat the whole file as ASCII.

Where you do fprintf(fp, "%d\n", i) and fscanf(fp, "%d", &i) you could just as easily use fwrite(&i, 1, sizeof(i), fp) and fread(&i, 1, sizeof(i), fp) . The amount read/written would be far more consistent.

Murtan 317 Practically a Master Poster

On line 2, r is coming from the values in the dictionary, not the keys.
So you can't use it as a key on line 8, you can't index a dictionary by the definition.

You could either test to see if the answer is a key and if it is, if the value matches the definition you have.

Alternatively (and probably better) iterate the keys on line 2 and then don't print the key, but print what you lookup from the dictionary using the key on line 6. Then you can just compare the answer with the key value.

SoulMazer commented: A big help. Followed through. +1
Murtan 317 Practically a Master Poster

Are you sure the link to test1.cpp is the right file?

It is calling members of Logbook that are not defined in logbook.h and if I understand correctly, both files were given and you're not supposed to change them.