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

I am having trouble with a C++ code that I'm working on. It is a spell...
I am having trouble with a C++ code that I'm working on. It is a spell checker program. It needs to compare two arrays, a dictionary, and an array with misspelled strings that are compared to the strings in the dictionary. the strings that are in the second array that is not in the Dictionary are assumed to be misspelled. All of the strings in the dictionary are lowercase without any extra characters so the strings that are passed into...
I'm having trouble figuring out the constraints to this problem. I know that I am maximizing...
I'm having trouble figuring out the constraints to this problem. I know that I am maximizing 55x + 45y, however the variables are throwing me off. I only need help on question #1 as it would be a great help to understanding the rest of what the questions are asking. The problem is as follows: NorCal Outfitters manufactures a variety of specialty gear for outdoor enthusiasts. NorCal has decided to begin production on two new models of crampons: the Denali...
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'm having trouble implementing the merge function on this recursive merge sort. I am not allowed...
I'm having trouble implementing the merge function on this recursive merge sort. I am not allowed to change the parameter list in the functions. This is what I have so far, written in C. So far I've been getting segfaults, and I feel like it's because I'm off by 1, somewhere... void merge_the_array(int *list, int l1, int h1, int l2, int h2){ // create a temp array for l1-h1 int arr_a[(h1-l1)+1]; // create a temp array for l2-h2, adding 1...
I am having trouble fixing my build errors. The compiler I am using is Visual Studio.Thanks....
I am having trouble fixing my build errors. The compiler I am using is Visual Studio.Thanks. #include <iostream> #include <string> #include <cstdlib> using namespace std; /* * structure to store employee details * employee details are stored as linked list */ struct Employee { private:    string full_name; //full name    double net_income; //income public:    struct Employee *next; //pointing to the next employee details in the list                        /*                   ...
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)
C++ Bank Account Error Fix, full code. I am using Dev-C++ to Compile and Execute. The...
C++ Bank Account Error Fix, full code. I am using Dev-C++ to Compile and Execute. The project is below, I have supplied the code and I'm getting an error in SavingsAccount.h file. 17   5   C:\Users\adam.brunell\Documents\Classes\C++\Week4\SavingsAccount.h   [Error] 'SavingsAccount::SavingsAccount(std::string, double, double)' is protected A.Assume i.SavingsAccount: Assume an Interest Rate of 0.03 ii.HighInterestSavings: Assume an Interest Rate of 0.05, Minimum Balance = $2500 iii.NoServiceChargeChecking: Assume an Interest Rate = 0.02, Minimum of Balance = $1000 iv.ServiceChargeChecking – Assume account service charge = $10,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT