Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

My guess is that line should be calling the overloaded >> operator while( infile >> b ) , but its only a guess because I don't know what your program is supposed to be doing.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Basically the please hit any key to enter doesn't show up in Visual C++.Thanks for help

Because you didn't tell it to say that. When you run the program from the IDE, that message appears because the IDE told it to. When you run the program from the command-line that message will not appears unless your program tells it to.

>>while(b.get_account_number()!=-1)
That is an infinite loop. The value returned by that method never changes.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you forgot to initialize temp->next = NULL; at between lines 28 and 29, so at line 37 it can not find the last node.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Note that you have to allocate a new node on each iteration of the file read.

while( fd >> surn >> initial)
{
       temp1 = new phonenode;
       strcpy(temp1->surn, surn);
       strcpy(temp1->initial, initial);
       if( start_ptr == NULL)
      {
             // Add new node to the head of the linked list
      }
      else
       {
            // add new node to the tail of the linked list
       }
}

}

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

lines 31 and 32: what are you attempting to do there? chara arrays do not have overloaded operators such as >> If you want to copy the arrays then use strcpy() function. Either read your textbook or google to find out how to use that function.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It means the compiler doesn't know what string is. You failed to include <string> header file. After doing that, you need to declare strings as being part of std namespace: int find(const std::string& str);

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Your program is pretty close, you just need a few changes, such as int main() , use pointer to array in scanf() and flush out the '\n' characters

int main()
{
	int array[50],i,ele,n;
    char a;
	//clrscr();
	printf("the list should be sorted in ascending order\n");
	printf("enter the size of array\n");
	scanf("%d%c",&n,&a);
	printf("enter the elements\n");
	for(i=0;i<n;i++)
	{
		scanf("%d%c",&array[i],&a);
	}
	printf("enter the element to be searched\n");
	scanf("%d%c",&ele,&a);
	binary(array,n,ele);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>I'm using Dev-C++. I know its outdated, but last time I downloaded VS it totally screwed up the computer I was using and I had to get a new hard drive, so I really don't want to mess with it again.

??? Never heard of that before

In Dev-C++ you should have first created a project by selecting File --> New --> Project, then in the dialog box select Console Application. After the IDE finishes creating the project you can add the *.cpp and *.h files to the project.

>>I'm not sure about what you mean about how I'm linking them together,
When you have several *.cpp files they each have to be compiled into object files (your compiler will create *.o files). After that the linker has to put all those *.o files together along with the libraries (*.a) in order to create the executable program. Most (if not all) of the libraries you will be using for the forseeable future will be supplied by your compiler.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

What compiler are you using (if you already told us in another thread then tell us again because I don't want to have to read all your other posts to find out). And how are you linking all those files together ? Are you doing command-line or IDE builds ?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

MS-Access is a great database for small projects. Its ok for 1-3 simultaneous connections. Anything more and Access can generate file corruptions.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Here is another ODBC example that uses MS-Access and the Northwind example database. It does not cover everything that can be done with ODBC, just the basics of how to connect, run a query and get the results.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

1) suggest you define macros STDIN and STDOU instead of hardcoding 0 and 1 in the read/write statements

#define STDOUT  1
#define STDIN   0

2) use sizeof operator to get the size of data

write( STDOUT, buf4, strlen(buf4) );
    read( STDIN, myArr[i].gender, sizeof(myArr[i].gender) );
    write( STDOUT, buf5, strlen(buf5) );
    read( STDIN, myArr[i].status, sizeof(myArr[i].status) );

[edit] And what they said above ^^^^ [/edit]

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
num3 = (num1 * num2) / 2.0;
cout <<  "Their average is " << num3  << "\n";
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

try using more parentheses, like this: cout << "Their average is " << (num3 = (num1 * num2) / 2.0); or splitting it into two separate lines.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Post the errors. My guess is that it doesn't like line 10.

lines 15 and 16: The value of revl is 0 (line 12) so the results of those calculations will also be 0.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>I seem to recall I had to include iostream.h to use the CString class. Do I have that right?

No. You need to create an MFC program or a console program that supports MFC. The IDE will generate the files with necessary includes, such as afx.h.

1) There is no relationship between CString and iostream. They are two distinctly different c++ classes, one can be (and usually are) used without the other.

2) CString is part of MFC, so it can't be used without MFC.

Why would you want to use CString in a non-MFC program? There already is an alternative -- #include <string>

Frederick2 commented: Thanks for the input Ancient Dragon! +2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

don't add the '-' until the words are printed out at lines 18 and 19. Then print two words at a time with the '-' between then.

for( int i = 0; i < svect.size(); i += 2 )
    cout << svec[i] << '-' << svec[i+1] << '\n';
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

#include <iostream>

Can't use that in C programs.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>am i missing something?
Just add a counter, when it reaches 20 then stop the loop. Also, pay attention to the quantities that are displayed because the smallest ones are sorted to the top, not to the bottom. So the first 20 items in that array will be the smallest, not the largest. To fix that you will need to change the sort callback function on line 18 of your original post to use > operator instead of <.

>>damn why cant i use the CODE button
I don't use a button, just add code tags manually

[code]

// put your code here

[/code]

NEW DANIWEB FEATURE Look at the top of the Quick Edit window, next to the other buttons, and you will see [code] button. Just click it and paste your code between the two tags as I showed above.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

This should do it

vector<pair<string,int> >::iterator it;

for(it = wordvector.begin(); it != wordvector.end(); it++)
   cout << (*it).first << " = " << (*it).second <<  "\n";
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

AFAIK we were never able to list just the solved threads. The best you can do is list all the threads that you posted in and the ones you started.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you have to overload the << operator

class MyClass
{
public:
   friend ofstream& operator<<(const ofstream& out, const MyClass& str);
..
...
};
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

static class data objects also have to be declared like normal globals.

#include "DivSales.h"
#include <iostream>
using namespace std;

DivSales::totalSales = 0;

void DivSales::addTotal(int a, int b, int c, int d)
{
	cout << "Enter 1st Quarter:" << endl;
	cin >> a;
	cout << "Enter 2nd Quarter:" << endl;
	cin >> b;
	cout << "Enter 3rd Quarter:" << endl;
	cin >> c;
	cout << "Enter 4th Quarter:" << endl;
	cin >> d;

	quartSales[0] = a;
	quartSales[1] = b;
	quartSales[2] = c;
	quartSales[3] = d;
	totalSales = (a+b+c+d);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

This should fix that compiler error

const LinkedList::Iterator LinkedList::InsertAfter(Iterator& Iter, const ItemType& Item)
   {
      nodePtr nNode = new Node(Item, NULL, NULL);
      Iter.node->next= nNode;
      return(nNode);


   }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>scanf("%s",&Guess);
The "%s" tells scanf() that Guess is a pointer to a character array, not a single character. If all you want is a single character then call getchar() instead. (link)


If you want them to enter "open sesame", which is two words separated by a space, then its a lot easier to declare Guess as a character array then use fgets()

char Guess[80] = {0};
fgets( Guess, sizeof(Guess), stdin);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>but whenever i try it crashes the program. I also cant use *iter.node->next, because it says which takes a right hand operand of type nodePtr.

That's not what I posted -- re-read my post, it requires the parentheses ()

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It gets worse than that -- the size could be different between compilers on the same os and between operating systems.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

new operator causes an exception if it cannot allocate the memory, so your check for NULL will not do anything. You need to put that line in a try/catch block. As an alternative, you can use nothrow (link) and leave that check in your code.

I would think you need to add the new node to the Iter parameter, not tail. (*Iter).next = nNode;

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Some c++ stl classes, such as string, vector, and list, return size_t in some of its methods. For example. std::vector size() returns size_t value. Some compilers (such as Microsoft) will produce warnings if you attempt to compare size_t with int or long.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

A better flu solution

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Please note that #include <string> is only necessary for Borland. CODE::BLOCK and Dev-C++ do not need it.

That may be true, but its always good programming practice to include it anyway so that the code is portable across compilers.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

There are no compilers thatt will do it. If you are running MS-Windows then view Task Manager while the program is running and it will tell you how much memory it is consuming.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Most of the stuff you seen in your textbook will also probably apply to Vista. The major difference is in the include files. If you look towards the bottom of that link I posted you will find the include files you need and an example C program. It illustrates how to call _open() two ways: both with and without the pmode parameter.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

O_RDWR is used by very low-level C _open() function. Most programmers today use higher-level FILE* functions in C or fstream c++ class. But if you read this link you will see that O_RDWR is NOT one of the pmode flags -- pmode refers to permissions and is useful only when creating a new file.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Thanks!

Since I don't know much about Multithreading,

There's no better time than the present to learn. Write a simple console program that does nothing much more than create another thread and wait for it to finish. That is enough to show you how threads work -- its not really all that hard to do. CreateThread() parameters look complicated, but most of them can be set to NULL.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Its done almost like you posted it. Post what you have tried so that we can see what you might be doing wrong. You have to include <string>, and its lower-case "string", not "String". C++ is case sensitive, so you have to be careful about using capital letters.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

a) Flag Bad Post does not affect post count.

b) Already asked for that awhile back but they shot it down.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Line 28:
1) use a different loop counter name because it is hiding the loop counter declared on line 18.
2) why does that loop begin at 2 instead of 0, such as like this? for(int j = 0; j < nrAttend; ++j)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Each line in the data file represents the high and low temps for the corresponding month, such as the first line is for January, second line for Feb, third line is March, etc. So all you have to do is have an integer that counts the lines read. So the first line read would display month[0]

int count = 0;
 while (inData>>temp_highs>>temp_lows)
{
       outData<<month[count]<<" "<<temp_highs<<" "<<temp_lows
            <<"\n"; // new line here
      ++count; // increment the counter

}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>outData<<month<<" "<<temp_highs<<" "<<temp_lows<<endl;

month is a 2d array of strings. How else do you expect that statement to behave??? If you want it to print the month name then you have to tell it which one, like month[0].

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Check the parameter list again -- according to function prototype the 4th parameter for averagehigh() is supposed to be ifstream but you are passing ofstream. You need to correct one of the two.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 27 and 28: you failed to open the files

ifstream inData("myfile.txt");
ofstream outData("outfile.txt");

>>"too few arguements to function

Carefully check and recheck the argument list in the function prototypes that appear at the top of your program with the parameter list that is passed on lines 37-40. There apparently are some discrepancies.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>BTW, how does c_str() work? I will read about c_str() later.
Don't read about it later -- DO IT NOW.

kvprajapati commented: Well said. +13
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

A "code snipped" is supposed to be some code you have finished and want to show everyone else to help them solve a similar problem. That's why there are no "reply" or "quote" links in your thread so that others can help you. Unfortunately Dani has decided, unwisely IMO, to mix code snippets in the same forum as c++ questions, confusing people like you who really don't know the difference between them.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Good thing you proposed a challenging project. You will learn much more this way and your knowledge base will increase considerably. Don't be bothered about "biting off more than you can chew" ... u will choke, and then you will swallow , with pain, and you will be the wiser for it.

If he has all the time in the world I might agree. But there is a short time constraint -- I suppose the assignment has to be turned in before the class ends.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>I still encounter problem with conversion of string variable to numeric variable using strtof() function call. It seems that that function requires a char instead of string for the conversion

If you had bothered to read the methods available to std::string you would have seen c_str(), which returns const char*. Next time read about the classes you are using instead of blindly tossing code to the screen hoping the compiler will fix your bugs for you.

And you should not have made this a "code snippet" because it ain't one.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you just want to add a new line of text at the end of the file, then open the file for append mode. Read about the open method here. Or call seekp() to set the file pointer to end of file before writing.

If you want to add a new line somewhere else then you have to rewrite the entire file.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

pthread.h is not natively supported on MS-Windows operating system. But you can get win32 port of that.

tux4life commented: You're doing an incredible job here :) (not sarcastic :P) +21
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>I would like to work on POSIX thread programming using TC v3.0

You can't -- that compiler is too ancient.

STL is supplied with a compiler because it is compiler-implementation specific. Your compiler doesn't have it because the compiler pre-dates STL. Upgrade to a modern compiler such as Code::Blocks or VC++ 2008 Express and you will have the STL for that compiler.

Salem commented: Well said +36
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

So, let me get this straight: you told your prof that you will write a program that you have no clue how to write??? Like biting off more than you can chew?

On a scale of 0 to 100% how well do you know c++ or c ? Are you taking intro, intermediate, or advanced class ?

For the graphics I suppose wxWidgets might be the best way to go because its portable to most compilers and at least three operating systems that I know of. But wxWidgets will require a firm understanding of C language.