Concept explainers
Explanation of Solution
The given code snippet is not correctly formatted:
#include <iostream>
#include <string>
using namespace std; (1)
const double X = 13.45;const int Y=18; (2)(3)
const char STAR= '*';
int main()
{string employeeID;string department; int num; (4)(9)
double salary; (9)
cout<<"Enter employee ID: "; cin>> employeeID; cout<<endl; (5)(6)(9)(10)
cout<<"Enter department: "; cin (5)(6)(7)(9)
>>department; (5)(7)(9)
cout<<endl; cout<<"Enter a positive integer less than 80:"; (5)(6)(9)(10)
cin>>num;cout<<endl; salary=num*X; (5)(6)(8)(9)(10)
cout<<"ID: "<< employeeID <<endl; (5)(9)(10)
cout<<"Department "<<department<&...
Want to see the full answer?
Check out a sample textbook solutionChapter 2 Solutions
C++ Programming: From Problem Analysis to Program Design
- #include<iostream>#include<string.h>using namespace std; struct student{ int number; string name; int age; string city;}s[10]; struct module{ int number; string name; string code; int credit;}m[10]; struct assessment{ int number; int marks1; int marks2;}a[10]; int index1 =0, index2=0, index3=0; void StudentRegistration(){ if(index1==10) { cout<<"No more data can be added"<<endl; return; } string temp; cout<<"Enter personal data"<<endl; cout<<"Enter Student Number"<<endl; cin>>s[index1].number; cout<<"Enter Student Name"<<endl; getline(cin, temp); getline(cin,s[index1].name); cout<<"Enter Age"<<endl; cin>>s[index1].age; cout<<"Enter city"<<endl; getline(cin,temp); getline(cin,s[index1].city); index1++;} void ModuleEnrolment(int id){ if(index2==10) { cout<<"No more data can be…arrow_forwardNonearrow_forwardstruct date{ int day; int month; int year; }; Write a function named void increaseDay(struct date *d) that increases the value of a variable of struct date type with integer year, month, and day members by one day. Write a function named void decreaseDay(struct date *d) that decreases the value of a variable of struct date type with integer year, month, and day members by one day. Write a C program that reads from the user a date in d/m/y format and the amount of increase or decrease as an integer. Display the new date in d/m/y format. You may call related functions as many as given increase or decrease value. Note 1: You do not need to consider leap years. Use always 28 days for month February. Note 2: Do not modify the function prototypes. Sample Input1: Sample Output1: 12/8/1990 -5 7/8/1990 Sample Input2: Sample Output2: 26/2/2005 5 3/3/2005 Sample Input3: Sample Output3: 29/12/1998 7 5/1/1999…arrow_forward
- struct gameType { string title; int numPlayers; bool online; }; gameType Awesome[50]; Write the C++ statements that print out all gameType fields from Awesome whose numPlayers is > 1.arrow_forwardstruct gameType { string title; int numPlayers; bool online; }; gameType Awesome[50]; Write the C++ statement that sets the first [0] title of Awesome to Best.arrow_forward#include <iostream> #include <string> using namespace std; int main() { // Declare and initialize variables. string employeeFirstName; string employeeLastName; double employeeSalary; int employeeRating; double employeeBonus; const double BONUS_1 = .25; const double BONUS_2 = .15; const double BONUS_3 = .10; const double NO_BONUS = 0.00; const int RATING_1 = 1; const int RATING_2 = 2; const int RATING_3 = 3; // This is the work done in the housekeeping() function // Get user input cout << "Enter employee's first name: "; cin >> employeeFirstName; cout << "Enter employee's last name: "; cin >> employeeLastName; cout << "Enter employee's yearly salary: "; cin >> employeeSalary; cout << "Enter employee's performance rating: "; cin >> employeeRating; // This is the work done in the detailLoop() function // Use switch statement to…arrow_forward
- #include using namespace std; int main() int x=1,y=2; for (int i=0; i<3; i++) e{ x=x*y; 8{ } cout<arrow_forward#include <iostream>#include <string>#include <climits> using namespace std;class BalancedTernary { protected: // Store the value as a reversed string of +, 0 and - characters string value; // Helper function to change a balanced ternary character to an integer int charToInt(char c) const { if (c == '0') return 0; return 44 - c; } // Helper function to negate a string of ternary characters string negate(string s) const { for (int i = 0; i < s.length(); ++i) { if (s[i] == '+') s[i] = '-'; else if (s[i] == '-') s[i] = '+'; } return s; } public: // Default constructor BalancedTernary() { value = "0"; } // Construct from a string BalancedTernary(string s) { value = string(s.rbegin(), s.rend()); } // Construct from an integer BalancedTernary(long long n) { if (n == 0) { value = "0"; return; } bool neg = n < 0; if (neg) n = -n; value = ""; while (n !=…arrow_forwardC++ complete magic Square #include <iostream> using namespace std; /*int f( int x, int y, int* p, int* q ){if ( y == 0 ){p = 0, q = 0;return 404; // status: Error 404}*p = x * y; // product*q = x / y; // quotient return 200; // status: OK 200} int main(){int p, q;int status = f(10, 2, &p, &q);if ( status == 404 ){cout << "[ERR] / by zero!" << endl;return 0;}cout << p << endl;cout << q << endl; return 0;}*/ /*struct F_Return{int p;int q;int status;}; F_Return f( int x, int y ){F_Return r;if ( y == 0 ){r.p = 0, r.q = 0;r.status = 404;return r;}r.p = x * y;r.q = x / y;r.status = 200;return r;} int main(){F_Return r = f(10, 0);if ( r.status == 404 ){cout << "[ERR] / by zero" << endl;return 0;}cout << r.p << endl;cout << r.q << endl;return 0;}*/ int sumByRow(int *m, int nrow, int ncol, int row){ int total = 0;for ( int j = 0; j < ncol; j++ ){total += m[row * ncol + j]; //m[row][j];}return total; } /*…arrow_forwardC++ enum Major {COMPUTER_SCIENCE, COMPUTER_SECURITY_INFO_ASSURANCE, CYBER_SECURITY, ELECTRICAL_ENGINEERING, OTHER}; struct Name { string first; string last; char middleInitial; }; struct StudentRecord { Name studentName; Major major; string email; }; StudentRecord student12; Suppose you are student12. Show the C++ statements used to fill in all of your information for your StudentRecord. Show how would you assign the third letter from the email field to a local char variable called myChar.arrow_forward#include <iostream> #include <string> #include<iomanip> using namespace std; int main() { int monthlyUsage[12]; double consumption[12]; double discount[12]; double tax[12]; double bill[12]; string fullMonthName[12] = { "January","February","March","April","May","June","July","August","September","October","November","December" }; string month[12] = { "Jan","Feb","March","April","May","June","July","Aug","Sep","Oct","Nov","Dec"}; for (int i = 0; i < 12; i++) { cout << "please input monthly usage in kWh for " << fullMonthName[i] << ": " <<endl; cin >> monthlyUsage[i]; // Get user input and put it inside array monthlyUsage // TO DO CALCULATION FOR THE CONSUMPTION if (monthlyUsage[i] > 0 && monthlyUsage[i] < 101) { consumption[i] = (17.5/100) * monthlyUsage[i]; } else if (monthlyUsage[i] > 100 && monthlyUsage[i] < 201) { consumption[i] = 17.5 + ((monthlyUsage[i] - 100) * (18.5 / 100)); } else if (monthlyUsage[i]…arrow_forwardusing System; using System.Linq; using System.Text; namespace Games; { class Program { staticvoid Main(string[] args) { int choice,games_choice; cout<<"What are your favorite games - outdoor or indoor"<<endl; cout<<"Press 1 for 'outdoor' or Press 2 for 'indoor'"<<endl; cin>>choice; if(choice==1) { cout<<"What is your favorite outdoor game"<<endl; cout<<"Press 1 for Tennis"<<endl; cout<<"Press 2 for Football"<<endl; cout<<"Press 3 for Cricket"<<endl; cin>>games_choice; if(games_choice==1) cout<<"I also like Tennis"<<endl; elseif(games_choice==2) cout<<"I also like Football"<<endl; elseif(games_choice==3) cout<<"I also like Cricket"<<endl; } elseif(choice==2) { cout<<"What is your favorite indoor game"<<endl; cout<<"Press 1 for Ludo"<<endl; cout<<"Press 2 for Chess"<<endl; cout<<"Press 3 for Cards"<<endl;…arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education