1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Leto [7]
3 years ago
7

Online Book Merchants offers premium customers 1 free book with every purchase of 5 or more books and offers 2 free books with e

very purchase of 8 or more books. It offers regular customers 1 free book with every purchase of 7 or more books, and offers 2 free books with every purchase of 12 or more books. Write a statement that assigns freeBooks the appropriate value based on the values of the bool variable isPremiumCustomer and the int variable nbooksPurchased.
Computers and Technology
1 answer:
iragen [17]3 years ago
6 0

Answer:

The if else statements for the given scenario is shown below.

if ( isPremiumCustomer == true && nbooksPurchased >= 8 )

           freeBooks = 2;

else if ( isPremiumCustomer == true && nbooksPurchased >= 5 && nbooksPurchased < 8 )

           freeBooks = 1;

else if ( isPremiumCustomer == false && nbooksPurchased >= 12 )

           freeBooks = 2;

else if ( isPremiumCustomer == false && nbooksPurchased >= 7 && nbooksPurchased < 12 )

           freeBooks = 1;

Explanation:

The number of free books to be given is determined by multiple if else statements based on the values of Boolean variable and number of books purchased.

The c++ program to implement the above statements is given below.

#include <iostream>

using namespace std;

int main() {

   int nbooksPurchased = 7, freeBooks;

   bool isPremiumCustomer = false;    

   // determines the value of freeBooks

   if( isPremiumCustomer == true && nbooksPurchased >= 8 )

           freeBooks = 2;

   else if( isPremiumCustomer == true && nbooksPurchased >= 5 && nbooksPurchased < 8 )

           freeBooks = 1;

   else if( isPremiumCustomer == false && nbooksPurchased >= 12 )

           freeBooks = 2;

   else if( isPremiumCustomer == false && nbooksPurchased >= 7 && nbooksPurchased < 12 )

           freeBooks = 1;    

   cout << " Premium customer " << " \t \t " << isPremiumCustomer << endl;

   cout << " Number of free books " << " \t " << freeBooks << endl;    

   return 0;

}  

OUTPUT

Premium customer      0

Number of free books     1

 

Initially, the Boolean variable and integer variables are declared and initialized.

The variables are initialized inside the program. No user input is taken.

The value of 1 for premium customer represents true.

For regular customer, 0 will be displayed for the premium customer statement.

The if statement consists of multiple conditions inside one pair of braces. The compact form of if else is used as only the statement is needed per the question.

You might be interested in
Write a program whose input is a string which contains a character and a phrase, and whose output indicates the number of times
otez555 [7]

Answer:

The program written in python is as follows

def countchr(phrase, char):

     count = 0

     for i in range(len(phrase)):

           if phrase[i] == char:

                 count = count + 1

     return count

phrase = input("Enter a Phrase: ")

char = input("Enter a character: ")

print("Occurence: ",countchr(phrase,char))

Explanation:

To answer this question, I made use of function

This line defines function countchr

def countchr(phrase, char):

This line initializes count to 0

     count = 0

This line iterates through each character of input phrase

     for i in range(len(phrase)):

This line checks if current character equals input character

           if phrase[i] == char:

The count variable is incremented, if the above condition is true

                 count = count + 1

The total number of occurrence is returned using this line

     return count

The main method starts here; This line prompts user for phrase

phrase = input("Enter a Phrase: ")

This line prompts user for a character

char = input("Enter a character: ")

This line prints the number of occurrence of the input charcater in the input phrase

print("Occurence: ",countchr(phrase,char))

4 0
3 years ago
Alicia uses a software application to store the names, email addresses, and phone numbers of her friends in alphabetical order.
Tomtit [17]
She is in spreadsheet.
3 0
4 years ago
Read 2 more answers
One of the disadvantages of cable technology is that:
Artemon [7]

Answer:

The answer is letter C

Explanation:

Systems used by many providers require customers to share bandwidth with neighbors

8 0
3 years ago
What is the worst case time complexity of insertion sort where position of the data to be inserted is calculated using binary se
laiz [17]

Answer:

O(n²)

Explanation:

The worse case time complexity of insertion sort using binary search for positioning of data would be O(n²).

This is due to the fact that there are quite a number of series of swapping operations that are needed to handle each insertion.

4 0
3 years ago
Danielle is analyzing logs and baselines of the systems and services that she is responsible for in her organization. She wants
GalinKa [24]

Answer:

b. Machine learning

Explanation:

The technique that is being described in this situation is known as Machine Learning. This is a fairly new technology that has become popular over the last decade. Machine learning uses artificial intelligence to analyze data and learn from it. Every time the system analyzes the data it learns something new, saves it, and implements it to its processes. Therefore, the more times it repeats the more it learns. These systems are continuously getting better and learning more, which makes them incredibly efficient.

5 0
3 years ago
Other questions:
  • Annabella was giving a presentation to a group of 20 real estate agents on
    15·2 answers
  • The checksum doesn't compute for a packet sent at the Internet Protocol (IP) level. What will happen to the data?
    14·1 answer
  • Which of the following is a template definition?
    5·1 answer
  • A ____ is a program that is installed without the permission or knowledge of the computer user, that is designed to alter the wa
    11·1 answer
  • Write a C program that reads a string containing text and nonnegative numbers from the user and prints out the numbers contained
    6·1 answer
  • Which of the following statements is true?
    11·1 answer
  • When a bank account pays compound interest, it pays interest not only on the principal amount that was deposited into the accoun
    15·1 answer
  • Which of the following statements is true?
    9·1 answer
  • Pls tell me the answer pls i need the answer
    6·2 answers
  • Write a Java program that launches 1000 threads. Each thread adds 1 to a variable sum that initially is 0. You need to pass sum
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!