Hello I am very new to C++ but I have managed to scavenge through here and gather enough resources to get some sort of aggregation going between my notes and scale class 12:1 multiplicity I believe that is 12 notes to 1 scale class., I am aware that a scale is 7 notes but I am trying to Initially aggregate this over to the scale class first for later use within it.

How would I write a getter to return a specific element of m_notes rather than the whole vector? will this require me learning more about reference wrapper? I noticed that the only way we seem to be able to print values is by overloading the out operator will this be problematic.

1.Main.c

#include <iostream>
#include "Scale.h"
#include "Note.h"
#include <string>
#include <ostream>
#include <functional> // std::reference_wrapper
#include <vector>


using namespace std;


int main(){



    Scale rudysScale{0,"X"};

    Notes n0{"A"};
    Notes n1{"A#"};
    Notes n2{"B"};
    Notes n3{"C"};
    Notes n4{"C#"};
    Notes n5{"D"};
    Notes n6{"D#"};
    Notes n7{"E"};
    Notes n8{"F"};
    Notes n9{"F#"};
    Notes n10{"G"};
    Notes n11{"G#"};


    rudysScale.addNote(n0);
    rudysScale.addNote(n1);
    rudysScale.addNote(n2);
    rudysScale.addNote(n3);
    rudysScale.addNote(n4);
    rudysScale.addNote(n5);
    rudysScale.addNote(n6);
    rudysScale.addNote(n7);
    rudysScale.addNote(n8);
    rudysScale.addNote(n9);
    rudysScale.addNote(n10);
    rudysScale.addNote(n11);

    cout << rudysScale;









    return 0;

}

Note.h

#ifndef NOTES_H
#define NOTES_H

#include <iostream>
#include <string>
#include <functional> // std::reference_wrapper
#include <vector>
#include "Scale.h"


class Notes
{
    public:

    Notes(const std::string& note):
        m_notes{note}
{

}





    const std::string& getName() const {return m_notes;}



    private:

    std::string m_notes{};

    };




#endif // NOTES_H

Scale.h

#ifndef SCALE_H
#define SCALE_H

#include <iostream>
#include <string>
#include "Note.h"
#include <functional> // std::reference_wrapper
#include <vector>
#include <sstream>



    class Scale{



public:


    Scale(int x,std::string y);                  //Constructor



     void setRoot(std::string rootKind);         //Options here of (A-G#)
     void setType(int scaleKind);               // 0 - Maj,  1 - Min





    std::string viewRoot();              //Accessors
    int viewType();                      //Accessors





    void addNote(const Notes& note)
     {
        m_notes.push_back(note);
     }




   friend std::ostream& operator<<(std::ostream& out, const Scale& scale)
  {
    out << "Scale Notes of Alphabet : ";
    for (const auto& note : scale.m_notes)
    {
      out << note.get().getName() << ' ';
    }
    out << '\n';
    return out;
  }




private:

    int type;                            //Scale type data member (0 - Maj 1 - Min )
    std::string root;                    //Root note(A-G)
    std::vector<std::reference_wrapper<const Notes>> m_notes{}; 
    };

#endif // SCALE_H

Scale.cpp

#include "Scale.h"
#include <iostream>
#include <string>
#include "Note.h"

    Scale::Scale(int x,std::string y)
    {
    type = x;
    root = y;
    }



    void Scale::setRoot(std::string rootKind){               //Options here of (A-G#)
    root = rootKind;                                        //mutator
    }

    void Scale::setType(int scaleKind){
    type = scaleKind;                                     //mutator
    }




    std::string Scale::viewRoot(){
    return root;
    }

    int Scale::viewType(){
    return type;
    }


I have yet to seperate my Note.h into a cpp file, but I will get to this later today.

0

There are 0 best solutions below