 |
 |
String.h
|
 |
|
 |
|
Banned
Join Date: Mar 2000
Location: Sherman Oaks, CA USA
Status:
Offline
|
|
Okay, so my C++ book has an assignment in it that requires the library <lvp\string.h> So far, I have learnedd that <lvp\string.h> doesn't exist in any form of that type, but it does live on in string.h. So, I got that put into my assignment, but now, it still can't make out the class String in the beginning of the app. The rest of it is fine.
Anything that has // in front of it is there because when I bring it to class to compile it there, I need those, but for Project Builder, they remain off.
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">/* Vote Analysis program. Names and votes for two candidates are entered and the percentages and votes are displayed in a table.
Chris Hanks 7-29-02 */
#include <iostream.h>
//#include <conio.h>
#include <strings.h>
int main()
{
//clrscr();
cout << "-- Vote Analysis Program --" << endl << endl;
String Candidate1, Candidate2;
cout << "Enter name of first candidate: ";
cin >> Candidate1;
cout << "Enter name of second candidate: ";
cin >> Candidate2;
long Votes1, Votes2;
cout << "Enter votes for " << Candidate1 << ": ";
cin >> Votes1;
cout << "Enter votes for " << Candidate2 << ": ";
cin >> Votes2;
cout << endl;
long VotesTotal = Votes1 + Votes2;
double Percent1 = 100 * double (Votes1)/VotesTotal;
double Percent2 = 100 * double (Votes2)/VotesTotal;
const int ColWidth = 10; // Width of columns in table
cout.setf(ios::fixed);
cout.precision(2);
// Output column headings
cout.setf(ios::left);
cout.width(ColWidth); cout << "Candidate";
cout.setf(ios::right);
cout.width(ColWidth); cout << "Votes";
cout.width(ColWidth); cout << "Percent" << endl;
// Output election results
cout.setf(ios::left);
cout.width(ColWidth); cout << Candidate1;
cout.setf(ios::right);
cout.width(ColWidth); cout << Votes1;
cout.width(ColWidth); cout << Percent1 << endl;
cout.setf(ios::left);
cout.width(ColWidth); cout << Candidate2;
cout.setf(ios::right);
cout.width(ColWidth); cout << Votes2;
cout.width(ColWidth); cout << Percent2 << endl;
cout.width(ColWidth); cout << "TOTAL: ";
cout.width(ColWidth); cout << VotesTotal << endl;
return(0);
} </pre><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">So what class should be used in place of String? Is there another header file out there that can do a better job?
HELP!
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Jul 2002
Location: Leiden, Netherlands
Status:
Offline
|
|
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">Originally posted by The Dude:
<strong>Okay, so my C++ book has an assignment in it that requires the library <lvp\string.h> So far, I have learnedd that <lvp\string.h> doesn't exist in any form of that type, but it does live on in string.h. So, I got that put into my assignment, but now, it still can't make out the class String in the beginning of the app. The rest of it is fine.
Anything that has // in front of it is there because when I bring it to class to compile it there, I need those, but for Project Builder, they remain off.
So what class should be used in place of String? Is there another header file out there that can do a better job?
</strong></font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">Why don't you write a String Object yourself?
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: May 2002
Location: The Swamp
Status:
Offline
|
|
Hello,
I think your include statement for the string class is incorrect, it should be
#include <string.h>
It sounds to me that you're using a Lawrenceville Press Book, I'm guessing "An Intro to C++"? I think I bought that book a while back when I was taking an AP course. If it is that book, there should be a CD that has those particular classes on it.
|
|
12" PB 1 GHz Combo, 60GB, 512MB, AE
40GB iPod
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2000
Location: Tempe, AZ
Status:
Offline
|
|
Use #include <string> (without a .h) and the class name is 'string'. The clrscrn thing is not standard C++.
|
Geekspiff - generating spiffdiddlee software since before you began paying attention.
|
| |
|
|
|
 |
|
 |
|
Banned
Join Date: Mar 2000
Location: Sherman Oaks, CA USA
Status:
Offline
|
|
Yes, it is Lawrenceville book, "A Guide to Programming in C++" or something along those lines. I didn't get a CD with the book, instead we're using Borland Turbo C++ v3.
I'm entirely aware that clrscr isn't a standard C++ class, that's why I have it turned off. That way, I can bring it back the lab.
Bell rang. Bye.
|
|
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Oct 2000
Location: Portland, OR USA
Status:
Offline
|
|
The assignment is asking you to use their String class, whereas the '#include <string>' is using the standard C++ string class. This could be a major problem as the interfaces to the classes may differ in important ways. It looks like the String class should come on a CD.
BTW, clrscr() is in 'conio.h' and is a DOS thing, IIRC.
|
|
|
| |
|
|
|
 |
|
 |
|
Banned
Join Date: Mar 2000
Location: Sherman Oaks, CA USA
Status:
Offline
|
|
Gator, smeger, Lord, dude...I like love you guys!!
Works like a charm!!! THANK YOU!!! 
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|