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

>>Yeh, i agree remove that line
I didn't say that.

Maybe not, but I use them anyway just for clarity -- you don't have to think about it very much.

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

>>cout<<"Total price is= "<<(1500*12)+20000=";
remove the quote just before the semicolon. same problem on all the other lines in the 1st program

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

The file is not in the current directory. If you are using MS-Windows then use Explorer to verify the location of the file and add the full path to the filename. infile.open ("c:\\MyFolder\\studentFileName.txt");

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

Oh yea, I misread his post about VC++.

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

lines 9, 10, and 11: I thought this was supposed to be c++, not C ?????? So why are you writing C-style code in a c++ program?

cout << "Enter the keyword";
cin >> keyw;
cout << "Enter the key";
cin >> key;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

see line 41 of the code I posted. If you need the arguments just simply add them on that line.

I don't use system("PAUSE"). But you can add it anywhere you want.

>>how will i know that the struct has stored on the values
Add print stateuemts cout << "rank = " << dt.WorldRank

majestic0110 commented: Very kind, helpful and patient! +2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you can't use VC++ on Fedora because VC++ only runs on MS-Windows.

I have not used gdb in years but it should be able to handle a multi-file program with ease.

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

I don't know the answer to that so you will probably have to experiment to find out exactly how to do it. Another possibility is after you store it in that binary array

DATE dt.
memcpy(&dt, time_array, sizeof(DATE));
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It looks like that is the binary representation of a double. So why not just read it directly into a double and not bother with all that other code.

DATE dt;
infile.read(&dt, sizeof(dt));
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Here is one way to read that file and read it into a structure. VC++ 2008 Express compier.

#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <sstream>
using namespace std;

struct data
{
   int WorldRank;
   string Institution;
   string Region;
   string RegionalRank;
   string Country;
   string NationalRank;
   int ScoreOnAlumni;
   int ScoreOnAward;
   int ScoreOnHiCi;
   int ScoreOnNS;
   int ScoreOnSCI;
   int ScoreOnSize;
   int TotalScore;
};

ifstream& getaline(ifstream& in, char* line, size_t maxlinesize)
// read one line from a UNICODE formatted file and saves it into
// a standard ascii character array.
{
    char wc[sizeof(wchar_t)];
    size_t i = 0;
    while(i < maxlinesize && in.read(wc, sizeof(wc)) )
    {
        if( wc[0] == '\n')
            break;
        line[i++] = wc[0];
    }
    line[i] = 0;
    return in;
}

int main()
{
    vector<data> lst;
    ifstream in("..\\arw.txt", ios::binary);
    if( in.is_open() )
    {
        char line[255] = {0};
        in.read(line, 2);
        if(line[0] == -1 && line[1] == -2)
        {
            // unicode line
            // get a line
            getaline(in, line, sizeof(line)); // ignore the first line of titles
            while( getaline(in, line, sizeof(line)) )
            {
                // this is a tab deliminated file which means each column is deliminated
                // with a tab character.
                data dt;
                stringstream stream(line);
                string word;
                getline(stream,word,'\t');
                dt.WorldRank = atol(word.c_str());
                getline(stream,dt.Institution,'\t');
                getline(stream,dt.Region,'\t');
                getline(stream,dt.RegionalRank,'\t');
                getline(stream,dt.Country,'\t');
                getline(stream,dt.NationalRank,'\t');
                // etc. etc for the rest of the structure members

            }              
        }
        else
        {
            // ascii file
        }
        

    }

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

That is a UNICODE formatted text file which can not be read with standard fstream objects (that I know of). UNICODE files are not normal text files. The first two bytes are binary -1 and -2. So you first have to read the first two bytes to determine if it is in UNICODE format or not. The file you posted indicates it is UNICODE, and a hex dump of the file also confirmed that.

How did you generate that file? did your instructor give it to you for the class assignment or did you generate it yourself ?

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

It probably means you are online and the others are not online.

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

You can if you save all the points of the drawing. The Microsoft tutorial named Scribble does exactly that.

Also you might be able to save the drawing as a bitmap then save the bitmap. Another bitmap tutorial.

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

>>Mark Paul Twain Missippi 25
That line is not in the format you specified. It contains middle name (Paul). So do you store the middle name in the firstname or lastname, or just ignore it altogether?

>>This is only a sample data by in reality the file (.txt) contains 500lines and ~20 columns of data, with consists of characters, integers and floating point.
Then you have a lot more work ahead of you because the program must read all the columns in order to get to the next line. Maybe it would be more efficient to read one whole line at a time into one std::string then split it up with stringstream.

Post one entire line from that file -- load it into notepad, copy a line or two into the clipboard, then paste it here. Also an explaination of what each column means.

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

That saves it as binary data, so you can not view it with Notepad. If you want it saved as text then convert with CString

CString s;
s.Format("%d", r);
ar << s;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Q1: That's because I gave you bad info -- should be VariantTimeToSystemTime()

Q2: I don't know what that hex string is. Never saw it like that. Can you post an example?

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

Header files for mostly useful in multi-file projects where there are two or more *.cpp files which need to know about the same functions and definitions. Look in your compiler's include directory, it contains many header files. The ones you write are no different than those.

The more you write programs and header files the more useful they will appear to you. Especially when you begin to write multi-file programs. Many large projects consist of hundreds of *.cpp files, so common header files are absolutely essential.

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

So Can You help me to do that ?

No, sorry, its outside my expertise.

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

>>I don't know how to put line numbers on...how do I do that?

[code=cplusplus] // your code here

[/code]

put some print statements in various parts of the program to see that it is doing. Or learn to use your compiler's debugger so that you can execute the program one line at a time and see what it is doing.

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

>>but as far as i know this will store the details for only one person, right ?? what about the others, hope you understand where i am stuck.
Yes it will be for only one person -- BUT ...... you failed to read, or maybe comprehend, what the very next line is doing. It is adding that person to the array. Each time that push_back() line is executed it will add another name structure to the array of structures so that by the time the file is finished reading the array will contain a structure for each of the names.

>>I will not be able to used the >> operator as the names contains embedded spaces.
You mean there can be spaces in the first name or spaces in the last name? None of the data you posted is of that format. Only spaces between the names, not within the names.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
double corr(data data_sm, double meanx, double meany);

data getdata(const char file[], double* meanx, double* meany)
{
<snip>
	*meanx = getArrayBar (d.x , i -1 );
	*meany = getArrayBar (d.y , i -1 );

}

int main()
{
    double meanx = 0, meany = 0;
   <snip>
   data_sm = getdata(filename, &meanx, &meany);
    corr(data_sm, meanx, meany);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

yes, you have to code your own, something like you mentioned. Did you initialize all those integers to 0 before attempting to use any of them ? If not they will start out to be any old random crap, whatever happens to be on the stack at the time.

If that doesn't fix the problem then post code.

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

1. The header file should not have any code -- just function prototype extern short int DetectSensor(int sensorvalue[10]); Notice the semicolon at the end and there are no ( and )


2. In the *.cpp file, enclose the name of your header file in quotes #include "MySensor.H"; Angle bracks are for header files that are were supplied by your compiler, such as <string>. The ones you create are in your project's folder and should be surrounded by quotes.

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

Your program after line 7 is a big mess. Just delete all that junk.

I don't know what all those parameters to the delete function are supposted to be, but you don't need any of them.

All you have to do is open the input file, read the first and last names, compare them with what the user entered,

enter first name
enter last name
open input file
set a bool flag to false which is set to true if the name is found
while not end of file
     read last name
     read first name
     if last name and first name match user input
          set flag to true
          exit the loop and do nothing
end of loop
if the flag is still false
   add the last and first names to the file
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I see you never read your previous threads.

>>until now u didnt solve my problem use c++
WE are not supposed to solve YOUR homework, you are.

Ok, this took me all of 15 minutes to write

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
    vector<string> array;

    for(int i = 0; i < 3; i++)
    {
        cout << "Enter string #" << i+1 << ":  ";
        string word;
        cin >> word;
        array.push_back(word);
    }
    sort(array.begin(), array.end());
    vector<string>::iterator it;
    for(it = array.begin(); it != array.end(); it++)
        cout << *it << "\n";

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

You have not posted any code yet, so can not help you.

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

ok, here is example code

void print(int x, int y)
{
    cout << x << " " << y << "\n";
}

void calculate( int* meanx, int* meany)
// The two parameters are pointers to the integers that
// are declared in main()
{
    *meanx = 1;
    *meany = 2;
}

int main()
{
    int meanx = 0; 
    int meany = 0;
    calculate(&meanx, &meany);
    print(meanx, meany);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You have to use TurboC or TurboC++ compilers to use either of those links. graphics.h is obsolete and not supported by all other compilers.

I don't really know the answer to the question but I think it will be pretty complicated. Here is the jpg file format and here are other possible google links that may be useful.

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

>>You can also use the functions from conio.h,
Only if his compiler supports those functions. They are non-standard and only a few compilers support them.

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

convert to string then insert the commas

#include <sstream>
#include <string>
using namespace sd;

int main()
{
    int n = 4200;
    stringstream stream;
    stream << n;
    string str;
    stream >> str;
    // now insert the commas in the appropirate spot
    // I'll leave that up to you to figure out.
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>I would be able to do things so much easier if I knew certain functions existed.
You will, eventually. It takes awhile to get all that suff straight in your head -- I know it did for me.

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

>>i am new around here
Not with 22 posts under your belt

If you were banned you wouldn't be able to make this post. As for the color of your name -- looks normal to me.

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

That one confuses a lot of people -- just remember that on = is for assignment and two == is for asking a question.

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

>>is this correct usage?
No. Just like any other C program you have to read the data from the file.

#include<iostream>
#include <cstdio>
using namespace std;

int main()
{
    char text[255];
    FILE *name;
    name = popen("whoami", "r");
    fgets(text, sizeof(text), name);
    cout << "Name is : " << text;
    pclose(name);
    cout << endl;
    return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 49: if (size = 1) You are using the assignment operator not the boolean operator if (size == 1)

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

you could use pipes. see man pages for popen()

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

line 22: Oh I see them now -- that's why I always put them on separate lines so that they stand out and can be easily seen. Don't hide them.

while (i < size-2)    
  {
         cout << '-';
         i = i+1; 
   }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you are writing a console program then see these console functions. Not immediately sure which one(s) you need to use. You might also look through some of these links

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

First you have a DATE object, I don't know how you got that DATE but assume it comes from an SQL database query. So I'll just fake it here.

#include <windows.h>
#include <iostream>
using std::out;

int main()
{
    DATE dt = 123.4457676; // some fake number
    SYSTEMTIME stime;
    OleTimeToSystemTime( dt, &stime ); // convert to structure
    cout << stime.wMonth << "/" << stime.wDay << " " << stime.Year << "\n";
}

Click the link for SYSTEMTIME and you will see all the other structure members that you can use.

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

#1: get rid of that goto statement (lines 12 and 52)-- its a sure way to get an F on that program.

To exit the do loop when -1 is entered, add this on line 17: if( size < 0) break; line 47: isn't 0 a valid input value? If so then while( size > -1 ) line 22: what will that do if I enter size of 1? Answer: nothing because (size - 2) = -1 and the initial value of i is 0. Also, you need to put brackets { and } around lines 22 - 24. I see you have several other places where you need to use brackets. Indenting code is not enough to make multiple lines all part of the same loop.

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

line 29: recordcounter must be a const integer if it is to be used to set the array size as shown in lines 30-33. That means it must be a value > 0.

const int recordcount = 255;
Person person[recordcounter];

lines 30-33: delete all but one those arrays because you only need one of them. The struct contains all the information you need about one person -- you don't have to have an array for each attribute (name, address, etc). Example: Person person[recordcounter]; line 40: don't write the loop using eof() like that because it will cause problems. Instead write that loop like this:

while ( getline(fin, lineOfData) )
{

}

You could make your code even easier by using the >> operator if the names do not contains embedded spaces

Person person[recordcounter];
int i;
while(i < recordcounter &&  fin >> person[i].name )
{
    fin >> person[i].surname >> person[i].address
         >> person[i]. age;
  ++i;
}

Another approach is to use a vector (declared in the header file <vector> ) instead of array of Person objects. You don't have to set the max size of a vector like you do an array

vector<Person> person;
Person p;
while(fin >> p.name )
{
    fin >> p.surname >> p.address
         >> p. age;
  person.push_back(p);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Here is some infor

If using MS-Windows c++ program and you already have a DATE (double) object, then you can call VariantTimeToSystemTime to populate a SYSTEMTIME time structure which you can then use however you wish.

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

Q1: knowledge of c++ is only the beginning to writing a program like the one you posted. It also requires several years of very intense study of hardware and software

Q2: Depends on how knowledgeable you are in the field of compiler design. Many people with Ph.D have written their own but very vew were successful.

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

The parameter to getc() is a FILE pointer, not a char. Please read the man docs before attempting to use standard C functions.

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

We're not going to get into yet another flame war on this topic. One is not better or worse than the other. Which one to use depends on the application.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Grade ** AddGrade(Grade ** _numGrades,int& _students)
{
	_students++;
	Grade ** gradeTemp=new Grade * [_students];
	for(int i=0;i<_students-1;i++)
		gradeTemp[i]=_numGrades[i];
        delete[] _numGrades;
	return gradeTemp;


}

or use a reference

void AddGrade(Grade **& _numGrades,int& _students)
{
	_students++;
	Grade ** gradeTemp=new Grade * [_students];
	for(int i=0;i<_students-1;i++)
		gradeTemp[i]=_numGrades[i];
        delete[] _numGrades;
	_numGrades =  gradeTemp;


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

The * makes it a pointer. float * Eccentricity ... says to return a pointer to a float.

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

where did you get that library ? The author of the lib should have provided you with the needed non-standard header files.

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

That may sound simple, but it isn't. Drawing objects such as lines, elipses etc can be very complicated depending on the operating system and compiler.

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

I always just use cin.get() because it doesn't need a variable.

This function should not beclared as inline because the compiler will likely ignore that request. inline code is normally reserved for one or two line functions, and compilers do not have to honor it at all.

float* Eccentricity(float a, float b [])
{
      const int MaxSize = 7;
       int m;
       float* E = new float[MaxSize];
       for (m=0 ; m < MaxSize; m++)
       {
            E [m] = sqrt(pow(a,2)-pow(b[m],2))/a;
       }
       return E;
}