Question

In: Computer Science

Using dev c++ I'm having trouble with classes. I think the part that I am not...

Using dev c++

I'm having trouble with classes. I think the part that I am not understanding is sending data between files and also using bool data. I've been working on this program for a long time with many errors but now I've thrown in my hat to ask for outside help. Here is the homework that has given me so many issues:

The [REDACTED] Phone Store needs a program to compute phone charges for some phones sold in the store. There are two different pricing systems, depending on the phone purchased. Tax must be added on after the phone charge is computed. Each customer gets a neatly formatted receipt displayed to the screen.
You must write a driver and a class using separate files for full credit.
Learning Objectives
In this assignment, you will practice:
Using selection control structures
Creating a driver program and a class
Calling member functions.
Displaying neatly formatted output to the screen using C++ syntax
Requirements for the Phone Class
Data Members
Phone price (in dollars)
bool data member to indicate if phone is an iPhone or not
AppleCare years
Be sure to:
use the appropriate data type for each data member
use the appropriate access modifier for each data member
initialize each data member using an in-class initializer
Member Functions
One 3-parameter constructor – The constructor uses three parameters representing the phone price, whether or not the phone is an iPhone, and the AppleCare years. Use a member initializer list.
Getter and setter for each data member
getTotalPurchase function
This function must call the appropriate getter member functions where necessary. Do not access the data members directly.
This function calculates and returns the total amount of the phone.
If the phone is an iPhone, calculate additional charges for AppleCare as follows:
If the user chooses one year, the charge for AppleCare is 12% of the phone’s price.
If the user chooses more than one year, the charge for AppleCare is 10% of the phone’s price multiplied by the number of years.
The user cannot choose less than 1 year of AppleCare if the phone is an iPhone.
Compute the purchase subtotal by adding the AppleCare charges to the phone’s price.
Use a tax rate of 5% of the purchase subtotal to compute the sales tax amount in dollars. Add the sales tax amount to the purchase subtotal to determine the total purchase amount.
Return the total purchase amount to the calling code.
Requirements for the PhoneDriver Program
main Function
The user must be prompted appropriately.
All values related to money may include values after a decimal point. All values displayed to the screen must display with 2 places after the decimal.
The user must indicate whether or not the phone is an iPhone by typing a single character (y for yes, and n for no). Your program must be able to handle an upper or lowercase letter: Y, y, N, n.
Optional: Handle any other characters here by displaying an error message.
If the phone is an iPhone, prompt the user for the number of AppleCare years.
Instantiate a Phone object using the 3-parameter constructor.
Note that the parameter that indicates if the phone is an iPhone is a bool data type. The user must type a single character. You will have to use selection to instantiate a Phone object with the correct data type for this parameter.
Display the values in the output by calling the appropriate member function of the Phone object. The output must line up at the decimal point, as displayed in the sample runs.
Sample Run 1
Enter the price of the phone> 500.00
Is the phone an iPhone (Y/N)?> N

Price of phone           $500.00
Total purchase           $525.00
Sample Run 2
Enter the price of the phone> 600
Is the phone an iPhone (Y/N)?> y
Enter the number of years of AppleCare> 3

Price of phone           $600.00
Total purchase           $819.00
Sample Run 3
Enter the price of the phone> 800
Is the phone an iPhone (Y/N)?> Y
Enter the number of years of AppleCare> 1

Price of phone           $800.00
Total purchase           $940.80
Requirements for Full Credit on This Project
COMPLETE AND ACCURATE – Your program must compile, execute, and give accurate output.

-----------------------------------------------------------------------------------------------------------------------------------------------

My program: PhoneDriver.cp

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

#include
#include
#include "Phone.h"

using namespace std;

int main(){
  
   Phone myPhone{0, false, 1};
   int year;
  
   cout << "Enter the price of the phone> "; //prompt for price
   double price; //creating variable
   cin >> price; //obtaining user input
   myPhone.setPrice(price);
  
   cout << "\nIs the phone an iPhone (Y/N)? "; //prompt for if iphone or not
   string temp;
   cin >> temp;
   bool android; //creating variable
   //cin >> android; //obtaining user input
   temp == "Y" ? android = true : android = false;
  
   myPhone.setAndroid(android);
  
   if (android = 1){
   //getting the years of apple care
       cout << "Enter the number of years of AppleCare> ";
       cin >> year;
       myPhone.setYear(year);
   }
  
   printf("\nPhone price is $%.2f\n", myPhone.getPrice());
   printf("\nTotal purchase $%.2f\n", myPhone.getTotalPurchase());
  
   //cout << ("\nPhone price is $" << myPhone.getPrice();
   //cout << "\nTotal purchase $" << myPhone.getTotal();
   //cout << "\nPhone is apple: " << myPhone.getAndroid();
   //cout << "\nAppleCare years: " << myPhone.getYear();
      
}

----------------------------------------------------------------------------------------------------------------

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

My other program file: Phone.h

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

#include
#include

class Phone{  
  
public:
   //Phone(double phonePrice, bool phoneAndroid, int appleCare)
   Phone(double phonePrice, bool phoneAndroid, int phoneYear)
       : price{phonePrice}{
          
           if (phoneAndroid != 1){
               droid = phoneAndroid;
           }
          
       }
      
   void setPrice(double phonePrice){
       price = phonePrice;
   }
  
   double getPrice() const{
       return price;
   }
  
   void setAndroid(bool phoneAndroid){
       droid = phoneAndroid;
   }
  
   bool getAndroid() const{
       return droid;
   }
  
   void setYear(double phoneYear){
       yrs = phoneYear;
   }
  
   int getYear() const{
       return yrs;
   }
  
   double getTotalPurchase() const{
//commented out because it doesnt work and dont know how to fix, might finally ask the internet
       //if (droid != 0){
       //   if (yrs == 1){
               //total = price + (price * 1.12);
       //   }
           //total = price + (yrs * (price * 1.1));
  
       //}

       //return total;
   }
  
private:
   double price {0};
   bool droid {false};
   int yrs {1};
   double total {0};
};

Solutions

Expert Solution

Here is the updated code:

/////////////////////////////// PhoneDriver.cpp //////////////////////////////
#include <iostream>
#include <string>
#include "Phone.h"

using namespace std;

int main(){
  
   Phone myPhone{0, false, 1};
   int year;
  
   cout << "Enter the price of the phone> "; //prompt for price
   double price; //creating variable
   cin >> price; //obtaining user input
   myPhone.setPrice(price);
  
   cout << "Is the phone an iPhone (Y/N)? "; //prompt for if iphone or not
   string temp;
   cin >> temp;
   bool android; 
   
   // its an Android phone if the user did not enter y or Y
   android = (temp != "Y") && (temp != "y");

   myPhone.setAndroid(android);
  
   if (!android){
   //getting the years of apple care
       cout << "Enter the number of years of AppleCare> ";
       cin >> year;
       myPhone.setYear(year);
   }
  
   printf("Phone price is $%.2f\n", myPhone.getPrice());
   printf("Total purchase $%.2f\n", myPhone.getTotalPurchase());
}

And the phone.h file is below:

/////////////////////////////// Phone.h //////////////////////////////

class Phone{  
    public:
       // Three parameter constructor with member initializer
       Phone(double phonePrice, bool phoneAndroid, int phoneYear)
            : price(phonePrice), droid (phoneAndroid), yrs (phoneYear) {}
    
       void setPrice(double phonePrice){
           price = phonePrice;
       }
      
       double getPrice() const{
           return price;
       }
      
       void setAndroid(bool phoneAndroid){
           droid = phoneAndroid;
       }
      
       bool getAndroid() const{
           return droid;
       }
      
       void setYear(double phoneYear){
           yrs = phoneYear;
       }
      
       int getYear() const{
           return yrs;
       }
      
       double getTotalPurchase() const{
           if (droid) {
               double tax = price *0.05;
               return (price + tax);
           }
           else {
                double appleCare, tax;
                appleCare = (yrs == 1 ? 0.12 * price : 0.1 * price * yrs);
                tax = (price + appleCare) *0.05;
                return (price + appleCare + tax);
           }
       }
      
    private:
       double price {0.0};
       bool droid {false};
       int yrs {1};
};

Related Solutions

TCP client and server using C programming I am having trouble on how to read in...
TCP client and server using C programming I am having trouble on how to read in the IP adress and port number from the terminal Example: Enter IP address: 127.0.0.1 Enter Port Number: 8000 in both client and server code. How do can I make I can assign the Ip address and port number using the example above. the error I get is that the client couldn't connect with the server whenever i get the port number from the user...
I am having a trouble with a python program. I am to create a program that...
I am having a trouble with a python program. I am to create a program that calculates the estimated hours and mintutes. Here is my code. #!/usr/bin/env python3 #Arrival Date/Time Estimator # # from datetime import datetime import locale mph = 0 miles = 0 def get_departure_time():     while True:         date_str = input("Estimated time of departure (HH:MM AM/PM): ")         try:             depart_time = datetime.strptime(date_str, "%H:%M %p")         except ValueError:             print("Invalid date format. Try again.")             continue        ...
I'm having trouble thinking of a way that I can delete duplicates from a c string...
I'm having trouble thinking of a way that I can delete duplicates from a c string of alphabets. So what I'm supposed to do is I'm supposed to delete the repeated letters in the c string using pointers and also dynamically allocating space. I'm guessing that I will have to dynamically allocate space for an array to put in the letters that only appear once. To do that, can I create 2 pointers in a function and have 1 pointer...
I was able to calculate (a) but I am having trouble with the calculations of (b)....
I was able to calculate (a) but I am having trouble with the calculations of (b). Thanks! The following are New York closing rates for A$/US$ and $/£:                                     A$/$ = 1.5150;               $/£ = $1.2950             (a) Calculate the cross rate for £ in terms of A$ (A$/£).             (b) If £ is trading at A$1.95/£ in London (cross market) on the same day, is there an arbitrage opportunity?  If so, show how arbitrageurs with £ could profit from this opportunity and calculate the arbitrage...
I'm having trouble creating a histogram using openCV (color segmentation)
I'm having trouble creating a histogram using openCV (color segmentation)
I am working through this solution in rstudio and am having trouble fitting this table into...
I am working through this solution in rstudio and am having trouble fitting this table into a linear regression analysis. an answer with corrosponding r code used would be greatly appreciated A study was conducted to determine whether the final grade of a student in an introductory psychology course is linearly related to his or her performance on the verbal ability test administered before college entrance. The verbal scores and final grades for all 1010 students in the class are...
I'm having trouble programming connect four board game using linked lists, sets and maps in c++....
I'm having trouble programming connect four board game using linked lists, sets and maps in c++. Can you code connect four game using these concepts.
I am having the most trouble with 1d: 1. a. Prove that if f : A...
I am having the most trouble with 1d: 1. a. Prove that if f : A → B, g : B → C, and g ◦f : A → C is a 1-to-1 surjection, then f is 1-to-1 and g is a surjection. Proof. b. Prove that if f : A → B, g : B → C, g ◦ f : A → C is a 1-to-1 surjection, and g is 1-to-1, then f is a surjection. Proof. c....
I am working on these study questions and am having trouble understanding how it all works...
I am working on these study questions and am having trouble understanding how it all works together. Any help would be greatly appreciated!! An all equity firm is expected to generate perpetual EBIT of $50 million per year forever. The corporate tax rate is 0% in a fantasy no tax world. The firm has an unlevered (asset or EV) Beta of 1.0. The risk-free rate is 5% and the market risk premium is 6%. The number of outstanding shares is...
If anyone could simplify this for me. I'm having trouble understanding the material and I just...
If anyone could simplify this for me. I'm having trouble understanding the material and I just need a keep it simple stupid approach Discuss the various non influential as well as influential investments that company may have on their financial statements. Also compare and contrast how they are treated/recorded on the companies financial statements.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT