Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Arrays?

Reply
Thread Tools

Arrays?

 
 
Jim Langston
Guest
Posts: n/a
 
      05-28-2008
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Hi,
>
> I'm currently writing a C++ program for an assignment.
>
> "Create a C++ program to manage 10 bank accounts... "
>
> To include;
>
> "An appropriate type definition to store the name, account number and
> balance of a bank account
> An array to record the details of the 10 bank accounts
> Functions/procedures to update/interrogate the bank accounts array."
>
> I have all the code for a single bank account where you can depost/
> withdaw and vew balance, but, Iím not quite sure about arrays and how
> to access them, so my idea was this:


[SNIP]

Following the rest of this thread it seems that you don't have a good
understanding what "appropriate type definition" or how to use it in an
array. Since this is homework, I can't/won't give you the answer, but look
at this:

#include <string>

struct Foo
{
std::string Name;
int Quantity;
float Value;
};

int main()
{
Foo Data[10];
Data[0].Name = "Screw";
Data[0].Quantity = 10;
Data[0].Value = 12.3;

Data[1].Name = "Bolt";
Data[1].Quantity = 20;
Data[1].Value = 3.1415926;
}

That is basically giving you everything right there as far as your data
goes. I probably gave you more information that I should have, but you
seemed rather lost.

--
Jim Langston
(E-Mail Removed)


 
Reply With Quote
 
 
 
 
gbvk@hotmail.co.uk
Guest
Posts: n/a
 
      05-28-2008
Thank you kwikius, but i seem to get bombarded with error messages
with this:

#include <iostream.h>
#include <stdlib.h>
#include <string>

struct Account{
std::string fName;
std::string lName;
float balance;
};

int main ()
{


Account Accounts [] =
{
{"Joe","Smithers",250.0},
{"Anesa","Williams",-500.0},
{"Sarah","Jacobs",1204.0},
{"Daniel","Lewis",-600.0},
{"Sabrina","Le Rue",789.0},
{"Gordon","Platt",-2987.0},
{"Tom","Jones",8721.0},
{"David","Brown",-20.0},
{"Lucy","Thomas",-3988.0},
{"Jenna","Allen",10000.0}
};



std::cout << "Please enter your account number : ";
//maybe start with invalid account number
int AccountNumber=-1;
std::cin >> AccountNumber ;
std::cout << "\n\n";

************************************************** **************************
Info :Compiling C:\Users\G\Desktop\SoftDev1Ass2\softdev1ass2.cpp
Warn : string.h(549,3):Functions containing for are not expanded
inline
Warn : string.h(557,3):Functions containing while are not expanded
inline
Warn : string.h(563,3):Functions containing for are not expanded
inline
Warn : string.h(575,3):Functions containing for are not expanded
inline
Warn : string.h(742,96):Conversion may lose significant digits
Warn : string.h(768,96):Conversion may lose significant digits
Warn : iterator.h(570,72):Conversion may lose significant digits
Warn : iterator.h(570,72):Conversion may lose significant digits
Warn : iterator.h(529,72):Conversion may lose significant digits
Warn : iterator.h(530,72):Conversion may lose significant digits
Warn : iterator.h(531,72):Conversion may lose significant digits
Warn : iterator.h(532,72):Conversion may lose significant digits
Warn : iterator.h(529,72):Conversion may lose significant digits
Warn : iterator.h(530,72):Conversion may lose significant digits
Warn : iterator.h(531,72):Conversion may lose significant digits
Warn : iterator.h(532,72):Conversion may lose significant digits
Error: softdev1ass2.cpp(18,9):Cannot convert 'char *' to 'Account'
Error: softdev1ass2.cpp(18,10):} expected
Error: softdev1ass2.cpp(18,26)eclaration syntax error
Error: softdev1ass2.cpp(18,26)eclaration missing ;
Warn : softdev1ass2.cpp(18,26):'account' is assigned a value that is
never used
Warn : softdev1ass2.cpp(18,26):'choice' is declared but never used
Warn : softdev1ass2.cpp(18,26):'amount' is declared but never used
Error: softdev1ass2.cpp(18,27)eclaration terminated incorrectly
Error: softdev1ass2.cpp(28,3):Unexpected }
Error: softdev1ass2.cpp(32,10):'cout' is not a member of 'std'
Error: softdev1ass2.cpp(32,13)eclaration terminated incorrectly
Error: softdev1ass2.cpp(35,13):'cin' is not a member of 'std'
Error: softdev1ass2.cpp(35,16)eclaration terminated incorrectly
Error: softdev1ass2.cpp(36,14):'cout' is not a member of 'std'
Error: softdev1ass2.cpp(36,17)eclaration terminated incorrectly
Error: softdev1ass2.cpp(100,2):Unexpected }

>...but you seemed rather lost.


this is a huge under-statement, everytime i get a response (which has
been A1 from everyone) it just throws spanners into the works


 
Reply With Quote
 
 
 
 
kwikius
Guest
Posts: n/a
 
      05-28-2008

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Thank you kwikius, but i seem to get bombarded with error messages
> with this:


OK. Well I think the problem is that you have a very old compiler. In that
case you have to start at the bottom and see what it will find acceptable.

Start off with code that AFAIK is basically C code: I've removed std::string
and also used an alternative way to initialise.
BTW Generally when debugging you should only change one thing at a time, but
I changed 2

struct Account{
const char* fName; // mod
const char* lName; //mod
float balance;
};

int main()
{
// one way to create and fill array of accounts
Account Accounts[] =
{ // mods...
"John","Smith",1000.0,
"Mary","Jones",2000.0,
"Bill","Simpkins",20000.0
};
}

See if the compiler is happy with that. BTW just ignore anything that says
WARN. You only want to look at ERROR... but only at this "go or nogo" stage.

regards
Andy Little

 
Reply With Quote
 
gbvk@hotmail.co.uk
Guest
Posts: n/a
 
      05-28-2008
Info :Compiling C:\Users\G\Desktop\SoftDev1Ass2\softdev1ass2.cpp

Error: (1,1):Undefined symbol std::rwse_StringIndexOutOfRange in
module softdev1ass2.cpp
Error: (1,1):Undefined symbol std::rwse_PosBeyondEndOfString in
module softdev1ass2.cpp
Error: (1,1):Undefined symbol std::nullref in module softdev1ass2.cpp
Error: (1,1):Undefined symbol std::rwse_InvalidSizeParam in module
softdev1ass2.cpp
Error: (1,1):Undefined symbol std::rwse_ResultLenInvalid in module
softdev1ass2.cpp
Error: (1,1):Undefined symbol std::rwse_UnexpectedNullPtr in module
softdev1ass2.cpp
Error: (1,1):Undefined symbol std::__rw_stdexcept_NoNamedException in
module softdev1ass2.cpp

*pulls hair out*
 
Reply With Quote
 
gbvk@hotmail.co.uk
Guest
Posts: n/a
 
      05-28-2008
YES!

it seems #include <string> was messing it up
 
Reply With Quote
 
kwikius
Guest
Posts: n/a
 
      05-28-2008

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Info :Compiling C:\Users\G\Desktop\SoftDev1Ass2\softdev1ass2.cpp
>
> Error: (1,1):Undefined symbol std::rwse_StringIndexOutOfRange in
> module softdev1ass2.cpp
> Error: (1,1):Undefined symbol std::rwse_PosBeyondEndOfString in
> module softdev1ass2.cpp
> Error: (1,1):Undefined symbol std::nullref in module softdev1ass2.cpp
> Error: (1,1):Undefined symbol std::rwse_InvalidSizeParam in module
> softdev1ass2.cpp
> Error: (1,1):Undefined symbol std::rwse_ResultLenInvalid in module
> softdev1ass2.cpp
> Error: (1,1):Undefined symbol std::rwse_UnexpectedNullPtr in module
> softdev1ass2.cpp
> Error: (1,1):Undefined symbol std::__rw_stdexcept_NoNamedException in
> module softdev1ass2.cpp
>
> *pulls hair out*


which compiler is this... Borland or Microsoft VC++?

regards
Andy Little

 
Reply With Quote
 
gbvk@hotmail.co.uk
Guest
Posts: n/a
 
      05-28-2008
> which compiler is this... Borland or Microsoft VC++?

Borland 5.02 (1997) :/

 
Reply With Quote
 
Jim Langston
Guest
Posts: n/a
 
      05-28-2008
(E-Mail Removed) wrote:
> Thank you kwikius, but i seem to get bombarded with error messages
> with this:
>
> #include <iostream.h>


#include <iostream>

> #include <stdlib.h>


#include <cstdlib>

> #include <string>
>
> struct Account{
> std::string fName;
> std::string lName;
> float balance;
> };
>
> int main ()
> {
>
>
> Account Accounts [] =
> {
> {"Joe","Smithers",250.0},
> {"Anesa","Williams",-500.0},
> {"Sarah","Jacobs",1204.0},
> {"Daniel","Lewis",-600.0},
> {"Sabrina","Le Rue",789.0},
> {"Gordon","Platt",-2987.0},
> {"Tom","Jones",8721.0},
> {"David","Brown",-20.0},
> {"Lucy","Thomas",-3988.0},
> {"Jenna","Allen",10000.0}
> };
>
>
>
> std::cout << "Please enter your account number : ";
> //maybe start with invalid account number
> int AccountNumber=-1;
> std::cin >> AccountNumber ;
> std::cout << "\n\n";
>
> ************************************************** **************************
> Info :Compiling C:\Users\G\Desktop\SoftDev1Ass2\softdev1ass2.cpp
> Warn : string.h(549,3):Functions containing for are not expanded
> inline
> Warn : string.h(557,3):Functions containing while are not expanded
> inline
> Warn : string.h(563,3):Functions containing for are not expanded
> inline
> Warn : string.h(575,3):Functions containing for are not expanded
> inline
> Warn : string.h(742,96):Conversion may lose significant digits
> Warn : string.h(768,96):Conversion may lose significant digits
> Warn : iterator.h(570,72):Conversion may lose significant digits
> Warn : iterator.h(570,72):Conversion may lose significant digits
> Warn : iterator.h(529,72):Conversion may lose significant digits
> Warn : iterator.h(530,72):Conversion may lose significant digits
> Warn : iterator.h(531,72):Conversion may lose significant digits
> Warn : iterator.h(532,72):Conversion may lose significant digits
> Warn : iterator.h(529,72):Conversion may lose significant digits
> Warn : iterator.h(530,72):Conversion may lose significant digits
> Warn : iterator.h(531,72):Conversion may lose significant digits
> Warn : iterator.h(532,72):Conversion may lose significant digits
> Error: softdev1ass2.cpp(18,9):Cannot convert 'char *' to 'Account'
> Error: softdev1ass2.cpp(18,10):} expected
> Error: softdev1ass2.cpp(18,26)eclaration syntax error
> Error: softdev1ass2.cpp(18,26)eclaration missing ;
> Warn : softdev1ass2.cpp(18,26):'account' is assigned a value that is
> never used
> Warn : softdev1ass2.cpp(18,26):'choice' is declared but never used
> Warn : softdev1ass2.cpp(18,26):'amount' is declared but never used
> Error: softdev1ass2.cpp(18,27)eclaration terminated incorrectly
> Error: softdev1ass2.cpp(28,3):Unexpected }
> Error: softdev1ass2.cpp(32,10):'cout' is not a member of 'std'
> Error: softdev1ass2.cpp(32,13)eclaration terminated incorrectly
> Error: softdev1ass2.cpp(35,13):'cin' is not a member of 'std'
> Error: softdev1ass2.cpp(35,16)eclaration terminated incorrectly
> Error: softdev1ass2.cpp(36,14):'cout' is not a member of 'std'
> Error: softdev1ass2.cpp(36,17)eclaration terminated incorrectly
> Error: softdev1ass2.cpp(100,2):Unexpected }
>
>> ...but you seemed rather lost.

>
> this is a huge under-statement, everytime i get a response (which has
> been A1 from everyone) it just throws spanners into the works




--
Jim Langston
(E-Mail Removed)


 
Reply With Quote
 
Default User
Guest
Posts: n/a
 
      05-28-2008
(E-Mail Removed) wrote:

> YES!
>
> it seems #include <string> was messing it up


That seems highly unlikely, as that is the header required for
std::string.




Brian
 
Reply With Quote
 
kwikius
Guest
Posts: n/a
 
      05-28-2008

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>> which compiler is this... Borland or Microsoft VC++?

>
> Borland 5.02 (1997) :/


Fascinating... (I've never used Borland. I was warned off it many years ago
by an old pro ... )

If you could recompile and also show us the *exact, full* source code you
are compiling and include a couple of line numbers in comments on the very
lines they refer to, ( before you compile !!! ) in the source code so we
can see where it says the errors are..

regards
Andy Little


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments