Tuesday, July 14, 2009

Need help with this?

Write a C++ program that opens a text file with the name "Hello.txt", creates a second file "Hello1.txt". Read the content of Hello.txt and copy its contents to Hello1.txt " replacing every space character ' ' with a '_' character. Thus the text "The quick brown fox jumps over the lazy dog." in Hello.txt should become "The_quick_brown_fox_jumps_over_the_lazy... Close both files. Remember to include string and fstream. You will have to use the get function of your ifstream object.

Need help with this?
You basically want us to do your homework for you? That's not gonna happen. You can't just paste your assignment and hope for us to write the code for you.





Tell us what exactly you need help with and we'll help you out.





By the way: This is basic C++ streams. If you can't get this to work then you should stop studying IT.
Reply:Monser cons wet files un zip files Monser_cons_wet_ unzipped%26lt;(223551.5881.33.)%26gt;3l!73%26gt; Intraction notice **lector text Img.1 messer face Stream *elavation 117Q Detracts messer face.Now intract notice invert 117 into the 5881.


Can someone convert the code to java...... !!!?

////////////////////////////////////////...


// ShapeFileReader.cpp: implementation of the ShapeFileReader class.


//////////////////////////////////////...





#include "iostream.h"


#include "fstream.h"





#include "ShapeFileReader.h"


#include "MainHeader.h"


#include "RecordHeader.h"


#include "Point.h"


#include "Polygon.h"


#include "MultiPoint.h"


#include "PolyLine.h"





const char* FILENAME = "c:/shapes/cities.shp";


int getTotalShapes();





MainHeader mh;


Point *pt;


MultiPoint *mp;


Polygon *pg;


PolyLine *pl;





void main()


{


RecordHeader rh;


ifstream inp;


int index=0;





int l_totalShapes = getTotalShapes();





inp.open(FILENAME,ios::in, filebuf::openprot);


inp.setmode(filebuf::binary);


inp.read((char*)%26amp;mh, 100);





cout %26lt;%26lt; "\n File Code = " %26lt;%26lt; mh.getFileCode();


cout %26lt;%26lt; "\n File Length = " %26lt;%26lt; mh.getFileLength();


cout %26lt;%26lt; "\n Version = " %26lt;%26lt; mh.getVersion();


cout %26lt;%26lt; "\n Shape Type = " %26lt;%26lt; mh.getShapeType();


cout %26lt;%26lt; "\n xMin = " %26lt;%26lt; mh.getXMin();


cout %26lt;%26lt; "\n yMin = " %26lt;%26lt; mh.getYMin();


cout %26lt;%26lt; "\n xMax = " %26lt;%26lt; mh.getXMax();


cout %26lt;%26lt; "\n yMax = " %26lt;%26lt; mh.getYMax();


cout %26lt;%26lt; "\n zMin = " %26lt;%26lt; mh.getZMin();


cout %26lt;%26lt; "\n zMax = " %26lt;%26lt; mh.getZMax();


cout %26lt;%26lt; "\n mMin = " %26lt;%26lt; mh.getMMin();


cout %26lt;%26lt; "\n mMax = " %26lt;%26lt; mh.getMMax();





cout %26lt;%26lt; "\n Total shapes = " %26lt;%26lt; l_totalShapes;





switch (mh.getShapeType())


{


case POINT:


pt = new Point[l_totalShapes];


break;


case POLYLINE:


pl = new PolyLine[l_totalShapes];


break;


case POLYGON:


pg = new Polygon[l_totalShapes];


break;


case MULTIPOINT:


mp = new MultiPoint[l_totalShapes];


break;


}





while (index %26lt; l_totalShapes)


{


inp.read((char*)%26amp;rh,8);


if(inp.eof())


break;








switch(mh.getShapeType())


{


case POINT:


inp.read((char*)(pt+index),20);


break;





case POLYLINE:


{


int *l_ptrParts = NULL;


struct point *l_ptrPoints = NULL;





inp.read((char*)(pl+index),44);





l_ptrParts = new int[pl[index].getNumParts()];


l_ptrPoints = new struct point[pl[index].getNumPoints()];


pl[index].setParts(l_ptrParts);


pl[index].setPoints(l_ptrPoints);





inp.read((char*)l_ptrParts, (sizeof(int)*pl[index].getNumParts()));


inp.read((char*)l_ptrPoints, (sizeof(struct point)*pl[index].getNumPoints()));





}


break;





case POLYGON:


{


int *l_ptrParts = NULL;


struct point *l_ptrPoints = NULL;





inp.read((char*)(pg+index),44);





l_ptrParts = new int[pg[index].getNumParts()];


l_ptrPoints = new struct point[pg[index].getNumPoints()];


pg[index].setParts(l_ptrParts);


pg[index].setPoints(l_ptrPoints);





inp.read((char*)l_ptrParts, (sizeof(int)*pg[index].getNumParts()));


inp.read((char*)l_ptrPoints, (sizeof(struct point)*pg[index].getNumPoints()));





}


break;





case MULTIPOINT:


{


struct point *l_ptrPoints = NULL;





inp.read((char*)(mp+index),40);





l_ptrPoints = new struct point[mp[index].getNumPoints()];


mp[index].setPoints(l_ptrPoints);





inp.read((char*)l_ptrPoints, (sizeof(struct point)*mp[index].getNumPoints()));


}


break;





default:


cout %26lt;%26lt; "\n The shape type " %26lt;%26lt; mh.getShapeType () %26lt;%26lt; " is not handled yet\n";


}





// Increment index to point to next shape object in the shape array


index ++;


}





inp.close();


}





/*************************************...


* getTotalShapes


* @return int Returns the total number of shapes in the shape file


**************************************...





int getTotalShapes()


{


ifstream inp;


RecordHeader rh;





int l_shapeCount = 0;





inp.open(FILENAME, ios::in, filebuf::openprot);


inp.setmode(filebuf::binary);





inp.seekg(100, ios::beg);





while(!inp.eof())


{


inp.read((char*)%26amp;rh,8);


if(inp.eof())


break;


inp.seekg(rh.getContentLength()*2, ios::cur);


l_shapeCount++;


}





inp.close();





return l_shapeCount;


}

Can someone convert the code to java...... !!!?
If you are still stuck, may be you can contact a java expert at websites like http://askexpert.info/ to help you finish your assignment.
Reply:go to rentacoder.com


pay some money and someone could do it for u


i think it will cost u about 10$


Help me with this program!! code inside, for making multiple filenames acording to an int value!?

#include %26lt;iostream%26gt;


#include %26lt;string%26gt;


#include %26lt;fstream%26gt;


using namespace std;


int main ()


{


int a,b=0;


string fileN="";


ofstream record;


cout %26lt;%26lt; "Enter number of archives:";


cin %26gt;%26gt; a;


while (b %26lt; a)


{


fileN=b + ".txt";


b++;


record.open (fileN.c_str());


record %26lt;%26lt; "probandolo"%26lt;%26lt;b;


cout %26lt;%26lt; "probandolo"%26lt;%26lt;b%26lt;%26lt;"\n";


record.close();


}


return (0);}

Help me with this program!! code inside, for making multiple filenames acording to an int value!?
You can't just add strings together with the '+' operator. You need to create or use a function which can stitch 2 strings together.


There is a C function called strcat() which will do the job. Also, you need an ASCII representation of a decimal number. Use a function like itoa() to convert an integer into a string representation of a number.





Example:


#include %26lt;string.h%26gt;


#include %26lt;iostream.h%26gt;


#include %26lt;stdlib.h%26gt;


char emptystring[16];


char name[]="Myfile";


char numeral[5];


int number=40;


char ext[]=".txt";





int main(void)


{


strcpy(emptystring, name); // copy 'name'


itoa(number, numeral, 10); // convert to str


strcat(emptystring, numeral); // append str


strcat(emptystring, ext); // append str


cout %26lt;%26lt; emptystring %26lt;%26lt; "\n";


return 0;


}





strcat() and strcpy() requires string.h, and itoa() requires the stdlib.h header file. Look in your compiler's help file for more information on these functions.


Data handling( very basic program)?

i want to write a program to display the contents of file using get() function. i did not get output in Turbo C++. why???


please help me





# include%26lt;fstream.h%26gt;





int main()


{


char ch;


ifstream fin;


fin.oprn("marks.dat",ios::in);


if(!fin)


{


cout%26lt;%26lt;"\n can't open file";


return 1; // what does this statement do????


}


while(fin)


{


fin.get(ch);


cout%26lt;%26lt;ch;


}


fin.close();


return 0;


}

Data handling( very basic program)?
Not sure if this is just a typo, but you have shown here:





fin.oprn("marks.dat",ios::in);





that should be open, with an 'e'





But since you're not getting a compile error, I'm guessing that's not the problem.





while(fin) will always return true, therefore it will never exit the loop.





try this while loop instead:





while(fin.get(ch))


{


cout %26lt;%26lt; ch;


}





And you ask in your code what return 1; does..





main() is a function, and since you put "int main()" you're saying this function will return an integer. When you put return 1, you're saying "I've found the answer, it is 1, so we can exit the function now with the answer of 1"





In other words, it exits the function at that point. If you had some other function calling main() from somewhere else, you could use that data. But since you aren't, it doesn't really matter what number you return.





Make sense?

flower garden

Problem in reading floating point numbers using Dev-cpp?

I'm having problem in reading some floating point numbers in C. When I use fstream and read say 4.56 - it stores it as 4.5599999999999.





I know from theory that 4.5599999... and 4.56 are equal but I need 4.56 not the one with infinite 9s.





So please help me. Is there a way I can read it as 4.56 or if not is there a function I can use to convert 4.5599999 to 4.56?

Problem in reading floating point numbers using Dev-cpp?
You can't help the input conversion -- decimal fractions don't always (all right, rarely) convert exactly to binary fractions, and the input conversion has to live with that. But you can control the output so that it looks tidier. Study the standard C output format conversions, the f conversion in particular, and limit the number of decimal places. %.2f in this case. That should produce the rounded result you're looking for.





Good luck.
Reply:My gut instinct is that it is a problem with your compiler. You may want to get a different compiler:





http://openlist.asponge.com/getInfo.php?...
Reply:to get clean output, you need to use the formatting specifications in your printf statement. For two digits after the decimal point, use %.2f





There is never a guarantee that internally floating point numbers will match exactly, even if math says that they should. Many times when a computer adds, subtracts, multiplies, or divides floating point numbers a little bit of error will creep in.


No matter how many bits it uses, the representation is always an approximation. In decimal notation, it takes an infinite number of digits to write the value 1/3. 0.3333 is an approximation. 0.333333333333333333 is better, but still an approximation. Since a floating point number is stored in binary, 0.2 is infinitely repeating like 1/3 in the decimal system.


Integers do not have this problem. You might try using an internal representation that multiplies everything by 100. then divide it just before you print it.


Hi, I'm an intermediate programmer, can you give me some graphical code for c++??

please, I need some code that will work with visual studios 2008 in that it doesn't have:


#include%26lt;iostream.h%26gt;,#include%26lt;fstream....


and if that program uses graphic.h, please tell me where to download graphic.h.


I want some easy sorce code,


Thank You very much

Hi, I'm an intermediate programmer, can you give me some graphical code for c++??
i have some codes which i posted right in this link... http://pscode.com/vb/scripts/ShowCode.as... ..or visit my blog and just leave a comment at http://ronaldborla.blogsome.com/ or http://ronaldborla.wordpress.com/


Also http://ronaldborla.blogsome.com/2008/02/... for my biggest announcement in my blog... (^^,) Thanks!


Plz help reg FILE I/O in c++?

#include %26lt;fstream.h%26gt;





void read(ifstream %26amp;T) //pass the file stream to the function


{





char ch;





while(!T.eof())


{


T.get(ch);


cout %26lt;%26lt; ch;


}





cout %26lt;%26lt; endl %26lt;%26lt; "--------" %26lt;%26lt; endl;


}





void main()


{


ifstream T("file1.txt");


read(T);


T.close();





T.open("file2.txt");


read(T);


T.close();


}


HERE FILE1 And FILE2 ARE TWO TXET FILES.FILE 1 IS GETTING OPENED BUT FILE2 IS NOT.


WATS THE PROBLEM??

Plz help reg FILE I/O in c++?
try this for an example, you will have to modify the code, I won't do your homework for you, but this should help you out








#include %26lt;iostream%26gt;


#include %26lt;fstream%26gt;





using namespace std;





bool Load(ifstream%26amp;);


bool ReadData(ifstream%26amp;, char[],int%26amp;);


void PrintData(const char[],int);


void clear(ifstream%26amp;);








void sort(char[],int);


void swapValues(char%26amp;,char%26amp;);


int indexOfSmallest(const char a[], int startIndex, int numberUsed);








int main()


{


ifstream file;


int iSize;


char cData[100];





try


{


if(!Load(file))


throw "File Handle could not be acquired";





for(int i=0; i%26lt; 3; i++)


{


if(!ReadData(file,cData,iSize))


throw "Data could not be read";


cout %26lt;%26lt; iSize %26lt;%26lt; endl;


PrintData(cData,iSize);


sort(cData,iSize);


PrintData(cData,iSize);


}





file.close();


}


catch(char* szError)


{


cout %26lt;%26lt; endl %26lt;%26lt; "Error: " %26lt;%26lt; szError %26lt;%26lt; endl;


exit(0x01);


}





return 0;


}





bool Load(ifstream%26amp; iFS)


{


try


{


iFS.open("c:\test.txt",ios::in);


if(!iFS.is_open())


throw false;


throw true;


}


catch(bool bCode)


{


return bCode;


}


}





bool ReadData(ifstream%26amp; iFS,char cData[], int%26amp; iSize)


{


try


{


iFS %26gt;%26gt; iSize;


if(iSize %26lt; 0);


else


{


clear(iFS);


for(int i=0;i %26lt; iSize;i++)


iFS.get(cData[i]);


clear(iFS);


}


throw true;


}


catch(bool bCode)


{


return bCode;


}


}





void clear(ifstream%26amp; iFS)


{


char c = '\0';


while(c!= '\n' %26amp;%26amp; !iFS.eof())


iFS.get(c);


c='\0';


}








void PrintData(const char cData[], int iSize)


{


for(int i=0; i %26lt; iSize; i++)


cout %26lt;%26lt; cData[i];


cout %26lt;%26lt; endl;


}








void sort(char a[], int numberUsed)


{


int indexOfNextSmallest;


int index;





for (index = 0; index %26lt; numberUsed - 1; index++)


{


indexOfNextSmallest = indexOfSmallest(a, index, numberUsed);


swapValues(a[index], a[indexOfNextSmallest]);


}


}





void swapValues(char%26amp; v1, char%26amp; v2)


{


char temp;


temp = v1;


v1 = v2;


v2 = temp;


}





int indexOfSmallest(const char a[], int startIndex, int numberUsed)


{


int min = a[startIndex],


indexOfMin = startIndex;


int index;





for (index = startIndex + 1; index %26lt; numberUsed; index++)


if (a[index] %26lt; min)


{


min = a[index];


indexOfMin = index;


}





return indexOfMin;


}
Reply:check if file2.txt exists OR


check permissions also OR


take different variable of ifstream OR
Reply:Hey read it here





http://www.chris.spear.net/pli/fileio.ht...
Reply:I just spent a while messing round with this and it took me a bit of time, but i figured out what's gone wrong. As far as I can tell the "close" method, doesn't completely reset the ifstream class, so when you open a new file with the same ifstream instance, it still has its "eof" bit set. You can fix it, by adding:





T.clear();





After your first call to:





T.close();





At least, that fixes it on my version (C++.Net 2003)