For each class create an *.h and *.cpp file that contains the class definition a
ID: 3802109 • Letter: F
Question
For each class create an *.h and *.cpp file that contains the class definition and the member functions. There will also be one file called 'main.cpp' that contains the main() function, and will instantiate the objects and test them.
Create 2 new classes for this project, one will be a 'Song' class and one will be a 'Date' class
Take the song class. Add the project new files called Song.h and Song.cpp and create the new class from scratch in those files. Use the 3 most important data members that describe the class/object to build (Example if I had book I would want Ttile Author and Pages so choose 3 for a song) and the write 2 constructors, 3 get member functions, 3 set member functions and a toString method and that is all.
Once you have created a new class, you need to adjust the main() function to allow the user to input the data members for your class and create an object of that type. Use the toString method to then display the new object on the screen. When the project is complete, both classes/objects should be created and displayed with main().
Please do not use the same 3 data types for any class's member variables. That is, do not make them all ' int ' or all ' string '.
Date class, the data members will be int day; int year; string month; Create a Date class with 2 constructors, 3 get member functions, 3 set member functions and a toString method. Adjust the main() function to use the Date class.
When the user wants to build a Date object, on the screen input 3 values, one for each member variable. Insert values into the Date object then output a simple message like:
"The Date object is: March 2, 2013"
It is very important that the data input be inserted INTO the object, and pulled back OUT of the object to print the above message.
Write a method: int getMonthNumber(); that returns the proper value 1-12 based on the string stored in the month variable. It should return the value -1 if the current value in the month variable is NOT valid. DO NOT store the month number in a member variable (local is OK), generate it when the method is called.
Write a method: void printDate( int format ); when it is called the format value will determine how the date is output to the screen using cout:
format 0: Mar 12, 2013
format 1: 12 Mar 2013
format 2: 3-12-2013
format 3: 3/12/13
Of course the actual values stored in the object will be output, this is only an example. Modify the main program to print the date in these additional formats. Optional: Use the int getMonthNumber(); method to check if the user enters a proper value for the month variable.
_____ Three global variables (not the same type)
_____ Two constructor methods
_____ Three 'get' methods
_____ Three 'set' methods
_____ One 'toString' method
_____ In the main function you create an object, insert values into the object, and print the object
_____ Five total classes Song.cpp, Song.h, Date.cpp, Date.h and a main()
Explanation / Answer
Here I am providing the all 5 files which you required for the project.
Song.h
class Song{
public:
int songid;
string songname;
string singername;
void setsongid(int i);
void setsongname(string name);
void setsingername(string sname);
void toString();
int getsongid();
string getsongname();
string getsingername();
};
Song.cpp
#include <iostream.h>
#include <string>
#include Song.h
Song::Song()
{
songid=0;
songname-"";
singername="";
}
void Song::setsongid(int i){ songid=i; }
void Somg::setsongname(string name){ songname=name;}
void Song::setsingername(string sname){ singername=sname;}
int Song::getsongid(){ return songid; }
string Song::getsongname(){ return songname; }
string Song::getsingername();{ return singername; }
void Song::toString()
{
cout<<getsongid()<<" " <<getsongname()<<" " <<getsingername();
}
Date.h
class Date{
public:
int day;
int year;
string month();
void setday(int d);
void setyear(int y);
void setmonth(int m);
void toString();
};
Date.cpp
#include <iostream.h>
#include <string.h>
#include Date.h
Date::Date()
{
day=1;
year=2017;
month="jan";
void Date::setday(int d){ day=d;}
void Date::setyear(int y){year=y;}
void Date::setmonth(int m){
getmonthnumber(m);
}
int getmonthnumber(int month){
if(month>=1||month<=12){
month=m;
}
else
{
System.out.println("Enter valid month");
}
}
void printdate(int format){
System.out.println("Enter Format you wish
0. mmm dd, yyyy
1. dd mmm yyyy
2. dd-mm-yyyy
3. mm/dd/yy
Enter your choice: ");
int c,d,m,y;
char mm;
switch(c){
Case 0: d=day;
m=month;
y=year;
if(month==1){mm="jan"}
else if(month==2){mm="feb"}
else if(month==3){mm="Mar"}
else if(month==3){mm="Apr"}
else if(month==5){mm="May"}
else if(month==6){mm="Jun"}
else if(month==7){mm="Jul"}
else if(month==8){mm="Aug"}
else if(month==9){mm="Sep"}
else if(month==10){mm="Oct"}
else if(month==11){mm="Nov"}
else if(month==12){mm="Dec"}
System.out.println(mm+" "+d", "+y);
break;
Case 1: d=day;
m=month;
y=year;
if(month==1){mm="jan"}
else if(month==2){mm="feb"}
else if(month==3){mm="Mar"}
else if(month==3){mm="Apr"}
else if(month==5){mm="May"}
else if(month==6){mm="Jun"}
else if(month==7){mm="Jul"}
else if(month==8){mm="Aug"}
else if(month==9){mm="Sep"}
else if(month==10){mm="Oct"}
else if(month==11){mm="Nov"}
else if(month==12){mm="Dec"}
System.out.println(d+" "+mm+" "+y);
break;
Case 2: d=day;
m=month;
y=year;
System.out.println(d+"-"++m+"-"+y);
break;
Case 4: d=day;
m=month;
y=year;
System.out.println(d+"/"++m+"/"+y);
break;
}
}
void Date::toString()
{
cout<<getday()<<" "<<getmonth()<<" "<<getyear();
}
};
main.cpp
#include<iostream.h>
#include<string.h>
#include Date.h
#include Song.h
#include Date.cpp
#include Song.cpp
Song s1;
Date d1;
cout<<"Enter Song id: ";
setsongid(s1.songid);
cout<<"Enter Song name: ";
setsongname(s1.songname);
cout<<"Enter Singer name : ";
setsingername(s1.singername);
s1.getsongid();
s1.getsongname();
s1.getsingername();
s1.toString();
cout<<"Enter day";
setday(d1.day);
cout<<"Enter Month";
setmonth("d1.month);
cout<<"Enter year");
setyear(d1.year);
d1.day();
d1.month();
d1.yera();
d1.toString();
}
return 0;
}
Hence the solution provided.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.