-1

I think there is something simple wrong with my header file where I have the nested class declared, if not that, I must had missed a step in setting up the nested class. I only get an error in main towards the bottom when I try to declare an instance of it (printpersonal).

error in main isn't till bottom. Everything above is good.

#include <iostream>
#include <fstream>
#include <sstream>
#include <cstdlib>
#include <stdio.h>
#include "Stocks.h"
using namespace std;

int main(){
cout<<"Create account username: "<<endl;
string name;
cin>>name;
cout<<"Create password: "<<endl;
string password;
cin>>password;
accountinfo personal;
personal.name=name;
personal.password=password;
ifstream data;
int counter=0;

dividends div;

data.open("Netflix.csv");

string word;
Stocks annualdata;//class
//Date, Open, High, Low, Close, Volume, Adjusted Close
ticker info;//struct
int lineindex=0;
while(getline(data, word, '\n')){

        stringstream ss;
        int wordindex=0;
        if(lineindex>0){
        ss<<word;

        while(getline(ss,word,',')){
            if(wordindex==0){//10 lines of data total
                info.date=word;
                }
             if(wordindex==1){//10 lines of data total
                info.open=addDouble(word);
                }
             if(wordindex==2){//10 lines of data total
                info.high=addDouble(word);
                }
             if(wordindex==3){//10 lines of data total
                info.low=addDouble(word);
                }
             if(wordindex==4){//10 lines of data total
                info.close=addDouble(word);
                }
             if(wordindex==5){//10 lines of data total
                info.volume=addInt(word);
                }
             if(wordindex==6){//10 lines of data total
                info.adjustedclose=addDouble(word);
                }
        wordindex++;
            }
        }
    annualdata.addDay(info);
    lineindex++;
}
annualdata.maxprofit();
annualdata.oneyear();
annualdata.sixmonths();
annualdata.maxloss();
double money;
double divs=div.annualdiv;
if(data=="Apple.csv"){
    money=div.addDiv(divs);
    div.oneyear();

    }
Stocks::Account printpersonal;
printpersonal.printaccountinfo(personal);


return 0;
}

Header File

#ifndef STOCKS_H
#define STOCKS_H
#include <string>
using namespace std;

 //Date, Open, High, Low, Close, Volume, Adjusted Close
 struct ticker{
 std::string date;
 double open;
 double high;
 double low;
 double close;
 int volume;
 double adjustedclose;
 };
 struct accountinfo{
std::string name;
std::string password;
};

class Stocks//base class
{
public:
    Stocks();//Constructor1 method7
    Stocks(std::string, double, double, double, double, int, double);
    void addDay(ticker);//method1
    void maxprofit();//method2
    void oneyear();//method3
    void sixmonths();//method4
    void maxloss();//method5


    int index=253;
    double money=1000;
    int shares;
    ticker annual[254];

    class Account {//nested class

    public:
    Account();//method11
    void printaccountinfo(accountinfo info){//method12
    }
};


protected:
private:

};
class dividends:public Stocks{//derived class

public:
    dividends(){};//constructor2 method8
    double annualdiv=(.57+.57+.52+.52);

 double addDiv(double annualdiv);//method6
 void oneyear();//overloaded method method9


 };

#endif // STOCKS_H

Source File

#include "Stocks.h"
#include <iostream>

using namespace std;

 Stocks::Stocks(string d, double o, double h, double l, double c, int   v, double ac)
 {
 string date=d;
 double open=o;
double high=h;
double low=l;
int volume=v;
 double adjustedclose=ac;//Date, Open, High, Low, Close, Volume,  Adjusted         Close
}



Stocks::Stocks()
{
//dtor
}
void Stocks::addDay(ticker data){
annual[index].date=data.date;
annual[index].open=data.open;
annual[index].high=data.high;
annual[index].low=data.low;
annual[index].close=data.close;
annual[index].volume=data.volume;
annual[index].adjustedclose=data.adjustedclose;

index--;//most recent data is inserted at bottom (Chronologically)
}
void Stocks::maxprofit(){
int index=0;
int x=1;
while(index<254){
if(annual[index].open<annual[index].close){
    shares=money/annual[index].open;
    money+=shares*(annual[index].close-annual[index].open);
    while(x<254){//when you decide to sell
    if(annual[index].close>annual[index+x].open){
        index=x;
        x=254;
        }
    else{x++;}
    }
    index++;
    }
    else{index++;}

}
cout<<"Portfolio value using the optimal trading strategy after 1 year: $"<<money<<endl;
}
void Stocks::maxloss(){
int index=0;
int x=1;
while(index<254){
if(annual[index].open>annual[index].close){
    shares=money/annual[index].open;
    money+=shares*(annual[index].close-annual[index].open);
    while(x<254){//when you decide to sell
    if(annual[index].close>annual[index+x].open){
        index=x;
        x=254;
        }
    else{x++;}
        }
    index++;
    }
    else{index++;}
}
 cout<<"Portfolio value using the worst trading strategy after 1 year: $"<<money<<endl;
}
void Stocks::oneyear(){
money=1000;
shares=money/annual[0].open;
money+=(shares*annual[0].open-shares*annual[254].close);
//Color(12,"\N Hey! I'm in color!")

cout<<"portfolio value after 1 year: $"<<money<<endl;
}

void Stocks::sixmonths(){
money=1000;
shares=money/annual[0].open;
money+=(shares*annual[0].open-shares*annual[127].close);
//Color(12,"\N Hey! I'm in color!")

cout<<"portfolio value after 6 months: $"<<money<<endl;
}
double dividends::addDiv(double annualdiv){
money=1000;
money=money+annualdiv;
return money;
}
void dividends::oneyear(){
money=1000;
money+=(shares*annual[0].open-shares*annual[254].close);

shares=money/annual[0].open;
cout<<"Apple portfolio amount including dividends: $"        <<money+annualdiv<<endl;

}
grilam14
  • 81
  • 1
  • 9
  • 1
    Lot of code with chaotic indentation. A disincentive to debug. – user4581301 Oct 28 '16 at 05:03
  • Too many bugs in code to be able to provide a full answer. Problem in title is clear, though: You did not implement `Stocks::Account::Account()`. – user4581301 Oct 28 '16 at 05:30
  • possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – user4581301 Oct 28 '16 at 05:32
  • that is likely it, i'll see – grilam14 Oct 28 '16 at 05:34
  • Fixing that may open up a torrent of other errors. For example, `if (data == "Apple.csv")` Why compare a string with a file stream? Compiler's not going to like that. – user4581301 Oct 28 '16 at 05:36
  • That's just a placeholder for something when I get to that point. I may just ditch nested methods because this is not working. – grilam14 Oct 28 '16 at 05:40

1 Answers1

0

I noticed you're missing a ; after your Account class. Not sure if that's the cause of the error but I think that needs to be fixed.

grigor
  • 1,584
  • 1
  • 13
  • 25
  • There is a semicolon there, after the printaccountinfo function right? – grilam14 Oct 28 '16 at 04:53
  • Yes, my bad. The indentation is messed up so I got confused. – grigor Oct 28 '16 at 05:06
  • My error was not putting a () at the end of the class declaration in main. Now I have a new error, it's telling me my function in class Account is not actually a member. – grilam14 Oct 28 '16 at 05:09