|
||
|
|
#1 (permalink) |
|
Forum Expert
Join Date: Oct 2002
Location: Iowa, USA
Age: 38
Posts: 395
|
I'm writing a visual C++ .Net Console application, and I have it almost finished. The object is to create arrays and populate them with stock symbols, amount of shares for each stock, purchase price of each share, and to generate a random price for the current price. Then I am to calculate the total purchase value of each stock, then the current value of each stock. Then I am to output each stock symbol, the purchase value of each stock, the current value of each stock, and the difference (profit/loss) of each stock to a MessageBox. The problem enters when I try to build a string using a build string method that returns a concatenated string (concatenated within a for loop local to the BuildOutputString method), and then try to assign the returned string to a string variable local to the main method.
Code:
// Stocks.cpp : main project file.
#include "stdafx.h"
#include <Windows.h>
#include <stdio.h>
#include <string>
#using <System.dll>
#using <System.Windows.forms.dll>
using namespace System;
using namespace System::Windows::Forms;
const int NUMSTOCKS = 3;
//void GetValue( array<int ^> ^gcnew[], array<double ^> ^gcnew[] );
array<String ^>^ AddSymbol();
array<int ^>^ AddShares();
array<double ^>^ AddPurchasePrice();
array<double ^>^ GetCurrentPrice();
array<double ^>^ GetPurchaseValue( array<int ^> ^shares, array<double ^> ^prices );
array<double ^>^ GetCurrentValue( array<int ^> ^shares, array<double ^> ^prices );
String ^BuildOutputString( array<String ^> ^symbols, array<double ^> ^pValues, array<double ^> ^cValues );
int main( array<System::String ^> ^args )
{
array<String ^> ^ stockSymbols = AddSymbol();
array<int ^> ^ stockShares = AddShares();
array<double ^> ^ purchasePrice = AddPurchasePrice();
array<double ^> ^ currentPrice = GetCurrentPrice();
array<double ^> ^ purchaseValues = GetPurchaseValue( stockShares, purchasePrice );
array<double ^> ^ currentValues = GetCurrentValue( stockShares, GetCurrentPrice() );
String ^output = BuildOutputString( stockSymbols, purchaseValues, currentValues );
//String ^str = &stockSymbols[i];
//MessageBox( NULL, &stockSymbols[i], "Stocks", MB_SETFOREGROUND );
MessageBox::Show( output,
"Stocks",
MessageBoxButtons::OK,
MessageBoxIcon::Information );
return 0;
}
array<String ^>^ AddSymbol()
{
array<String ^> ^localArray = gcnew array<String ^>( NUMSTOCKS );
localArray[0] = "KWK", localArray[1] = "SFY", localArray[2] = "GM";
return localArray;
}
array<int ^>^ AddShares()
{
array<int^ > ^localArray = gcnew array<int ^>( NUMSTOCKS );
localArray[0] = 10, localArray[1] = 10, localArray[2] = 10;
return localArray;
}
array<double ^>^ AddPurchasePrice()
{
array<double ^> ^localArray = gcnew array<double ^>( NUMSTOCKS );
localArray[0] = 36.67, localArray[1] = 43.09, localArray[2] = 31.55;
return localArray;
}
array<double ^>^ GetCurrentPrice()
{
Random ^randomDouble = gcnew Random();
array<double ^> ^localArray = gcnew array<double ^>( NUMSTOCKS );
for ( int i = 0; i < localArray->Length; ++i )
{
localArray[i] = randomDouble->NextDouble() * 100.00f;
}
return localArray;
}
array<double ^>^ GetPurchaseValue( array<int ^> ^shares, array<double ^> ^prices )
{
array<double ^> ^localArray = gcnew array<double ^>( shares->Length );
for ( int i = 0; i < shares->Length; ++i )
{
localArray[i] = ( ( Convert::ToDouble( shares[i] ) ) * ( *prices[i] ) );
}
return localArray;
}
array<double ^>^ GetCurrentValue( array<int ^> ^shares, array<double ^> ^prices )
{
array<double ^> ^localArray = gcnew array<double ^>( shares->Length );
for ( int i = 0; i < shares->Length; ++i )
{
localArray[i] = ( ( Convert::ToDouble( shares[i] ) ) * ( *prices[i] ) );
}
return localArray;
}
String ^BuildStringOutput( array<String ^> ^symbols, array<double ^> ^pValues, array<double ^> ^cValues )
{
String ^localString;
for ( int i = 0; i < symbols->Length; ++i )
{
double change = ( *pValues[i] - *cValues[i] );
localString = String::Concat( localString,
symbols[i],
"/n", pValues[i]->ToString(),
"/n", cValues[i]->ToString(),
"/n/nChange In Value: ", Convert::ToString( change ) );
}
return localString;
}
Stocks.obj : error LNK2028: unresolved token (0A000299) "class System::String ^ __clrcall BuildOutputString(cli::array<class System::String ^ >^,cli::array<class System: ouble ^ >^,cli::array<class System: ouble ^ >^)" (?BuildOutputString@@$$FYMP$AAVString@System@@P$01 AP$AAV12@P$01AP$AAVDouble@2@1@Z) referenced in function "int __clrcall main(cli::array<class System::String ^ >^)" (?main@@$$HYMHP$01AP$AAVString@System@@@Z)Stocks.obj : error LNK2019: unresolved external symbol "class System::String ^ __clrcall BuildOutputString(cli::array<class System::String ^ >^,cli::array<class System: ouble ^ >^,cli::array<class System: ouble ^ >^)" (?BuildOutputString@@$$FYMP$AAVString@System@@P$01 AP$AAV12@P$01AP$AAVDouble@2@1@Z) referenced in function "int __clrcall main(cli::array<class System::String ^ >^)" (?main@@$$HYMHP$01AP$AAVString@System@@@Z)Any help is greatly appreciated. Btw, I'm using VS2k5 with WinXP Last edited by Axle; 01-21-2007 at 05:22 AM. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|