#include <iostream>
#include <vector>
#include <iomanip>
using namespace std;
int main() {
const int NUM_ITEMS = 8;
vector <double> inverse(NUM_ITEMS);
int j;
double temp;
for (int i = 0; i < NUM_ITEMS; i++) {
inverse.at(i) = 1 / (i + 1.0);
}
cout << fixed << setprecision(2);
cout << "Original vector..." << endl;
for (int i = 0; i < NUM_ITEMS; i++) {
cout << inverse.at(i) << " ";
}
cout << endl;
cout << "Reversed vector..." << endl;
for (int i = 0; i < NUM_ITEMS; i++) {
cout << inverse.at(i) << " ";
}
return 0;
}
Original vector...
1.00 0.50 0.33 0.25 0.20 0.17 0.14 0.13
Reversed vector...
0.13 0.14 0.17 0.20 0.25 0.33 0.50 1.00
Using the code below write code to reverse the order of the vector. In other words, the value stored at index 0 will be swapped with the last item in the vector, the value stored at index 1 will be swapped with the next to last item in the vector, etc.
#include <iostream>
#include <vector>
#include <iomanip>
using namespace std;
int main() {
const int NUM_ITEMS = 8;
vector<double> inverse(NUM_ITEMS);
int j;
double temp;
for (int i = 0; i < NUM_ITEMS; i++) {
inverse.at(i) = 1 / (i + 1.0);
}
cout << fixed << setprecision(2);
cout << "Original vector..." << endl;
for (int i = 0; i < NUM_ITEMS; i++) {
cout << inverse.at(i) << " ";
}
cout << endl;
for (int i = 0; i < NUM_ITEMS / 2; ++i) {
temp = inverse.at(i);
inverse.at(i) = inverse.at(NUM_ITEMS - i - 1);
inverse.at(NUM_ITEMS - i - 1) = temp;
}
cout << "Reversed vector..." << endl;
for (int i = 0; i < NUM_ITEMS; i++) {
cout << inverse.at(i) << " ";
}
return 0;
}
#include <iostream> #include <vector> #include <iomanip> using namespace std; int main() { const int NUM_ITEMS =...
#include <iostream> #include <iomanip> #include <vector> #include <string> using namespace std; struct menuItemType { string menuItem; double menuPrice; }; void getData(menuItemType menuList[]); void showMenu(menuItemType menuList[], int x); void printCheck(menuItemType menuList[], int menuOrder[], int x); int main() { const int menuItems = 8; menuItemType menuList[menuItems]; int menuOrder[menuItems] = {0}; int orderChoice = 0; bool ordering = true; int count = 0; getData(menuList); showMenu(menuList, menuItems); while(ordering) { cout << "Enter the number for the item you would\n" << "like to order, or...
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main()
{
const int index = 5;
int head = 0;
string s[index];
int flag = 1;
int choice;
while (flag)
{
cout << "\n1. Add an Item in
the Chores List.";
cout << "\n2. How many Chores
are in the list.";
cout << "\n3. Show the list
of Chores.";
cout << "\n4. Delete an...
Use this code to create multiple functions.
#include<iostream>
#include<iomanip>
#include<fstream>
using namespace std;
int main()
{
cout << fixed << showpoint <<
setprecision(2);
ofstream outFile;
outFile.open("Feras's.txt");
outFile << "..Skinny Feras's Restaurant ..\n\n" <<
endl;
int choise=10, quantity;
float paid, SubTotal=0, Tax = .10, Total, RM, more;
while(choise!=0)
{
system("cls");
cout << "\t**Welcome To Skinny Alsaif Restaurant Lol**"
<< endl;
cout << "\nWhat would you like to have?" <<
endl;
cout << "1. Burger." << endl;
cout << "2. Pizza." <<...
im not sure why my code isnt working? include <iostream> #include <iomanip> using namespace std; int main() { int amountOfCoffee; double Price; char salesTaxChargeability; double TotalAmount; const double SALESTAX = 0.035; // 3.5 % cout << "\nEnter the number of pounds of coffee ordered in Pounds :"; cin >> amountOfCoffee; cout << "\nEnter the price of coffee per Pound :"; cin >> Price; cout << "\nIs sales tax Chargeable (y or n): "; cin >> salesTaxChargeability; if ( (salesTaxChargeability ==...
#include "stdafx.h" #include <iostream> #include <vector> #include <cassert> using namespace std; // function prototypes int loadDisk(vector<int> &firstPeg, int numDisks); void printPeg(vector<int> &peg); int hanoi(struct pegType &startPeg, struct pegType &swapPeg, struct pegType &endPeg, int numDisk); void moveDisk(struct pegType &startPeg, struct pegType &endPeg); struct pegType { vector <int> diskStack; int name; }; int main() { int numDisk = 7; int i; pegType peg1, peg2, peg3; peg1.name = 1; peg2.name = 2; peg3.name = 3;...
This is C++ code for parking fee management program #include <iostream> #include <iomanip> using namespace std; void input(char& car, int& ihour,int& imin, int& ohour, int& omin); void time(char car, int ihour, int imin, int ohour, int omin, int& phour, int& pmin, int& round, double& total); void parkingCharge (char car, int round, double& total); void print(char car, int ihour, int imin, int ohour, int omin, int phour, int pmin, int round, double total); int main() { char car; int ihour; int...
#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;
Part 1. [30 points] In this part, your program
loads a vending machine serving cold drinks. You start with many
foods, some are drinks. Your code loads a vending machine from
foods, or, it uses water as a default drink. Create class Drink,
make an array of drinks, load it and display it.
Part 1 steps:
[5 points] Create a class called
Drink that contains information about a single
drink. Provide...
#include <iostream> using namespace std; const int SIZE = 10; void displayGreaterThan(int[], int); void displaySmallerThan(int[],int); void displayArrayContent(int[]); void displayLargestValue(int[]); void displaySmallestValue(int[]); int main(){ int number; int numbers[SIZE] = {9,1,90,98,53,22,76,29,37,65}; cout <<"Enter a number: "; cin >> number; cout << endl; displayGreaterThan(numbers,number); cout << endl; displaySmallerThan(numbers,number); cout << endl; displayArrayContent(numbers); cout << endl; displayLargestValue(numbers); cout << endl; displaySmallestValue(numbers); cout << endl; return 0; } void displayGreaterThan(int value[],int num){ cout << " All larger value(s)than" <<...
#include <iostream> #include <cmath> #include <iomanip> #include <cstdlib> using namespace std; bool isInt (double value) { double dummy; return bool(modf(value, &dummy) == 0); } double sqr(double value) { return value * value; } double calcFrictionFactor(double R, double D, double epsilon) { const double BlasiusCoefficient = 0.3164; double f_old, f_new; f_new = BlasiusCoefficient * pow(R, -0.25); // loop until our two values are within 0.000001 of each other do { f_old = f_new; // previous guess is now the old one...
FILL IN THE BLANKS #include #include <> *BLANK* using namespace std; int main() { const double HOURLY_RATE = 15; string input_str; cout << "Enter days of attendance: " << endl; *BLANK* (cin, input_str); stringstream input_stream(); int total_hours = 0; while(!input_stream.())*BLANK* { int hours; string day; input_stream >> day; if(day == *BLANK*|| day == *BLANK*) { hours = 5; } *BLANK*(day == "Tuesday" || day == "Thursday") { hours = 4; } else if(day ==...