THIS IS FOR C++ PROGRAMMING USING VISUAL STUDIO
THE PROGRAM NEEDS TO BE IN C++ PROGRAMMING
#include "pch.h"
#include
#include
using namespace std;
// Function prototype
void displayMessage(void);
void totalFees(void);
double calculateFees(int);
double calculateFees(int bags) {
return bags * 30.0;
}
void displayMessage(void) {
cout << "This program calculates the total
amount of checked bag fees." << endl;
}
void totalFees() {
double bags = 0;
cout << "Enter the amount of checked bags you
have." << endl;
cout << "5 CHECKED BAG LIMIT" <<
endl;
cout << "How many checked bags do you have?
";
cin >> bags;
if (bags < 0 || bags > 5) {
cout << "Checked Bags must be
in the range 0-5";
return;
}
// Display total amount of checked bag fees
cout << "\nChecked Bag Fees\n";
cout << "------------------\n";
cout << setprecision(2) << fixed <<
showpoint;
cout << "Total Checked Bag Fees : " <<
setw(8) << calculateFees(bags) << endl;
}
int main() {
int choice = 0;
bool close = false;
do {
cout << "\n[1] - Display
Message" << endl;
cout << "[2] - Calculate
Total Fees" << endl;
cout << "[3] - Quit" <<
endl;
cout << "Choice: ";
cin >> choice;
switch (choice) {
case 1:
displayMessage();
break;
case 2:
totalFees();
break;
case 3:
close =
true;
break;
default:
cout <<
"You have entered an invalid choice" << endl;
break;
}
if (close) {
cout <<
"Thanks for using the application." << endl;
break;
}
else {
continue;
}
} while (true);
return 0;
}
Hi,
(please note:I have not understood the purpose of the code pasted in the question. As it doesn't have any connection to the question posted.)
if you want to add sorting and search functionalities to above code you can do the same adding case 4 and case 5)
please find the code and output attached below.
Kindly upvote.
#include <iostream>
#include<string.h>
#include<stdlib.h>
using namespace std;
void dualSort(string[], int[], int);
void binarySearch(string[],int[],int,int);
int main()
{
const int NUM_NAMES = 10;
string customerNames[NUM_NAMES]={"Baldwin,Alex",
"Gosling,Ryan",
"Bullock,Sandra",
"Townsend,pete",
"Trump,Donald",
"Markle,Megan",
"Lopez,Jennifer",
"Urban,Keith",
"Stone,Emma",
"Grande,Ariana"};
int customerId[NUM_NAMES]={55,89,23,10,56,88,90,33,22,11};
int count = 0;
int choice;
do
{
cout << "Menu: Select your
option\n\n";
cout << "(1) Dual Sort(using
bubble sort two arrays)\n";
cout << "(2) Binary Search
using dual sort\n";
cout << "(3)
Quit.\n\n";
cout << "Enter your choice
---> ";
cin >> choice;
if (1 <= choice &&
choice <= 5)
{
switch
(choice)
{
case 1:
cout <<
"The customer names and Id's are: " << endl;
for (int count = 0; count < NUM_NAMES; count++)
{
cout << "Before sort:" << customerNames[count] <<
"\n" << customerId[count] << " " << endl;
}
dualSort(customerNames,customerId,
NUM_NAMES);
break;
case 2:
int
custIdreq;
cout <<
"Enter the customer Id to be searched" << endl;
cin >>
custIdreq;
dualSort(customerNames,customerId,NUM_NAMES);
binarySearch(customerNames,customerId,custIdreq,NUM_NAMES);
break;
default:
cout << "Invalid choice. Enter
again.\n\n";
break;
}
}
}
while (choice != 3);
}
void str_swap(string *str1, string *str2)
{
string temp_custname = *str1;
*str1 = *str2;
*str2 = temp_custname;
}
void int_swap(int *xp, int *yp)
{
int temp = *xp;
*xp = *yp;
*yp = temp;
}
void binarySearch(string customerNames[], int customerId[],int
value, int n)
{
//First as requested in question do dual sort(bubble sort) then do
binary Search
int low = 0, high = n - 1;
int index;
while (low <= high)
{
index = (high + low) / 2;
if (customerId[index] == value) {
cout << "customer having custId "<< value
<<
" is "
<< customerNames[index] <<
endl;
return;
}
else if (customerId[index] > value)
high = index - 1;
else
low = index + 1;
}
cout << "Sorry, no such customer Id is found \n";
}
void dualSort(string customerNames[], int customerId[], int
NUM_NAMES)
{
char s1[100],s2[100];
for(int i=0;i<NUM_NAMES-1;i++)
{
for(int j=i+1;j<NUM_NAMES;j++)
{
if(customerId[j]<customerId[i])
{
str_swap(&customerNames[i],&customerNames[j]);
int_swap(&customerId[i],&customerId[j]);
}
}
}
for (int count = 0; count < NUM_NAMES; count++)
{
cout << "After Sort:" << customerNames[count] <<
"\n" << customerId[count] << " " << endl;
}
}
THIS IS FOR C++ PROGRAMMING USING VISUAL STUDIO THE PROGRAM NEEDS TO BE IN C++ PROGRAMMING #inclu...
Redo Programming Exercise 7 of Chapter 7 so that your program handles exceptions such as division by zero and invalid input. Your program should print Denominator must be nonzero and reprompt for a valid denominator when 0 is entered for a denominator. Please specify what should go in the divisionByZero.h file and the changes made to main.cpp Please provide output. Thank you in advance! main.cpp so far #include <iostream> using namespace std; void addFractions(int num1, int num2, int den1, int...
c++ programming : everything is done, except when you enter ("a" ) in "F" option , it does not work. here is the program. #include <iostream> #include <string> #include <bits/stdc++.h> #include <iomanip> #include <fstream> using namespace std; #define MAX 1000 class Inventory { private: long itemId; string itemName; int numberOfItems; double buyingPrice; double sellingPrice; double storageFees; public: void setItemId(long id) { itemId = id; } long getItemId() { return itemId; } void setItemName(string name) { itemName = name; } string...
C++ Design a class bankAccount that defines a bank account as an ADT and implements the basic properties of a bank account. The program will be an interactive, menu-driven program. a. Each object of the class bankAccount will hold the following information about an account: account holder’s name account number balance interest rate The data members MUST be private. Create an array of the bankAccount class that can hold up to 20 class objects. b. Include the member functions to...
using the source code at the bottom of this page, use the following instructions to make the appropriate modifications to the source code. Serendipity Booksellers Software Development Project— Part 7: A Problem-Solving Exercise For this chapter’s assignment, you are to add a series of arrays to the program. For the time being, these arrays will be used to hold the data in the inventory database. The functions that allow the user to add, change, and delete books in the store’s...
Can you fix this program and run an output for me. I'm using C++ #include using namespace std; //function to calculate number of unique digit in a number and retun it int countUniqueDigit(int input) { int uniqueDigitCount = 0; int storeDigit = 0; int digit = 0; while (input > 0) { digit = 1 << (input % 10); if (!(storeDigit & digit)) { storeDigit |= digit; ...
c++, I am having trouble getting my program to compile, any help would be appreciated. #include <iostream> #include <string> #include <string.h> #include <fstream> #include <stdlib.h> using namespace std; struct record { char artist[50]; char title[50]; char year[50]; }; class CD { //private members declared private: string artist; //asks for string string title; // asks for string int yearReleased; //asks for integer //public members declared public: CD(); CD(string,string,int); void setArtist(string); void setTitle(string); void setYearReleased(int); string getArtist() const; string getTitle() const; int...
C++ getline errors I am getting getline is undefined error messages. I would like the variables to remain as strings. Below is my code. #include <iostream> #include<string.h> using namespace std; int index = 0; // variable to hold how many customers are entered struct Address //Structure for the address. { int street; int city; int state; int zipcode; }; // Customer structure struct Customer { string firstNm, lastNm; Address busAddr, homeAddr; }; // Functions int displayMenu(); Customer getCustomer(); void showCustomer(Customer);...
Using C++, fix the following code so that (1) Change the student array storage part so that the data is loaded from a file "students.txt". Use an appropriate data termination flag. (2) Sort the student array in ascending order of GPA using insertion sort. Print the sorted array (3) Sort the student array in ascending order of ID using insertion sort. Print the sorted array (4) Illustrate Binary search for a particular ID that would be found and one...
I am trying to run this program in Visual Studio 2017. I keep getting this build error: error MSB8036: The Windows SDK version 8.1 was not found. Install the required version of Windows SDK or change the SDK version in the project property pages or by right-clicking the solution and selecting "Retarget solution". 1>Done building project "ConsoleApplication2.vcxproj" -- FAILED. #include <iostream> #include<cstdlib> #include<fstream> #include<string> using namespace std; void showChoices() { cout << "\nMAIN MENU" << endl; cout << "1: Addition...
C++ programming language: In this program you will create a simplified bag that acts like a stack meaning that the Last item inserted is the First Item that comes out. Your backend implementation must use a linked list. The code should pass the test (there's only 1) and there should be no memory leaks. Note that passing the test does not ensure full credit! The functions are listed in the suggested order of implementation but you may implement them in...