C++ Program, please provide notes explaining functions if able: Create your own
ID: 3727555 • Letter: C
Question
C++ Program, please provide notes explaining functions if able:
Create your own classes and use them to build objects. 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 'Shoes' class and one will be a required 'Date' class.
Process: Take assigned class 'Shoe' add to your project new files called Shoe.h and Shoe.cpp and create the new class from scratch in those files. Make 3 important data members that describe the class/object you want to build and the write 2 constructors, 3 get member functions, 3 set member functions, and a toString method. 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().
Do not use the same 3 data types for any class's member variables.
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.
Be able to 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"
Explanation / Answer
here is your program : ----------->>>>>>>.
Shoes.h : ----------->>>>>>>
#ifndef _SHOES_H
#define _SHOES_H
#include<iostream>
using namespace std;
class Shoes{
string brand;
int size;
double cost;
public:
Shoes();
Shoes(string,int,double);
void setBrand(string);
void setSize(int);
void setPrice(double);
string getBrand()const;
int getSize()const;
double getPrice()const;
string toString();
};
#endif
Shoes.cpp : ------------>>>>>>
#include "Shoes.h"
#include<sstream>
Shoes::Shoes(){
brand = "";
size = 0;
cost = 0.0;
}
Shoes::Shoes(string br,int s,double price){
cost = price;
size = s;
brand = br;
}
void Shoes::setBrand(string br){
brand = br;
}
void Shoes::setPrice(double price){
cost = price;
}
void Shoes::setSize(int s){
size = s;
}
int Shoes::getSize()const{
return size;
}
double Shoes::getPrice()const{
return cost;
}
string Shoes::getBrand()const{
return brand;
}
string Shoes::toString(){
string s;
s.reserve(100);
s = "Brand = ";
s += brand;
s += " Size = ";
s += (char)('0'+size);
s += " Price = ";
stringstream ss;
ss.clear();
ss<<cost;
string s1;
ss>>s1;
s += s1;
return s;
}
Date.h : ------------->>>>>>
#ifndef __DATE__H
#define __DATE__H
#include<iostream>
using namespace std;
class Date{
int day;
int year;
string month;
public:
Date();
Date(int,string,int);
void setDay(int);
void setMonth(string);
void setYear(int);
string getMonth()const;
int getDay()const;
int getYear()const;
string toString();
};
#endif
Date.cpp : --------->>>>>
#include "Date.h"
#include<sstream>
Date::Date(){
month = "January";
day = 1;
year = 1980;
}
Date::Date(int d,string m,int y){
month = m;
if(d < 1 && d > 31){
day = 1;
}else{
day = d;
}
year = y;
}
void Date::setDay(int d){
if(d < 1 && d > 31){
}else{
day = d;
}
}
void Date::setMonth(string m){
month = m;
}
void Date::setYear(int y){
year = y;
}
int Date::getDay()const{
return day;
}
int Date::getYear()const{
return year;
}
string Date::getMonth()const{
return month;
}
string Date::toString(){
string s = month;
stringstream ss;
ss<<day<<" "<<year;
string s1;
string s2;
ss>>s1>>s2;
s += " ";
s += s1;
s += ", ";
s += s2;
return s;
}
main.cpp : ----------->>>>>>>>>>-
#include "Shoes.cpp"
#include "Date.cpp"
int main(){
Date d1,d2(2,"March",2013);
Shoes s1,s2("Reebok",7,4500);
s1.setBrand("Puma");
s1.setSize(8);
s1.setPrice(2300.99);
d1.setDay(25);
d1.setMonth("April");
d1.setYear(2018);
cout<<"Date: ";
cout<<d1.toString();
cout<<endl;
cout<<d2.toString()<<endl;
cout<<"Shoes : ";
cout<<s1.toString()<<endl;
cout<<s2.toString()<<endl;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.