EBK STARTING OUT WITH C++
EBK STARTING OUT WITH C++
9th Edition
ISBN: 9780134379371
Author: MUGANDA
Publisher: PEARSON CUSTOM PUB.(CONSIGNMENT)
bartleby

Concept explainers

Expert Solution & Answer
Book Icon
Chapter 12.2, Problem 12.7CP

Explanation of Solution

Purpose of the given code:

The purpose of the given code is to find the fat grams for the ice cream flavor that is entered by the user.

Program:

The “if…else if” statements are highlighted below.

//Include required header files

#include<iostream>

#include<cstring>

using namespace std;

// Main function

int main()

{

  //Declare constant variable

  const int LENGTH = 20;

  //Declare array of characters

  char iceCream[LENGTH];

  //Print the statements

  cout<<"What flavor of ice cream do you like best? ";

  cout<<"Chocolate, Vanilla, or Pralines and Pecan? ";

  //Get a flovor from the user

  cin.getline(iceCream, LENGTH);

  //Print the statements

  cout<<"Here is the number of fat grams for a half ";

  cout<<"cup serving:\n";

  //Check if the user enters "Chocolate"

if(strcmp(iceCream,"Chocolate")==0)

//Print the statement

cout<<"Chocolate: 9 fat grams.\n";

//Check if the user enters "Vanilla"

else if(strcmp(iceCream,"Vanilla")==0)

//Print the statement

cout<<"Vanilla: 10 fat grams.\n";

//Check if the user enters "Pralines" or "Pecan"

else if((strcmp(iceCream,"Pralines")==0)||(strcmp(iceCream,"Pecan")==0))

//Print the statement

cout<<"Pralines and Pecan: 14 fat grams...

Blurred answer
Students have asked these similar questions
Question 1 is already done need help with the others though    This is the C code I have so far  #include <stdio.h>   #include <stdlib.h>   struct employees   {   char name[20];   int ssn[9];   int yearBorn, salary;   };   struct employees **emps = new employees()[10]; //Added new statement ---- bartleby     // function to read the employee data from the user   void readEmployee(struct employees *emp)   {   printf("Enter name: ");   gets(emp->name);   printf("Enter ssn: ");   for(int i =0; i <9; i++)   scanf("%d", &emp->ssn[i]);   printf("Enter birth year: ");   scanf("%d", &emp->yearBorn);   printf("Enter salary: ");   scanf("%d", &emp->salary);   }       // function to create a pointer of employee type   struct employees *createEmployee()   {   // creating the pointer   struct employees *emp = malloc(sizeof(struct employees));   // function to read the data   readEmployee(emp);   // returning the data   return emp;   }       // function to…
This is the C code I have so far  #include <stdio.h>   #include <stdlib.h>   struct employees   {   char name[20];   int ssn[9];   int yearBorn, salary;   };   struct employees **emps = new employees()[10]; //Added new statement ---- bartleby     // function to read the employee data from the user   void readEmployee(struct employees *emp)   {   printf("Enter name: ");   gets(emp->name);   printf("Enter ssn: ");   for(int i =0; i <9; i++)   scanf("%d", &emp->ssn[i]);   printf("Enter birth year: ");   scanf("%d", &emp->yearBorn);   printf("Enter salary: ");   scanf("%d", &emp->salary);   }       // function to create a pointer of employee type   struct employees *createEmployee()   {   // creating the pointer   struct employees *emp = malloc(sizeof(struct employees));   // function to read the data   readEmployee(emp);   // returning the data   return emp;   }       // function to print the employee data to console   void display(struct employees…
USING C   A catalog listing for a textbook consists of the authors’ names, the title, the publisher, and the year ofpublication. Declare a structure type catalog_entry_t and a variable book , and write statements thatstore the relevant data for this textbook in book .   I have this code so far but not sure where to go from here    #include<stdio.h>#include<string.h> typedef struct{char author_name[50], title[50], publisher[50];int publication;} catalog_entry_t;catalog_entry_t book; strcpy(book.author_name,"Rhett Beeson");strcpy(book.title,"This class is hard");strcpy(book.publisher,"TTU");book.publication=2021

Chapter 12 Solutions

EBK STARTING OUT WITH C++

Ch. 12.3 - Prob. 12.11CPCh. 12.3 - Prob. 12.12CPCh. 12.4 - What is the output of the following program?...Ch. 12 - A(n)___________is represented in memory as an...Ch. 12 - The____________ statement is required before the...Ch. 12 - A(n)____________is written in your program as a...Ch. 12 - Prob. 4RQECh. 12 - The______________ is used to mark the end of a...Ch. 12 - Prob. 6RQECh. 12 - Prob. 7RQECh. 12 - Prob. 8RQECh. 12 - Prob. 9RQECh. 12 - Prob. 10RQECh. 12 - Prob. 11RQECh. 12 - Prob. 12RQECh. 12 - Prob. 13RQECh. 12 - Prob. 14RQECh. 12 - Prob. 15RQECh. 12 - Prob. 16RQECh. 12 - Prob. 17RQECh. 12 - Prob. 18RQECh. 12 - Write a function whose prototype is char...Ch. 12 - #inc1ude iostream using namespace std; int main()...Ch. 12 - #include iostream using namespace std; int main()...Ch. 12 - #include iostream using namespace std; int main()...Ch. 12 - #inc1ude iostream #inc1ude string using namespace...Ch. 12 - #inc1ude iostream #inc1ude cstring using namespace...Ch. 12 - #inc1ude iostream using namespace std; int main()...Ch. 12 - #inc1ude iostream #inc1ude string using namespace...Ch. 12 - #include iostream #inc1ude cstring using namespace...Ch. 12 - #include iostre4m #inc1ude cstring using namespace...Ch. 12 - Each of the following programs or program segments...Ch. 12 - Soft Skills 30. You are a member of a...Ch. 12 - Prob. 1PCCh. 12 - Prob. 2PCCh. 12 - Prob. 3PCCh. 12 - Prob. 4PCCh. 12 - Name Arranger Write a program that asks for the...Ch. 12 - Prob. 6PCCh. 12 - Prob. 7PCCh. 12 - Prob. 8PCCh. 12 - Prob. 9PCCh. 12 - Password Verifier Imagine you are developing a...Ch. 12 - Prob. 11PCCh. 12 - Check Writer Write a program that displays a...Ch. 12 - Prob. 13PCCh. 12 - Dollar Amount Formatter Modify Program 12-13 by...Ch. 12 - Word Separator Write a program that accepts as...Ch. 12 - Prob. 16PCCh. 12 - I before e except after c A friend of yours who is...Ch. 12 - User Name Write a program that queries its...Ch. 12 - String Splitter Write a function vectorstring...Ch. 12 - Palindromic Numbers A palindromic number is a...
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
  • Text book image
    Microsoft Visual C#
    Computer Science
    ISBN:9781337102100
    Author:Joyce, Farrell.
    Publisher:Cengage Learning,
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,