SlideShare a Scribd company logo
I can't figure out why it wont compile! How do I create the different files needed
Here is the question:
(1) Create three files to submit:
ItemToPurchase.h - Class declaration
ItemToPurchase.cpp - Class definition
main.cpp - main() function
Build the ItemToPurchase class with the following specifications:
Default constructor
Public class functions (mutators & accessors)
SetName() & GetName() (2 pts)
SetPrice() & GetPrice() (2 pts)
SetQuantity() & GetQuantity() (2 pts)
Private data members
string itemName - Initialized in default constructor to "none"
int itemPrice - Initialized in default constructor to 0
int itemQuantity - Initialized in default constructor to 0
(2) In main(), prompt the user for two items and create two objects of the ItemToPurchase class.
Before prompting for the second item, call cin.ignore() to allow the user to input a new string. (2
pts)
Ex:
(3) Add the costs of the two items together and output the total cost. (2 pts)
Ex:
Here is my code,
Program:
ItemToPurchase.h
#ifndef ITEMPURCHASEH
#define ITEMPURCHASEH
using namespace std;
//class Declaration
class ItemToPurchase
{
//declare private variables
private:
string itemName;
int itemPrice;
int itemQuantity;
//declare public methods
public:
//constructor
ItemToPurchase();
//methods
void SetName(string name);
string GetName();
void SetPrice(int price);
int GetPrice();
void SetQuantity(int quantity);
int GetQuantity();
};
#endif
ItemToPurchase.cpp
#include <iostream>
#include "ItemToPurchase.h"
using namespace std;
//constructor definition
ItemToPurchase::ItemToPurchase():itemName("none"),itemPrice(0),itemQuantity(0){}
//method definitions
void ItemToPurchase::SetName(string name)
{
itemName=name;
}
string ItemToPurchase::GetName()
{
return itemName;
}
void ItemToPurchase::SetPrice(int price)
{
itemPrice=price;
}
int ItemToPurchase::GetPrice()
{
return itemPrice;
}
void ItemToPurchase::SetQuantity(int quantity)
{
itemQuantity=quantity;
}
int ItemToPurchase::GetQuantity()
{
return itemQuantity;
}
main.cpp
#include <iostream>
#include "ItemToPurchase.h"
using namespace std;
//main() function
int main()
{
//declare variables
string name;
int price;
int quantity;
//create two objects of ItemToPurchase class
ItemToPurchase item1,item2;
//get item1 details
cout<<"Item 1"<<endl;
cout<<"Enter the item name: "<<endl;
getline(cin,name);
cout<<"Enter the item price: "<<endl;
cin>>price;
cout<<"Enter the item price: "<<endl;
cin>>quantity;
//call methods and set variables values
item1.SetName(name);
item1.SetPrice(price);
item1.SetQuantity(quantity);
cin.ignore();
//get item2 details
cout<<"Item 2"<<endl;
cout<<"Enter the item name: "<<endl;
getline(cin,name);
cout<<"Enter the item price: "<<endl;
cin>>price;
cout<<"Enter the item price: "<<endl;
cin>>quantity;
//call methods and set variables values
item2.SetName(name);
item2.SetPrice(price);
item2.SetQuantity(quantity);
cout<<"TOTAL COST"<<endl;
//calculate item1 and item2 COST
int item1_cost=item1.GetQuantity()*item1.GetPrice();
int item2_cost=item2.GetQuantity()*item2.GetPrice();
//calculate total cost
int total_cost=item1_cost+item2_cost;
//display item1 and item2 details
cout<<item1.GetName()<<" "<<item1.GetQuantity()<<" @ $"<<item1.GetPrice()<<" =
"<<item1_cost<<endl;
cout<<item2.GetName()<<" "<<item2.GetQuantity()<<" @ $"<<item2.GetPrice()<<" =
"<<item2_cost<<endl;
cout<<endl<<"Total: $"<<total_cost;
return 0;
}
Program:
ItemToPurchase.h
#ifndef ITEMPURCHASEH
#define ITEMPURCHASEH
using namespace std;
//class Declaration
class ItemToPurchase
{
//declare private variables
private:
string itemName;
int itemPrice;
int itemQuantity;
//declare public methods
public:
//constructor
ItemToPurchase();
//methods
void SetName(string name);
string GetName();
void SetPrice(int price);
int GetPrice();
void SetQuantity(int quantity);
int GetQuantity();
};
#endif
ItemToPurchase.cpp
#include <iostream>
#include "ItemToPurchase.h"
using namespace std;
//constructor definition
ItemToPurchase::ItemToPurchase():itemName("none"),itemPrice(0),itemQuantity(0){}
//method definitions
void ItemToPurchase::SetName(string name)
{
itemName=name;
}
string ItemToPurchase::GetName()
{
return itemName;
}
void ItemToPurchase::SetPrice(int price)
{
itemPrice=price;
}
int ItemToPurchase::GetPrice()
{
return itemPrice;
}
void ItemToPurchase::SetQuantity(int quantity)
{
itemQuantity=quantity;
}
int ItemToPurchase::GetQuantity()
{
return itemQuantity;
}
main.cpp
#include <iostream>
#include "ItemToPurchase.h"
using namespace std;
//main() function
int main()
{
//declare variables
string name;
int price;
int quantity;
//create two objects of ItemToPurchase class
ItemToPurchase item1,item2;
//get item1 details
cout<<"Item 1"<<endl;
cout<<"Enter the item name: "<<endl;
getline(cin,name);
cout<<"Enter the item price: "<<endl;
cin>>price;
cout<<"Enter the item price: "<<endl;
cin>>quantity;
//call methods and set variables values
item1.SetName(name);
item1.SetPrice(price);
item1.SetQuantity(quantity);
cin.ignore();
//get item2 details
cout<<"Item 2"<<endl;
cout<<"Enter the item name: "<<endl;
getline(cin,name);
cout<<"Enter the item price: "<<endl;
cin>>price;
cout<<"Enter the item price: "<<endl;
cin>>quantity;
//call methods and set variables values
item2.SetName(name);
item2.SetPrice(price);
item2.SetQuantity(quantity);
cout<<"TOTAL COST"<<endl;
//calculate item1 and item2 COST
int item1_cost=item1.GetQuantity()*item1.GetPrice();
int item2_cost=item2.GetQuantity()*item2.GetPrice();
//calculate total cost
int total_cost=item1_cost+item2_cost;
//display item1 and item2 details
cout<<item1.GetName()<<" "<<item1.GetQuantity()<<" @ $"<<item1.GetPrice()<<" =
"<<item1_cost<<endl;
cout<<item2.GetName()<<" "<<item2.GetQuantity()<<" @ $"<<item2.GetPrice()<<" =
"<<item2_cost<<endl;
cout<<endl<<"Total: $"<<total_cost;
return 0;
}
I can't figure out why it wont compile! How do I create the different.pdf

More Related Content

Similar to I can't figure out why it wont compile! How do I create the different.pdf

This code has nine errors- but I don't know how to solve it- Please g.pdf
This code has nine errors- but I don't know how to solve it-  Please g.pdfThis code has nine errors- but I don't know how to solve it-  Please g.pdf
This code has nine errors- but I don't know how to solve it- Please g.pdf
aamousnowov
 
please code in c#- please note that im a complete beginner- northwind.docx
please code in c#- please note that im a complete beginner-  northwind.docxplease code in c#- please note that im a complete beginner-  northwind.docx
please code in c#- please note that im a complete beginner- northwind.docx
AustinaGRPaigey
 
Lecture2.ppt
Lecture2.pptLecture2.ppt
Lecture2.ppt
TarekHemdan3
 
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdfC++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
aassecuritysystem
 
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docxfilesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
ssuser454af01
 
This is a java lab assignment. I have added the first part java re.pdf
This is a java lab assignment. I have added the first part java re.pdfThis is a java lab assignment. I have added the first part java re.pdf
This is a java lab assignment. I have added the first part java re.pdf
feetshoemart
 
Getting error - (Return type of out-of-line definition of 'Product--Ge.pdf
Getting error - (Return type of out-of-line definition of 'Product--Ge.pdfGetting error - (Return type of out-of-line definition of 'Product--Ge.pdf
Getting error - (Return type of out-of-line definition of 'Product--Ge.pdf
NicholasflqStewartl
 
Lecture 9_Classes.pptx
Lecture 9_Classes.pptxLecture 9_Classes.pptx
Lecture 9_Classes.pptx
NelyJay
 
Given an array nums of size n- return the majority element- The majori.pdf
Given an array nums of size n- return the majority element- The majori.pdfGiven an array nums of size n- return the majority element- The majori.pdf
Given an array nums of size n- return the majority element- The majori.pdf
MattCu9Parrd
 
Operator overload rr
Operator overload  rrOperator overload  rr
Operator overload rr
Dhivya Shanmugam
 
Why won't my code build and run- and what is the correct code so it bu (1).pdf
Why won't my code build and run- and what is the correct code so it bu (1).pdfWhy won't my code build and run- and what is the correct code so it bu (1).pdf
Why won't my code build and run- and what is the correct code so it bu (1).pdf
umeshagarwal39
 
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdfAssignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
formicreation
 
Why won't my code build and run- and what is the correct code so it bu.pdf
Why won't my code build and run- and what is the correct code so it bu.pdfWhy won't my code build and run- and what is the correct code so it bu.pdf
Why won't my code build and run- and what is the correct code so it bu.pdf
umeshagarwal39
 
#ifndef CRYPTO_HPP#define CRYPTO_HPP#include functional#.docx
#ifndef CRYPTO_HPP#define CRYPTO_HPP#include functional#.docx#ifndef CRYPTO_HPP#define CRYPTO_HPP#include functional#.docx
#ifndef CRYPTO_HPP#define CRYPTO_HPP#include functional#.docx
gertrudebellgrove
 

Similar to I can't figure out why it wont compile! How do I create the different.pdf (14)

This code has nine errors- but I don't know how to solve it- Please g.pdf
This code has nine errors- but I don't know how to solve it-  Please g.pdfThis code has nine errors- but I don't know how to solve it-  Please g.pdf
This code has nine errors- but I don't know how to solve it- Please g.pdf
 
please code in c#- please note that im a complete beginner- northwind.docx
please code in c#- please note that im a complete beginner-  northwind.docxplease code in c#- please note that im a complete beginner-  northwind.docx
please code in c#- please note that im a complete beginner- northwind.docx
 
Lecture2.ppt
Lecture2.pptLecture2.ppt
Lecture2.ppt
 
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdfC++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
 
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docxfilesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
 
This is a java lab assignment. I have added the first part java re.pdf
This is a java lab assignment. I have added the first part java re.pdfThis is a java lab assignment. I have added the first part java re.pdf
This is a java lab assignment. I have added the first part java re.pdf
 
Getting error - (Return type of out-of-line definition of 'Product--Ge.pdf
Getting error - (Return type of out-of-line definition of 'Product--Ge.pdfGetting error - (Return type of out-of-line definition of 'Product--Ge.pdf
Getting error - (Return type of out-of-line definition of 'Product--Ge.pdf
 
Lecture 9_Classes.pptx
Lecture 9_Classes.pptxLecture 9_Classes.pptx
Lecture 9_Classes.pptx
 
Given an array nums of size n- return the majority element- The majori.pdf
Given an array nums of size n- return the majority element- The majori.pdfGiven an array nums of size n- return the majority element- The majori.pdf
Given an array nums of size n- return the majority element- The majori.pdf
 
Operator overload rr
Operator overload  rrOperator overload  rr
Operator overload rr
 
Why won't my code build and run- and what is the correct code so it bu (1).pdf
Why won't my code build and run- and what is the correct code so it bu (1).pdfWhy won't my code build and run- and what is the correct code so it bu (1).pdf
Why won't my code build and run- and what is the correct code so it bu (1).pdf
 
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdfAssignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
 
Why won't my code build and run- and what is the correct code so it bu.pdf
Why won't my code build and run- and what is the correct code so it bu.pdfWhy won't my code build and run- and what is the correct code so it bu.pdf
Why won't my code build and run- and what is the correct code so it bu.pdf
 
#ifndef CRYPTO_HPP#define CRYPTO_HPP#include functional#.docx
#ifndef CRYPTO_HPP#define CRYPTO_HPP#include functional#.docx#ifndef CRYPTO_HPP#define CRYPTO_HPP#include functional#.docx
#ifndef CRYPTO_HPP#define CRYPTO_HPP#include functional#.docx
 

More from ColinjHJParsonsa

The organ in the brain that is primarily responsible for normal respir.pdf
The organ in the brain that is primarily responsible for normal respir.pdfThe organ in the brain that is primarily responsible for normal respir.pdf
The organ in the brain that is primarily responsible for normal respir.pdf
ColinjHJParsonsa
 
The total value of your inventory amounts to $150-000- Your inventory.pdf
The total value of your inventory amounts to $150-000- Your inventory.pdfThe total value of your inventory amounts to $150-000- Your inventory.pdf
The total value of your inventory amounts to $150-000- Your inventory.pdf
ColinjHJParsonsa
 
The total of individual weights of garbage discarded by 16 households.pdf
The total of individual weights of garbage discarded by 16 households.pdfThe total of individual weights of garbage discarded by 16 households.pdf
The total of individual weights of garbage discarded by 16 households.pdf
ColinjHJParsonsa
 
The total of individual weights of garbage discarded by 16 households (1).pdf
The total of individual weights of garbage discarded by 16 households (1).pdfThe total of individual weights of garbage discarded by 16 households (1).pdf
The total of individual weights of garbage discarded by 16 households (1).pdf
ColinjHJParsonsa
 
The Oracle tutorial on Object-Oriented Programming- What is an object-.pdf
The Oracle tutorial on Object-Oriented Programming- What is an object-.pdfThe Oracle tutorial on Object-Oriented Programming- What is an object-.pdf
The Oracle tutorial on Object-Oriented Programming- What is an object-.pdf
ColinjHJParsonsa
 
The table below shows the orbital period (in AU ) and the distance (in.pdf
The table below shows the orbital period (in AU ) and the distance (in.pdfThe table below shows the orbital period (in AU ) and the distance (in.pdf
The table below shows the orbital period (in AU ) and the distance (in.pdf
ColinjHJParsonsa
 
The Student Economics Society plans to recruit a new chairperson- Data.pdf
The Student Economics Society plans to recruit a new chairperson- Data.pdfThe Student Economics Society plans to recruit a new chairperson- Data.pdf
The Student Economics Society plans to recruit a new chairperson- Data.pdf
ColinjHJParsonsa
 
The slope coefficient - is called 1- Alpha 2- Beta 3- Regression 4- In.pdf
The slope coefficient - is called 1- Alpha 2- Beta 3- Regression 4- In.pdfThe slope coefficient - is called 1- Alpha 2- Beta 3- Regression 4- In.pdf
The slope coefficient - is called 1- Alpha 2- Beta 3- Regression 4- In.pdf
ColinjHJParsonsa
 
The Seven Seas Travel Agency maintains an organized collection of cust.pdf
The Seven Seas Travel Agency maintains an organized collection of cust.pdfThe Seven Seas Travel Agency maintains an organized collection of cust.pdf
The Seven Seas Travel Agency maintains an organized collection of cust.pdf
ColinjHJParsonsa
 
The Seven Seas Travel Agency maintains an organized collection of cust (1).pdf
The Seven Seas Travel Agency maintains an organized collection of cust (1).pdfThe Seven Seas Travel Agency maintains an organized collection of cust (1).pdf
The Seven Seas Travel Agency maintains an organized collection of cust (1).pdf
ColinjHJParsonsa
 
The sequence in which different silicate minerals crystallize during t.pdf
The sequence in which different silicate minerals crystallize during t.pdfThe sequence in which different silicate minerals crystallize during t.pdf
The sequence in which different silicate minerals crystallize during t.pdf
ColinjHJParsonsa
 
The Scientific Method Pre-Labohatory Assignment To be handed in to you.pdf
The Scientific Method Pre-Labohatory Assignment To be handed in to you.pdfThe Scientific Method Pre-Labohatory Assignment To be handed in to you.pdf
The Scientific Method Pre-Labohatory Assignment To be handed in to you.pdf
ColinjHJParsonsa
 
If W_AA -1-WAB-1-1- and W_BB-1-1- the population size is 10-000 - and.pdf
If W_AA -1-WAB-1-1- and W_BB-1-1- the population size is 10-000 - and.pdfIf W_AA -1-WAB-1-1- and W_BB-1-1- the population size is 10-000 - and.pdf
If W_AA -1-WAB-1-1- and W_BB-1-1- the population size is 10-000 - and.pdf
ColinjHJParsonsa
 
If we are looking for the probability of event E occurring given that.pdf
If we are looking for the probability of event E occurring given that.pdfIf we are looking for the probability of event E occurring given that.pdf
If we are looking for the probability of event E occurring given that.pdf
ColinjHJParsonsa
 
If the weather is good- which happens with probability 0-7- Jessica wa.pdf
If the weather is good- which happens with probability 0-7- Jessica wa.pdfIf the weather is good- which happens with probability 0-7- Jessica wa.pdf
If the weather is good- which happens with probability 0-7- Jessica wa.pdf
ColinjHJParsonsa
 
If the nation's investment opportunities are highly attractive relativ.pdf
If the nation's investment opportunities are highly attractive relativ.pdfIf the nation's investment opportunities are highly attractive relativ.pdf
If the nation's investment opportunities are highly attractive relativ.pdf
ColinjHJParsonsa
 
If the probability density function of a continuous random variable X.pdf
If the probability density function of a continuous random variable X.pdfIf the probability density function of a continuous random variable X.pdf
If the probability density function of a continuous random variable X.pdf
ColinjHJParsonsa
 
If the inner lining of the air sacs of birds is neither thin nor highl.pdf
If the inner lining of the air sacs of birds is neither thin nor highl.pdfIf the inner lining of the air sacs of birds is neither thin nor highl.pdf
If the inner lining of the air sacs of birds is neither thin nor highl.pdf
ColinjHJParsonsa
 
If the partial pressure of oxygen is lower in the pulmonary capillarie.pdf
If the partial pressure of oxygen is lower in the pulmonary capillarie.pdfIf the partial pressure of oxygen is lower in the pulmonary capillarie.pdf
If the partial pressure of oxygen is lower in the pulmonary capillarie.pdf
ColinjHJParsonsa
 
If the company declares a two-for-one stock split- how many shares are.pdf
If the company declares a two-for-one stock split- how many shares are.pdfIf the company declares a two-for-one stock split- how many shares are.pdf
If the company declares a two-for-one stock split- how many shares are.pdf
ColinjHJParsonsa
 

More from ColinjHJParsonsa (20)

The organ in the brain that is primarily responsible for normal respir.pdf
The organ in the brain that is primarily responsible for normal respir.pdfThe organ in the brain that is primarily responsible for normal respir.pdf
The organ in the brain that is primarily responsible for normal respir.pdf
 
The total value of your inventory amounts to $150-000- Your inventory.pdf
The total value of your inventory amounts to $150-000- Your inventory.pdfThe total value of your inventory amounts to $150-000- Your inventory.pdf
The total value of your inventory amounts to $150-000- Your inventory.pdf
 
The total of individual weights of garbage discarded by 16 households.pdf
The total of individual weights of garbage discarded by 16 households.pdfThe total of individual weights of garbage discarded by 16 households.pdf
The total of individual weights of garbage discarded by 16 households.pdf
 
The total of individual weights of garbage discarded by 16 households (1).pdf
The total of individual weights of garbage discarded by 16 households (1).pdfThe total of individual weights of garbage discarded by 16 households (1).pdf
The total of individual weights of garbage discarded by 16 households (1).pdf
 
The Oracle tutorial on Object-Oriented Programming- What is an object-.pdf
The Oracle tutorial on Object-Oriented Programming- What is an object-.pdfThe Oracle tutorial on Object-Oriented Programming- What is an object-.pdf
The Oracle tutorial on Object-Oriented Programming- What is an object-.pdf
 
The table below shows the orbital period (in AU ) and the distance (in.pdf
The table below shows the orbital period (in AU ) and the distance (in.pdfThe table below shows the orbital period (in AU ) and the distance (in.pdf
The table below shows the orbital period (in AU ) and the distance (in.pdf
 
The Student Economics Society plans to recruit a new chairperson- Data.pdf
The Student Economics Society plans to recruit a new chairperson- Data.pdfThe Student Economics Society plans to recruit a new chairperson- Data.pdf
The Student Economics Society plans to recruit a new chairperson- Data.pdf
 
The slope coefficient - is called 1- Alpha 2- Beta 3- Regression 4- In.pdf
The slope coefficient - is called 1- Alpha 2- Beta 3- Regression 4- In.pdfThe slope coefficient - is called 1- Alpha 2- Beta 3- Regression 4- In.pdf
The slope coefficient - is called 1- Alpha 2- Beta 3- Regression 4- In.pdf
 
The Seven Seas Travel Agency maintains an organized collection of cust.pdf
The Seven Seas Travel Agency maintains an organized collection of cust.pdfThe Seven Seas Travel Agency maintains an organized collection of cust.pdf
The Seven Seas Travel Agency maintains an organized collection of cust.pdf
 
The Seven Seas Travel Agency maintains an organized collection of cust (1).pdf
The Seven Seas Travel Agency maintains an organized collection of cust (1).pdfThe Seven Seas Travel Agency maintains an organized collection of cust (1).pdf
The Seven Seas Travel Agency maintains an organized collection of cust (1).pdf
 
The sequence in which different silicate minerals crystallize during t.pdf
The sequence in which different silicate minerals crystallize during t.pdfThe sequence in which different silicate minerals crystallize during t.pdf
The sequence in which different silicate minerals crystallize during t.pdf
 
The Scientific Method Pre-Labohatory Assignment To be handed in to you.pdf
The Scientific Method Pre-Labohatory Assignment To be handed in to you.pdfThe Scientific Method Pre-Labohatory Assignment To be handed in to you.pdf
The Scientific Method Pre-Labohatory Assignment To be handed in to you.pdf
 
If W_AA -1-WAB-1-1- and W_BB-1-1- the population size is 10-000 - and.pdf
If W_AA -1-WAB-1-1- and W_BB-1-1- the population size is 10-000 - and.pdfIf W_AA -1-WAB-1-1- and W_BB-1-1- the population size is 10-000 - and.pdf
If W_AA -1-WAB-1-1- and W_BB-1-1- the population size is 10-000 - and.pdf
 
If we are looking for the probability of event E occurring given that.pdf
If we are looking for the probability of event E occurring given that.pdfIf we are looking for the probability of event E occurring given that.pdf
If we are looking for the probability of event E occurring given that.pdf
 
If the weather is good- which happens with probability 0-7- Jessica wa.pdf
If the weather is good- which happens with probability 0-7- Jessica wa.pdfIf the weather is good- which happens with probability 0-7- Jessica wa.pdf
If the weather is good- which happens with probability 0-7- Jessica wa.pdf
 
If the nation's investment opportunities are highly attractive relativ.pdf
If the nation's investment opportunities are highly attractive relativ.pdfIf the nation's investment opportunities are highly attractive relativ.pdf
If the nation's investment opportunities are highly attractive relativ.pdf
 
If the probability density function of a continuous random variable X.pdf
If the probability density function of a continuous random variable X.pdfIf the probability density function of a continuous random variable X.pdf
If the probability density function of a continuous random variable X.pdf
 
If the inner lining of the air sacs of birds is neither thin nor highl.pdf
If the inner lining of the air sacs of birds is neither thin nor highl.pdfIf the inner lining of the air sacs of birds is neither thin nor highl.pdf
If the inner lining of the air sacs of birds is neither thin nor highl.pdf
 
If the partial pressure of oxygen is lower in the pulmonary capillarie.pdf
If the partial pressure of oxygen is lower in the pulmonary capillarie.pdfIf the partial pressure of oxygen is lower in the pulmonary capillarie.pdf
If the partial pressure of oxygen is lower in the pulmonary capillarie.pdf
 
If the company declares a two-for-one stock split- how many shares are.pdf
If the company declares a two-for-one stock split- how many shares are.pdfIf the company declares a two-for-one stock split- how many shares are.pdf
If the company declares a two-for-one stock split- how many shares are.pdf
 

Recently uploaded

Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
IGCSE Biology Chapter 14- Reproduction in Plants.pdf
IGCSE Biology Chapter 14- Reproduction in Plants.pdfIGCSE Biology Chapter 14- Reproduction in Plants.pdf
IGCSE Biology Chapter 14- Reproduction in Plants.pdf
Amin Marwan
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
GeorgeMilliken2
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
adhitya5119
 
Solutons Maths Escape Room Spatial .pptx
Solutons Maths Escape Room Spatial .pptxSolutons Maths Escape Room Spatial .pptx
Solutons Maths Escape Room Spatial .pptx
spdendr
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
haiqairshad
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Fajar Baskoro
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
TechSoup
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
siemaillard
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Denish Jangid
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
Celine George
 
B. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdfB. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdf
BoudhayanBhattachari
 

Recently uploaded (20)

Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
IGCSE Biology Chapter 14- Reproduction in Plants.pdf
IGCSE Biology Chapter 14- Reproduction in Plants.pdfIGCSE Biology Chapter 14- Reproduction in Plants.pdf
IGCSE Biology Chapter 14- Reproduction in Plants.pdf
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
 
Solutons Maths Escape Room Spatial .pptx
Solutons Maths Escape Room Spatial .pptxSolutons Maths Escape Room Spatial .pptx
Solutons Maths Escape Room Spatial .pptx
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
 
B. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdfB. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdf
 

I can't figure out why it wont compile! How do I create the different.pdf

  • 1. I can't figure out why it wont compile! How do I create the different files needed Here is the question: (1) Create three files to submit: ItemToPurchase.h - Class declaration ItemToPurchase.cpp - Class definition main.cpp - main() function Build the ItemToPurchase class with the following specifications: Default constructor Public class functions (mutators & accessors) SetName() & GetName() (2 pts) SetPrice() & GetPrice() (2 pts) SetQuantity() & GetQuantity() (2 pts) Private data members string itemName - Initialized in default constructor to "none" int itemPrice - Initialized in default constructor to 0 int itemQuantity - Initialized in default constructor to 0 (2) In main(), prompt the user for two items and create two objects of the ItemToPurchase class. Before prompting for the second item, call cin.ignore() to allow the user to input a new string. (2 pts) Ex: (3) Add the costs of the two items together and output the total cost. (2 pts) Ex: Here is my code, Program:
  • 2. ItemToPurchase.h #ifndef ITEMPURCHASEH #define ITEMPURCHASEH using namespace std; //class Declaration class ItemToPurchase { //declare private variables private: string itemName; int itemPrice; int itemQuantity; //declare public methods public: //constructor ItemToPurchase(); //methods void SetName(string name); string GetName(); void SetPrice(int price); int GetPrice(); void SetQuantity(int quantity); int GetQuantity(); }; #endif ItemToPurchase.cpp #include <iostream> #include "ItemToPurchase.h" using namespace std; //constructor definition ItemToPurchase::ItemToPurchase():itemName("none"),itemPrice(0),itemQuantity(0){} //method definitions void ItemToPurchase::SetName(string name) { itemName=name; } string ItemToPurchase::GetName() { return itemName; } void ItemToPurchase::SetPrice(int price) { itemPrice=price;
  • 3. } int ItemToPurchase::GetPrice() { return itemPrice; } void ItemToPurchase::SetQuantity(int quantity) { itemQuantity=quantity; } int ItemToPurchase::GetQuantity() { return itemQuantity; } main.cpp #include <iostream> #include "ItemToPurchase.h" using namespace std; //main() function int main() { //declare variables string name; int price; int quantity; //create two objects of ItemToPurchase class ItemToPurchase item1,item2; //get item1 details cout<<"Item 1"<<endl; cout<<"Enter the item name: "<<endl; getline(cin,name); cout<<"Enter the item price: "<<endl; cin>>price; cout<<"Enter the item price: "<<endl; cin>>quantity; //call methods and set variables values item1.SetName(name); item1.SetPrice(price); item1.SetQuantity(quantity); cin.ignore(); //get item2 details cout<<"Item 2"<<endl; cout<<"Enter the item name: "<<endl; getline(cin,name); cout<<"Enter the item price: "<<endl;
  • 4. cin>>price; cout<<"Enter the item price: "<<endl; cin>>quantity; //call methods and set variables values item2.SetName(name); item2.SetPrice(price); item2.SetQuantity(quantity); cout<<"TOTAL COST"<<endl; //calculate item1 and item2 COST int item1_cost=item1.GetQuantity()*item1.GetPrice(); int item2_cost=item2.GetQuantity()*item2.GetPrice(); //calculate total cost int total_cost=item1_cost+item2_cost; //display item1 and item2 details cout<<item1.GetName()<<" "<<item1.GetQuantity()<<" @ $"<<item1.GetPrice()<<" = "<<item1_cost<<endl; cout<<item2.GetName()<<" "<<item2.GetQuantity()<<" @ $"<<item2.GetPrice()<<" = "<<item2_cost<<endl; cout<<endl<<"Total: $"<<total_cost; return 0; } Program: ItemToPurchase.h #ifndef ITEMPURCHASEH #define ITEMPURCHASEH using namespace std; //class Declaration class ItemToPurchase { //declare private variables private: string itemName; int itemPrice; int itemQuantity; //declare public methods public: //constructor ItemToPurchase(); //methods void SetName(string name); string GetName(); void SetPrice(int price); int GetPrice();
  • 5. void SetQuantity(int quantity); int GetQuantity(); }; #endif ItemToPurchase.cpp #include <iostream> #include "ItemToPurchase.h" using namespace std; //constructor definition ItemToPurchase::ItemToPurchase():itemName("none"),itemPrice(0),itemQuantity(0){} //method definitions void ItemToPurchase::SetName(string name) { itemName=name; } string ItemToPurchase::GetName() { return itemName; } void ItemToPurchase::SetPrice(int price) { itemPrice=price; } int ItemToPurchase::GetPrice() { return itemPrice; } void ItemToPurchase::SetQuantity(int quantity) { itemQuantity=quantity; } int ItemToPurchase::GetQuantity() { return itemQuantity; } main.cpp #include <iostream> #include "ItemToPurchase.h" using namespace std; //main() function int main() {
  • 6. //declare variables string name; int price; int quantity; //create two objects of ItemToPurchase class ItemToPurchase item1,item2; //get item1 details cout<<"Item 1"<<endl; cout<<"Enter the item name: "<<endl; getline(cin,name); cout<<"Enter the item price: "<<endl; cin>>price; cout<<"Enter the item price: "<<endl; cin>>quantity; //call methods and set variables values item1.SetName(name); item1.SetPrice(price); item1.SetQuantity(quantity); cin.ignore(); //get item2 details cout<<"Item 2"<<endl; cout<<"Enter the item name: "<<endl; getline(cin,name); cout<<"Enter the item price: "<<endl; cin>>price; cout<<"Enter the item price: "<<endl; cin>>quantity; //call methods and set variables values item2.SetName(name); item2.SetPrice(price); item2.SetQuantity(quantity); cout<<"TOTAL COST"<<endl; //calculate item1 and item2 COST int item1_cost=item1.GetQuantity()*item1.GetPrice(); int item2_cost=item2.GetQuantity()*item2.GetPrice(); //calculate total cost int total_cost=item1_cost+item2_cost; //display item1 and item2 details cout<<item1.GetName()<<" "<<item1.GetQuantity()<<" @ $"<<item1.GetPrice()<<" = "<<item1_cost<<endl; cout<<item2.GetName()<<" "<<item2.GetQuantity()<<" @ $"<<item2.GetPrice()<<" = "<<item2_cost<<endl; cout<<endl<<"Total: $"<<total_cost; return 0; }