>>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.
>>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.
>>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
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");
Oh yea, I misread his post about VC++.
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;
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
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.
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));
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));
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
}
}
}
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 ?
It probably means you are online and the others are not online.
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.
>>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.
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;
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?
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.
So Can You help me to do that ?
No, sorry, its outside my expertise.
>>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.
>>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.
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);
}
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.
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.
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
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;
}
You have not posted any code yet, so can not help you.
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);
}
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.
>>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.
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.
}
>>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.
>>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.
That one confuses a lot of people -- just remember that on = is for assignment and two == is for asking a question.
>>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;
}
line 49: if (size = 1)
You are using the assignment operator not the boolean operator if (size == 1)
you could use pipes. see man pages for popen()
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;
}
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
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.
#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.
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);
}
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.
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.
The parameter to getc() is a FILE pointer, not a char. Please read the man docs before attempting to use standard C functions.
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.
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;
}
The * makes it a pointer. float * Eccentricity ...
says to return a pointer to a float.
where did you get that library ? The author of the lib should have provided you with the needed non-standard header files.
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.
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;
}