Question

In: Computer Science

Language is C++ NOTE: No arrays should be used to solve problems and No non-constants global...

Language is C++

NOTE:
No arrays should be used to solve problems and No non-constants global variables should be used.

PART A: (Minusculo Inn)

Minusculo Inn has only eight guest rooms:

Room Number Amenities
101 1 king size bed
102, 103,104 2 double beds
201, 202 1 queen size bed
203, 204 1 double bed & sofa bed

Write a program that asks for the room number and displays the amenities. If the user enters a room number that does not exist, the program should display “Input error”.

You must use a switch statement in your program to solve this problem.
No Repetition Statements is needed in this problem. A User is only making one selection.

The Minusculo Inn Restaurant has 4 lunch combos for customers to choose:

   Combo A : Fried chicken with slaw [price: $4.25]
   Combo B : roast beef with mashed potato [price: $5.75]
   Combo C : Fish and chips [price: $5.25]
   Combo D : soup and salad [price: $3.75]

Write a program to calculate how much a party of customers should pay. Suppose the party orders 2 B’s, 1 A and 3 D’s. The casher will enter B, B, A, D, D, D and T into the program. The T means “calculating total of the order”. It is a signal telling the computer that the whole order has been entered and it is time to calculate the total amount the party should pay. Assume there is no sales tax. The following is an example:

   Enter item ordered [A/B/C/D] or T to calculate total: B
   Enter item ordered [A/B/C/D] or T to calculate total: B
   Enter item ordered [A/B/C/D] or T to calculate total: A
   Enter item ordered [A/B/C/D] or T to calculate total: D
   Enter item ordered [A/B/C/D] or T to calculate total: D
   Enter item ordered [A/B/C/D] or T to calculate total: D
   Enter item ordered [A/B/C/D] or T to calculate total: T
   Please pay this amount: $ 27

PART B: (Statistics program)

Write a program that reads the integers in the text file (user must enter name of file) and:

Displays the number of integers in the file (5 %)
Displays the number of even and odd integers (5%)
Displays the sum of the even integers and the sum of the odd integers as well as the sum of all the integers (5%)
Displays the largest integer and the smallest integer (5 %)
Computes the average of the largest and smallest integer (10 %)
Compute the sum of ALL the digits in the input file (i.e. 123 475 – Sum is 1+2+3+4+7+5 = 22) (15 %)

Assume the contents of the file are as follows:

123 475 61 77 910
234 138 134 95 674
345 31 211 952 873
22 7 876 347 450

The following is a sample output: User input is the 'integers.dat'

What is name of the input file? integers.dat
The number of integers in the file is 20
There are 11 odd integers and 9 even integers
The sum of the odd integers is 2645
The sum of the even integers is 4390
The sum of all the integers is 7035
The largest integer is 952
The smallest integer is 7
The average of 952 and 7 is 479.5
The sum of all the digits is 212

NOTE:

Use two decimal point precision for the average

To check your code, adjust one of the integers in the file, recompile your code and run again (suggest changing the largest and smallest integers )

Even though there are 20 integers in the file, the program should NOT presume there are 20 integers. In other words, you should not solve this problem by declaring 20 integer variables. If I choose to use another integers.dat file other than the one provided with the assignment, your program should still work correctly with that file as well. All you can assume is that a series of integers will be read in from the file. Therefore, you need to implement a solution that uses the repetition control structures (for, while, do…while) in the reading and processing of these values to produce your output

Solutions

Expert Solution

Part A: (Minusculo Inn)

Write a program that asks for the room number and displays the amenities

main.cpp

//========================================================

#include<iostream>
using namespace std;

int main()
{
   int room_number;
   cout << "Please choose one room number between 101 to 104 and 201 to 204 : ";
    cin >> room_number;   // read user input
   switch (room_number)    // switch statement on room_number
   {
   case 101: {cout << "Amenities: 1 king size bed" << endl; break; }
   case 102: {cout << "Amenities: 2 double beds" << endl; break; }
   case 103: {cout << "Amenities: 2 double beds" << endl; break; }
   case 104: {cout << "Amenities: 2 double beds" << endl; break; }
   case 201: {cout << "Amenities: 1 queen size bed" << endl; break; }
   case 202: {cout << "Amenities: 1 queen size bed" << endl; break; }
   case 203: {cout << "Amenities: 1 double bed & sofa bed" << endl; break; }
   case 204: {cout << "Amenities: 1 double bed & sofa bed" << endl; break; }
   default: {cout << "Input error" << endl; break; }
   }
   system("pause");
}

//========================================================

Sample Output 1:

Sample Output 2:

Sample Output 3:

//---------------------------------------------------------------------------------------------------------------------------------------

Write a program to calculate how much a party of customers should pay

main.cpp

//===========================================================

#include<iostream>
using namespace std;

int main()
{
   char item;
   float total =0.0;
   while (1) // read until user don't want total(T)
   {
       cout << "Enter item ordered [A/B/C/D] or T to calculate total: ";
       cin >> item; // read item provided by customer
       if (item == 'T') break;   // Customer wants total
       else
       {
           switch (item)
           {
           case 'A': { total += 4.25; break; } // A is order amount is added in total
           case 'B': { total += 5.75; break; } // B is order amount is added in total
           case 'C': { total += 5.25; break; } // C is order amount is added in total
           case 'D': { total += 3.75; break; } // D is order amount is added in total
           default:
               break;
           }
       }
   }
   cout << "Please pay this amount: $ " << total << endl;
   system("pause");
}

//===========================================================

Sample input/output 1:

Sample input/output 2:

Part B: (Statistics program)

main.cpp

//======================================================================

#include<iostream>
#include<fstream>
#include<string>
using namespace std;

int main()
{
   string file_name;
   cout << "What is name of the input file? ";
   cin >> file_name;        // read file name
   ifstream in(file_name); // open user file
   int count_num = 0;       // count total number
   int count_even = 0;      // count even numbers
   int count_odd = 0;       // count odd numbers
   int sum_even = 0;        // sum of even numbers;
   int sum_odd = 0;         // sum of odd numbers;
   int sum_num = 0;         // total sum;
   int max = INT_MIN;       // maximum number assigned minimum possible integer
   int min = INT_MAX;       // minimum number assigned maximum possible integer
   int digit_sum = 0;       // sum of all digit
   int number;
   if (in.fail())
   {
       cout << "File is not opened succesfully" << endl;
   }
   while (!in.eof())         // while loop till eof doesn't hit
   {
       in >> number;         // reading from file
       count_num++;
       sum_num += number;    // total sum calculation
       //even number
       if (number % 2 == 0) // checking even number
       {
           count_even++;
           sum_even += number;
       }
       else
       {
           count_odd++;
           sum_odd += number;
       }
       if (max < number) max = number;   // maximum number finding
       if (min > number) min = number;   // minimum number finding

       if (number < 0) number = -number; // negative to positive for digit sum
       while (number !=0)                // digit sum calculation
       {
           digit_sum += number % 10;
           number /= 10;
       }
   }
   cout << "The number of integers in the file is " << count_num << endl;
   cout << "There are " << count_odd << " odd integers and " << count_even << " even integers" << endl;
   cout << "The sum of the odd integers is " << sum_odd << endl;
   cout << "The sum of the even integers is " << sum_even << endl;
   cout << "The sum of all the integers is " << sum_num << endl;
   cout << "The largest integer is " << max << endl;
   cout << "The smallest integer is " << min << endl;
   cout << "The average of " << max << " and " << min << " is " << (max + min) / 2.0 << endl;
   cout << "The sum of all the digits is " << digit_sum << endl;
   system("pause");
}

//======================================================================

Sample input 1: 1.dat

123 475 61 77 910
234 138 134 95 674
345 31 211 952 873
22 7 876 347 450

Sample output 1:

Sample input 2: 1.dat

123 475 61 77 910
234 138 134 95 674
345 31 211 952 873
22 7 876 347 450
982 1

Sample output 2:

// tested with negative integer case

Sample input 3: 1.dat    

32 -45 65 451 256
-451 412 475 -1 -899
-213 -214 542 12 3

Sample output 3:


Related Solutions

Please write code for C language Problem: Write a couple of functions to process arrays. Note...
Please write code for C language Problem: Write a couple of functions to process arrays. Note that from the description of the function you have to identify what would be the return type and what would be part of the parameter. display(): The function takes an int array and it’s size and prints the data in the array. sumArray(): It takes an int array and size, and returns the sum of the elements of the array. findMax(): It takes an...
TO BE DONE IN C LANGUAGE BEFORE READING THE QUESTION PLEASE NOTE THAT YOUR FUNCTION SHOULD...
TO BE DONE IN C LANGUAGE BEFORE READING THE QUESTION PLEASE NOTE THAT YOUR FUNCTION SHOULD EXACTLY PRODUCE THE GIVEN OUTPUT AND THE TIME COMPLEXITY SHOULD BE O(N^2) YOU NEED TO KNOW ABOUT COCKTAIL SHAKER SORT ALGORITHM: Cocktail-shaker sort is a modification of Bubble sort. Cocktail-shaker sort traverses the data structure in one direction, pushing the largest element ahead towards one end of the data structure, and then in the opposite direction, pushing the smallest element towards the other end,...
Never declare a C++ global variable in this class. But global constants are ok. unsigned Size1...
Never declare a C++ global variable in this class. But global constants are ok. unsigned Size1 = 100; // never do this at global scope const unsigned Size2 = 120; // this is ok (but probably not very helpful) Don't use the string class and don't use system functions for math (like pow) or strings (like strlen). These functions are meant to be short and simple; if you're writing something long and complicated, look for a simpler solution. void countdown(...
Problems Background work with multidimensional arrays. Your C program should enable the end-user to create any...
Problems Background work with multidimensional arrays. Your C program should enable the end-user to create any 2D matrix of n number of rows and m number of columns. The end-user could either use random numbers to initialize the matrix data or enter the values of his/her matrix using standard​ input methods such as a keyboard. After setting up the matrix data using an automated random method or manual method, the end-user could perform any following operations. We will use the...
java by using Scite Objectives: 1. Create one-dimensional arrays and two-dimensional arrays to solve problems 2....
java by using Scite Objectives: 1. Create one-dimensional arrays and two-dimensional arrays to solve problems 2. Pass arrays to method and return an array from a method Problem 2: Find the largest value of each row of a 2D array             (filename: FindLargestValues.java) Write a method with the following header to return an array of integer values which are the largest values from each row of a 2D array of integer values public static int[] largestValues(int[][] num) For example, if...
java by using Scite Objectives: 1. Create one-dimensional arrays and two-dimensional arrays to solve problems 2....
java by using Scite Objectives: 1. Create one-dimensional arrays and two-dimensional arrays to solve problems 2. Pass arrays to method and return an array from a method Problem 1: Find the average of an array of numbers (filename: FindAverage.java) Write two overloaded methods with the following headers to find the average of an array of integer values and an array of double values: public static double average(int[] num) public static double average(double[] num) In the main method, first create an...
One of the problems with non-verbal language is that it is difficult to interpret. You are...
One of the problems with non-verbal language is that it is difficult to interpret. You are giving a presentation to your associates at work (or classmates in class) and you observe the following non-verbal behavior in your audience members. One associate/student is writing the entire time you are talking. One associate/student is smiling although you are talking about a serious issue. One associate/student has his/her eyes closed. Discuss three possible interpretations of each non-verbal behavior and analyze how each interpretation...
Note: Three Functions as shown in the question below should be used: Other Wise don't solve...
Note: Three Functions as shown in the question below should be used: Other Wise don't solve it.Thanks. Write an ATM C++ program simulation to do the three common tasks: withdraw, deposit and balance checking using three C++ functions. You must define 3 users. Each user information is stored in an array. The WETHDRAW function to make money withdrawal. The DEPOSIT function to deposit money in the account. The CHECKING function to check the account balance. To withdraw money successfully from...
Language C++ *note* Your function count should match those given in the description; you have no...
Language C++ *note* Your function count should match those given in the description; you have no need for extra functions beyond that, and you should not have less. -Write a function, doTheRegression(), that takes as input a variable of type integer and returns a value of type double. It computes and returns 80% of the value given as the amount after reduction. -In your main function, write code that asks the user what the original amount is, and if they...
examples of management problems in a multinational companies.(NOTE: the problems should not be market research in...
examples of management problems in a multinational companies.(NOTE: the problems should not be market research in nature)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT