Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) MusicNote

 

MusicChord is a class for a music note.

 

 

 

 

 

musicnote.h

 

#ifndef MUSICNOTE_H
#define MUSICNOTE_H
//---------------------------------------------------------------------------
#include <string>
//---------------------------------------------------------------------------
struct MusicNote
{
  MusicNote(const std::string& s);

  static bool IsValidNote(const std::string& s);
  static void Check();

  private:
  int m_note;
};
//---------------------------------------------------------------------------
#endif // MUSICNOTE_H

 

 

 

 

 

musicnote.cpp

 

//---------------------------------------------------------------------------
#include <cassert>
#include <vector>
//---------------------------------------------------------------------------
#include "musicnote.h"
//---------------------------------------------------------------------------
MusicNote::MusicNote(const std::string& s)
{
  assert(IsValidNote(s));
}
//---------------------------------------------------------------------------
bool MusicNote::IsValidNote(const std::string& s)
{
  if (s.empty()) return false;
  if (s[0] < 'A' || s[0] > 'G') return false;
  if (s.size() == 1) return true;
  if (s.size() > 2) return false;
  return (s[1] == '#' || s[1] == 'b');
}
//---------------------------------------------------------------------------


 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict

This page has been created by the tool CodeToHtml