WolfPack 491 Posting Virtuoso Team Colleague

What is the meaning of q?

WolfPack 491 Posting Virtuoso Team Colleague

[search]pascal triangle[/search]

WolfPack 491 Posting Virtuoso Team Colleague

if you don't know the rules, you should probably go find them on google or something.

Nope, no time. Give me the input sequence that can recreate the runtime error. When I enter column 1 as the very first input it exits.

WolfPack 491 Posting Virtuoso Team Colleague

Too long to make all the corrections. Make corrections for number 1 and number 19. You can understand as I have commented the changes. Do the others yourself and post if you have other problems.

#include <iostream>
using namespace std;
const double PI = 3.1415; 
// The constant pie. You may know that you can't output this as a fraction as pie has infinite decimals.
int main()
{
    float area;
    float base;
    float Sbase; //Small Base (Trapezoid Formula)
    float Bbase; // Big Base  (Trapezoid Formula)
    float Wbase; //Width of Base (Pyramid Formula)
    float Lbase; //Length of Base (Pyramid Formula)
    float circumference;
    float height;
    float length;
    float perimeter;
    float radius;
    float side;
    float sidea;
    float sideb;
    float width;
    
    int op; // make op an int. if it is a char it can only hold one character. So you can't input 10, 11, 12, .... That is why you got the multi character errors.
    char again = 'y';
    
    /* Removed your greetings to reduce number of code lines. Add them again */
    while (again == 'y')
    {
        //here the user chooses what he wants to find out    
        cout <<"FUNCTION LIST"<<endl;
        cout <<""<<endl;
        
        cout <<"\nArea of a Square = 1" <<endl;
        /* Similar couts for the other functions */    
        cout <<"\nVolume of a Sphere = 19"<<endl;
        cout <<"Surface Area of a Sphere = 20"<<endl;
        
        cin >> op;
        
        // Rather than using nested if else if statements, you could use a case statement too.
        // But I left it as it is.
        if …
Niklas commented: You helped me a lot thanks man +2
WolfPack 491 Posting Virtuoso Team Colleague

Well, the comparison also seems okay. Also if it is runtime errors, the problem is not with the syntax. Better post the 3 source files.

WolfPack 491 Posting Virtuoso Team Colleague
void Counter::display()
{ 
    std::cout << "The value of the counter is " << Count << std::endl; 
}

why wont it work?

This is correct. So no idea. Maybe you have not saved the correction. Or you are linking a different file. Anyway it is a problem with the linker, and not the source code. The sourcecode is correct. Double chekc the contents of the files you are compiling.

matrimforever commented: Awesome advice and help! +1
WolfPack 491 Posting Virtuoso Team Colleague

Thanks for the help so far. Something's wrong with my switch statement. It just goes to default , which is invalid selection then exits. What do I need to change?.

Most probably you haven't seen that I removed the quotes in the case statements.

case 1: // You had written '1'

Also i need to submit a driver.cpp file. Is that what you meant as the main.cpp? Not sure what that is.

If you have to submit only 2 files, counter.h and driver.cpp, just rename the main.cpp file to driver.cpp. If you have to submit 3 files, counter.h, counter.cpp and driver.cpp, you will have to shift the implementation of the counter class to counter.cpp and the main function to driver.cpp.

[counter.h]

class Counter
{
public:
    int Count; // If you want you can use long.
    // Counter(); Your assignment says not to define a contructor.
 
    void increment();
    void decrement();
    void display();
    void reset();
};

[counter.cpp]

#include "counter.h"
#include <iostream>
using namespace std;
void Counter::increment()
{
    Count++;
}
void Counter::decrement()
{
    Count--;
}
void Counter::display()
{ 
    std::cout << Count << std::endl; 
}
void Counter::reset()
{
    Count = 0;
}

[driver.cpp]

#include "counter.h"
#include <iostream>
using namespace std;
int main()
{
    int num1 = 0;
    Counter counter;
    counter.reset();
    while (1)// Added a infinite loop so that the program runs until you press 5.
    {
        cout << "\nSelect from the following options: Type" << endl;
        cout << "\n1 to increment the counter" << endl;
        cout << "\n2 to …
WolfPack 491 Posting Virtuoso Team Colleague
#include "counter.h"
 
 
using namespace std;
 
int main()
{
        int num1;
        Counter counter;
        cout << "\nSelect from the following options: Type" << endl;
        cout << "\n1 to increment the counter" << endl;
        cout << "\n2 to decrement the counter" << endl;
        cout << "\n3 to display the contents of the counter" << endl;
        cout << "\n4 to reset the counter to zero" << endl;
        cout << "\n5 to exit this program." << endl;
        cout << "\nValid operators are 1 - 4 " << endl;
        cin >> num1;
 
    switch( num1 )
 
 
            {
            case 1:
                counter.increment(); break;
            case 2:
                counter.decrement(); break;
            case 3:
                counter.display(); break;
            case 4:
                counter.reset(); break;
            case 5:
                exit(1);
            default:
                cout <<"Error, not a valid operator."<<endl;
 
           }
 
    return 0;
}

counter.h

class Counter
{
public:
    int Count; // If you want you can use long.
    // Counter(); Your assignment says no to define a contructor.
 
    void increment()
    {
        Count++;
    }
    void decrement()
    {
        Count--;
    }
     void display(){ std::cout << Count << std::endl; };
     void resetCounter(){Count = 0;};
};
WolfPack 491 Posting Virtuoso Team Colleague

Look. For the book I gave a link, you don't need asssembly at all. Only C or C++ will be enough. So just buy that book and follow it. This is the official site for that book and its operating system. You can download the sourcecode also from that site. What the book does is explain the design of the operating system. Before buying the book, try downloading the sourcecode and see if you can read through the cdoe without passing out. If you can, then buy the book. If you can't, learn C/C++ a bit further and then try writing an OS.

WolfPack 491 Posting Virtuoso Team Colleague

This is getting ridiculous.

WolfPack 491 Posting Virtuoso Team Colleague

Ok does it have to be C and C++ or one or anthoer?

Doesn't matter. There are Operating systems written in both C or C++. You will have to learn assembly language also.

WolfPack 491 Posting Virtuoso Team Colleague

It is possible to sort by subitem too. It all depends on the callback function that you send to the macro. If your callback function defines the relationship between Item1 and Item2 depending on the relationship between Subitem1 and Subitem2, you can sort by subitem. Can you post the code for the LVN_COLUMNCLICK notification of the ListView under the WM_NOTIFY message of the window procedure? Then I can get an idea on what you are currently doing.

Edit:
I will probably need the callback function you are using for comparison also.

WolfPack 491 Posting Virtuoso Team Colleague

Have you tried using the ListView_SortItems macro?

WolfPack 491 Posting Virtuoso Team Colleague

What I am trying to do:
Does the class object go in the header file or is it okay here? What do I put in the header file?

Well, you can put it here if you want. But the usual practice is to give it in the header file. The implementation is given in a cpp file, which is also usually seperate from the main.cpp file. So you will have 3 files in your program.
counter.h
counter.cpp
main.cpp


What I have so far, which is incomplete, but I want to see if I'm on the right track:

You may find this out yourself when you compile, but you haven't declared the variable Count of class Counter .

Also, to use increment() and the such, you should declare a object of class Counter , and then call those functions.

Counter counter;
counter.increment();
counter.decrement();
counter.reset();
...

like that.

WolfPack 491 Posting Virtuoso Team Colleague

Also can u find me a book on it at amazon or barnes and nobles Thank you

You seem to be a newbie without any programming experience whatsoever. Go and learn to crawl before trying to run. But what the heck. Go and get burnt. Here is a good book with already written source code. But if you don't understand all the #defines don't come here asking. Get a good C/C++ book and learn them yourself.

WolfPack 491 Posting Virtuoso Team Colleague

Why don't you write a simple code snippet and see? If the compiler doesn't complain, then it should be allowed.

WolfPack 491 Posting Virtuoso Team Colleague

I need to calculate the total hours and charges. Would the best way to do this is to have another formula at the bottom like CalculateCharges or do a cout with the num+num+num?

Create a variable called total_hours just after count. Inside the loop add num to it. After exiting the while loop cout the value of total_hours. Same for the charges.

WolfPack 491 Posting Virtuoso Team Colleague

my if condition is not working properly

That is because your logic is wrong.

for(j=0;j<a;j++)
    {
        q--;
        namre[q]=name[j];
    }
    if( strncmp(namre,name,num ) == 0)
    {
        printf("the word is same");
    }
    else
    {
        printf("the word is not same");
    }

Use #include <string.h> at the beginning of your code.

WolfPack 491 Posting Virtuoso Team Colleague

Where is it not working? If ithere are compile errors, give us the error messages. At first glance getche(); should be changed to getchar();

WolfPack 491 Posting Virtuoso Team Colleague

And to stop her from changing it again, you can tick this checkbox.

WolfPack 491 Posting Virtuoso Team Colleague

I don't like the American version of football -- too dull, uninteresting and brutal. European football (what we call socker) is a lot more exciting.

Reminds me of what some foriegn dignitary said after watching his first American football game.
"If it is a game, it is too much. If it is a fight, it is not enough."

WolfPack 491 Posting Virtuoso Team Colleague

Good effort. There were some parts where you could clear things up a little. So I will keep my end of the promise and here is a working program. You may also want to read up a little more about [search]for, while and do while in C and C++[/search]

#include <iostream>

using std::cout;
using std::cin;
using std::endl;
using std::ios;
using std::fixed;

#include <iomanip>

using std::setw;
using std::setiosflags;
using std::setprecision;

#include <cmath>


//function prototype
double calculateCharge(double);


int main()
{
    int num;
    int count = 1;
    while ( count <= 3 )
    {
        cout << "enter hours parked ";
        cin >> num;
        cout<< setw(5)<< "Customer Name" << setw(10)<< "Hours" << setw(15)<< "Charge\n";
        cout<< setw(5)<< "Car " << count << setw(14)<< num << setw(16)<< fixed << setprecision( 2 ) << calculateCharge (num) << endl;
        count = count + 1;
    }
    return 0;
}//end main

double calculateCharge( double x)
{
    double charge;

    if (x <= 3)
        charge = 2;
    else if (x >19)
        charge = 10;
    else if (x > 3)
        charge = 2 + (x - 3) * (.5);
    return charge;
}
WolfPack 491 Posting Virtuoso Team Colleague

Sorry no idea. Never developed anything in the Solaris environment. So guess someone else will have to take over this thread.

WolfPack 491 Posting Virtuoso Team Colleague

gee. don't know if laureen is also the same person ( the one after my comment in brickfish ), but she sure looks cute.

By the way, the last time I voted ( 4th time), you guys were 5 out of 66. :D Looks like you will be eating jam :P

WolfPack 491 Posting Virtuoso Team Colleague

This is a long shot, but can you just try this and tell me what happens?

#ifndef _REENTRANT
#define _REENTRANT
#endif
 
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>
#include <iostream.h>
#include <cmqc.h>
#include <string.h>
#include <wait.h>
#include <sys/wait.h>
WolfPack 491 Posting Virtuoso Team Colleague

I didn't just append a () only. I changed what is before the () also. Look more closely.

WolfPack 491 Posting Virtuoso Team Colleague

Just change it to

cout << "\nThe value of theValue in num1 is " << num1.getValue(); 
// The get and set public functions are provided to access private variables
WolfPack 491 Posting Virtuoso Team Colleague

If it is your code, and you wrote that line, how come you are asking us what the meaning of that particular line is? Anyway, judging from the meaning of the word Re-entrant, that would mean that this program is designed to be run in multiple threads, and very well maybe a compiler specific flag. You better refer the compiler documentation or the program documentation if it was not written by you. Anyother things would be difficult to say unless we see the relevant source code.

WolfPack 491 Posting Virtuoso Team Colleague

Telling us to finish the hard part just by doing the easy part doesn't qualify as you showing your effort in this problem. But for the time being, explain the expected output for these inputs.

Enter a month (1 - 12): 2
Enter a starting day (0 for Sunday, 1 for Monday...): 1
                Febuary
        S  M  T  W  T  F  S
----------------------------------
WolfPack 491 Posting Virtuoso Team Colleague

I have no clue how to make intSum = 0; in the loop, so everytime you have clean variables.

Just assign it zero here. You will also have to assign 1 to intPowr also.

if (intNumb == 0)
       {
            cout << "Sum of digits is :" << intSum << endl; // displays result when int = 0
            cout << "Enter an integer number (o to stop): ";
            cin >> intInpt;
            intSum = 0; // Reinitialize
            intPowr = 1; // Reinitialize
       }
WolfPack 491 Posting Virtuoso Team Colleague

Okay that is the function calculateCharge but that was not what I asked for.I want you to write a program that gets the number of hours parked for one customer as user input and print out the fee calculated by using calculateCharge. After that it is a simple modification to convert it for 3 customers.

WolfPack 491 Posting Virtuoso Team Colleague

Not sure about the theory. But here is a working code.

#include <stdio.h>
//#include <iomanip> why are you including this? You are not using it.


int main()
{

    int binary1[8] = {0,1,1,1,1,0,1,1}; //8 element array
    int binary2[8] = {1,0,1,0,1,1,1,1}; //8 element array
    int binarySum[9] = { 0 }; // Initilize to zero like this. It is much faster.
                             // The long integer appeared because you didnt initilize binarySum.
    int overflow[9] = { 0 }; // Initilize to zero like this. It is much faster.
    int i;

    for (i=7; i >= 0; i--)// Since you are adding binary1 and binary2,
                          // You should index from 7. There is no element 9 for them.
    {
        binarySum[i+1] = binary1[i] + binary2[i] + overflow[i+1];
        if ( binarySum[i+1] > 1)
        {
            if ( i == 0 )
            {
                binarySum[ i ] = 1;
            }
            overflow[i] = 1;
            binarySum[i+1] %= 2;
        }
    }

    for (i = 0; i < 8; i++) printf("%i", binary1[i]);
    printf("\n");
    for (i = 0; i < 8; i++) printf("%i", binary2[i]);
    printf("\n");
    printf("Binary Sum is: ");
    for (i = 0; i < 9; i++) printf("%i", binarySum[i]);
    printf("\n");
    printf("\n");
    printf("Carry Bit is: ");
    for (i = 8 ; i>=0 ; i--) printf("%i", overflow[i]);
    printf("\n");

    return (0);

}
WolfPack 491 Posting Virtuoso Team Colleague

Okay. Post the code that calculates the fee for one customer. Then we will help you on the repetition part.

WolfPack 491 Posting Virtuoso Team Colleague

Looks like your question doesnt belong in the C/C++ or for that matter in any software development forum. To create charts in Windows you can use Microsoft Excel. Was that what you were looking for?

WolfPack 491 Posting Virtuoso Team Colleague

The problem was the member allignment of the structure. For example, lets take your structure.
It has 15 chars and one int (that is 4 chars). So the size by adding them up is 19 chars. But try outputing sizeof rectype . You will probably get 20. This is because the compiler optimizes the structure so that it occupies an integer number of words. So in this case the next best is 20. (5 words). Therefore if you tell it to read sizeof rectype number of data, it will read 20 chars and you will find that part of data in the next records to be missing as they have been read by the previous records.

One way to get out of this issue is to instruct the compiler to, not allign the structure so that it occupies a full integer multiple of words. You can use the #pragma directive for that.

#pragma pack(1) 
typedef struct
{
      int num;
      //char junk[4];
      char name[NAMELEN];
} rectype;

This will prevent the alligning and the data will be read properly.

Another way is to do this.

for(i=1; i<35; ++i)
{
      fread(&(rec.num), sizeof rec.num,1,f);
      fread(&(rec.name), sizeof rec.name,1,f);
      printf("Record #%3d is %15d --> %-15s\n",i,rec.num,rec.name);
}

That will read 15 chars and one integer rather that the size of rectype, and give you the correct output.

Edit: The allignment is done at member level rather than at the structure level as my above explaination may imply.
for the default …

WolfPack 491 Posting Virtuoso Team Colleague

I'm attaching the binary file with extension .txt

Attachment? What attachment?

WolfPack 491 Posting Virtuoso Team Colleague

ooh. Now it is Lonnie is it? Someone is two timing.:twisted:

PS:
Just so that the others can know, you can vote again after 24 hours of your last vote. So there goes my 3rd one.

WolfPack 491 Posting Virtuoso Team Colleague

Leave it to the WoLfMaN to figure it out. :cheesy:
@Andor: Surely you are using hybrid mode in IE, and linear mode in Firefox.

Just so that to make it clearer, I attached an image so that you know how to change it (if you didn't already know)

I think it's because of the AJAX call when you used the quick reply box. Can you reproduce the error upon refreshing the page?

I dont understand (I'm not english speaker).

I don't think Dani was speaking English in this particular instance. :mrgreen:

andor commented: You are right (andor) +4
WolfPack 491 Posting Virtuoso Team Colleague

I have one more question with my loop if you dont mind.
The ANIMATIONNODE_TYPE_NUMBER is one type of argument that the function accepts and it defines the input to be a float input, but I can also define my input to be a Vector type if I used ANIMATIONNODE_TYPE_VECTOR instead.

Now the problem is I have a total of 93 inputs that I need to create (36 float type and 57 Vector type)
The problem is the inputs are not in a clean sequence, meaning the first 3 inputs are vector type, then the next 2 are number type, then again 3 vector, 2 num.... etc and it alternates like that..
So How would I setup a loop to handle the 3 vector, 2 num type of a sequence?

Don't know if I understand your problem correctly, but there are a number of ways that you can solve this problem by using various kinds of loops.
One would be to use a loop that counts to 93, and check it the remainder or dividing the loop counter with 5 to decide if it is a vector or float.

for ( i = 0 ; i < 93; i++)
{
         switch ( i % 5 )
         {
                     case 0:
                     case 1:
                     case 2:
                               // this means the vector type
                               sprintf ( label, "InputNum %d", i );
                               mInputs[i] = AnimationNodeInCreate ( i, label , ANIMATIONNODE_TYPE_VECTOR );
                                break;

                     case 3:
                     case 4:
                               // this means the float type
                               sprintf ( label, "InputNum %d", i );
                               mInputs[i] = AnimationNodeInCreate ( i, label ,    ANIMATIONNODE_TYPE_NUMBER)
                               break;
         }
}
WolfPack 491 Posting Virtuoso Team Colleague

So do you all agree I should set up the dropdown menu items to open in a new window?

I say that its behaviour should be consistent with normal hyperlinks. If clicking on a normal hyperlink opens a new window, so be it. If clicking on a normal hyperlink opens a page on the same window I think these links which look like green hyperlinks should do so. I would want a new tab or new window to open only if I explicitly say so, by control clicking or selecting new tab or new window by a menu.

WolfPack 491 Posting Virtuoso Team Colleague

Go through the code given in this thread and try writing it yourself. If you encounter problems post them in a new thread. If necessary post a link to this thread also). Nobody hands out free lunch here.

WolfPack 491 Posting Virtuoso Team Colleague

Use sprintf (or snprintf (if available this is the best )) to create a string in the form of "InputNumber%d", and pass that to the AnimationNodeInCreate function.

int i;
char label[ 15] = "";
for (i=0;i<36;i++)
{
         sprintf ( label, "InputNum %d", i );
         mInputs[i] = AnimationNodeInCreate ( i, label , ANIMATIONNODE_TYPE_NUMBER );
}
WolfPack 491 Posting Virtuoso Team Colleague

Ctrl + Clicking normal hyperlinks work as they are supposed to. Only the links of the search tag do not. So I guess what I am experiancing is not because of a disabled option.

WolfPack 491 Posting Virtuoso Team Colleague

Then must it be an issue of darn Firefox 2.0 rc.

WolfPack 491 Posting Virtuoso Team Colleague

Just tested if Ctrl + Left Click opens a new tab in firefox. It does not.

WolfPack 491 Posting Virtuoso Team Colleague

Voted and left a stinking comment. You explain to Lauren. :p

'Stein commented: Hehe thanks Wolfpack. :) -'Stein +3
WolfPack 491 Posting Virtuoso Team Colleague

(1567 / 1 ) % 10 = 7
(1567 / 10 ) % 10 = 6
(1567 / 100 ) % 10 = 5
(1567 / 1000) % 10 = 1

See a pattern?

WolfPack 491 Posting Virtuoso Team Colleague

I already have the line so I should need to use getline again.

You have the line, and you can get the first word delimited by a '~'. So you can use strcpy to compare the first word of the line with the word entered by the user and go to the next line if it doesnt match. :)

WolfPack 491 Posting Virtuoso Team Colleague

while(!dealers.eof())
{
getline(dealers,line, '~'); //get line and ignore/skip delimiter
}

Use the following loop to read the file line by line.

while(getline(dealers,line)
{

}

That is better than checking for the eof bit of the file stream.

I see that when I do a cout << line; after getline, it displays one line at a time so I am guessing it doesnt store the whole file in the line string like I thought before. I am also guessing in that same while loop is where I need to do the line comparisons.

Yes. That is correct.

3. Create a istringstream object lets call it isstream, from the string line.

I understand creating the object using:

istringstream isstream (line)?

Yes. That is the way. Now try the following piece of code.

string token;
istringstream isstream (line);
while ( getline( isstream ,token, '~') )
{
    cout << token << " ";
}
cout << "\n";
WolfPack 491 Posting Virtuoso Team Colleague

Right. This is what you should do.
1. Open the file ( You have already done that)
2. Read the opened file line by line into a string (lets call it line ). You can use getline for this.
3. Create a istringstream object lets call it isstream , from the string line .
4. You can again use isstream and getline to get each word delimited by the '~' character.
5. Compare the first word with the user input and if it matches, display the 4th word.

Try it and post your effort. We will help if you encounter further difficulties.