Question

In: Computer Science

Tony Gaddis C++ Conference Sessions An upcoming conference about C/C++ programming has three sessions planned: -...

Tony Gaddis C++ Conference Sessions An upcoming conference about C/C++ programming has three sessions planned:

- A session on the new features of C++ 17

- A session on functional programming in C/C++

- A session on lamda functions

Attendees can subscribe for any session. The organizers want to keep track of which attendees are attending which session.

Write a program that stores this information in a two-dimensional array of Booleans, where each row represents an attendee and each column represents their subscription for a session. You can restrict the program to seven attendees, resulting in a 7X3 array. The program should first have the user input the data for each attendee. Write two functions that take the array as their argument. One function should print out the number of people in each session and the other should return the number of people who subscribed to all sessions.

Solutions

Expert Solution

#include <iostream>

#include<string>

//This method takes the user input and substitutes it with true or false.

std::string substituteWithToF(std::string str){

if(str == "TRUE" ||str == "T" ||str == "true"||str == "YES"||str == "Y"||str == "yes" ||str == "y" )

return "true";

if(str == "FALSE" ||str == "F" ||str == "false"||str == "NO"||str == "N"||str == "no" ||str == "n" )

return "false";

return "invalid";

}

//This method prints number of people attending each session

void printAttendees(std::string sessionManage[7][3]){

int session1Attendees = 0;

int session2Attendees = 0;

for(int i=0;i<7;i++){

for(int j=0;j<3;j++){

if(j==1)

if(sessionManage[i][j]=="true") session1Attendees++;

if(j==2)

if(sessionManage[i][j]=="true") session2Attendees++;

}

}

std::cout<<"Number of people in session 1: "<<session1Attendees;

std::cout<<"Number of people in session 2: "<<session2Attendees;

}

//This method prints number of people attending both session

int printAllAttendees(std::string sessionManage[7][3]){

int sessionAttendees = 0;

for(int i=0;i<7;i++){

if(sessionManage[i][1]=="true" && sessionManage[i][2]=="true" )sessionAttendees++;

}

return sessionAttendees;

}

int main() {

//Taking array of string type instead of boolean to store attendee name, and in later stage the response is converted to true and false. Also, this prevents any error caused due to incorrect input.

std::string sessionManage[7][3];std::string flag;

//Asking user to input details

for(int i=0;i<7;i++){

for(int j=0;j<3;j++){

if(j==0){

std::cout << "Enter students name:\n";

std::cin>>sessionManage[i][j];

}

do{

//do-while loop is added so that user enters true or false values only.

std::cout << "Has student attended session 1? Please enter true/false or yes/no only\n";

std::cin>>sessionManage[i][j];

flag=substituteWithToF(sessionManage[i][j]);

sessionManage[i][j] = flag;

}while(flag == "invalid");

}

}

//Method to print the number of people in each session

printAttendees(sessionManage);

//Method that return the number of people who subscribed to all sessions.

int sessionAttendees = printAllAttendees(sessionManage);

std::cout<<"People attending both the sessions: "<<sessionAttendees;

}


Related Solutions

c++   In this lab you will create a program to make a list of conference sessions...
c++   In this lab you will create a program to make a list of conference sessions you want to attend. (List can be of anything...) You can hard code 10 Sessions in the beginning of your main program. For example, I have session UK1("Descaling agile",    "Gojko Adzic",       60);        session UK2("Theory of constraints", "Pawel Kaminski", 90); and then:        List l;        l.add(&UK1);        l.add(&UK2); Your Session struct should have the following member data: The Title The Speaker The session...
Starting out with Control Structures: Program challenges in C++ by Tony Gaddis This problem was adapted...
Starting out with Control Structures: Program challenges in C++ by Tony Gaddis This problem was adapted from questions 9 and 10 on page 661 Write a program that keeps track of a speakers’ bureau. The program should use a structure to store the following data about a speaker: Name, Telephone Number, Speaking Topic, Fee Required. The program should use a vector of structures. It should let the user enter data into the vector, change the contents of any element, and...
Tony Gaddis C++ Monkey Business A local zoo wants to keep track of how many pounds...
Tony Gaddis C++ Monkey Business A local zoo wants to keep track of how many pounds of food each of its three monkeys eats each day during a typical week. Write a program that stores this information in a two-dimensional 3 × 7 array, where each row represents a different monkey and each column represents a different day of the week. The monkeys are represented by integers 1, 2, and 3; the weekdays are "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday",...
C++ Tony Gaddis 8.11: Using Files-- String Selection Sort Modification Modify the selectionSort function presented in...
C++ Tony Gaddis 8.11: Using Files-- String Selection Sort Modification Modify the selectionSort function presented in this chapter so it sorts an array of strings instead of an array of ints. Test the function with a driver program that reads an integer, N, from standard input and then reads the first N strings from a file called href="asfunction:_root.doTutor,7,CPP">names. (Assume that N is less than or equal to 20.) Input Validation. If N read in from standard input is greater than...
Tony Gaddis C++ Tic-Tac-Toe Write a program that allows two players (player X and player O)...
Tony Gaddis C++ Tic-Tac-Toe Write a program that allows two players (player X and player O) to play a game of tic-tac-toe. Use a two- dimensional char array with three rows and three columns as the game board. Each element of the array should be initialized with an asterisk (*). The players take turns making moves and the program keeps track of whose turn it is. Player X moves first. The program should run a loop that: Displays the contents...
A company has three production departments A, B, and C and one service department D. Planned...
A company has three production departments A, B, and C and one service department D. Planned overhead costs for the quarter are as follows: Overheads £ Absorption basis Quality Control 3000 Direct Labour Hours Depreciation 3750 Machine value Insurance 1250 Machine value Rates and Rent 7500 Floor area Utility bills           625 Floor area The following information is available for each department: Absorption basis A B C D Machine Value (£) 5000 2500 3500 1500 Budgeted Direct Labour hours 1000 500...
The literature review section of a conference presentation should last about ____ minutes. a. three b....
The literature review section of a conference presentation should last about ____ minutes. a. three b. five c. seven d. nine
Homework 3 – Programming with C++ What This Assignment Is About: • Classes and Objects •...
Homework 3 – Programming with C++ What This Assignment Is About: • Classes and Objects • Methods • Arrays of Primitive Values • Arrays of Objects • Recursion • for and if Statements • Insertion Sort 2. Use the following Guidelines • Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc). • User upper case for constants. Use title case (first letter is upper case) for classes. Use lower case with uppercase word separators for...
C++ Programming Create a C++ program program that exhibits polymorphism. This file will have three class...
C++ Programming Create a C++ program program that exhibits polymorphism. This file will have three class definitions, one base class and three derived classes. The derived classes will have an inheritance relationship (the “is a” relationship) with the base class. You will use base and derived classes. The base class will have at least one constructor, functions as necessary, and at least one data field. At least one function will be made virtual. Class members will be declared public and...
Class object in C++ programming language description about lesson inheritance example.
Class object in C++ programming language description about lesson inheritance example.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT