Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

why is my output coming out empty? main.cpp include #include #include #include #include SetSummable.h #include PairSummable.h #include SetSummable.h #include PairSummable.h int main(int argc, char* argv[])

why is my output coming out empty?
main.cpp
include
#include
#include
#include
#include "SetSummable.h"
#include "PairSummable.h"
#include "SetSummable.h"
#include "PairSummable.h"
int main(int argc, char* argv[])
{
std::cout
std::cout
for (int i = 0; i
std::cout
std::cout
// Process the first file
// The values in this file will be interpreted as strings
// Sumation means string concatenation.
{
sdds::SetSummable<:pairsummable std::string>, 15, std::string, std::string> products;
// get the data from the file
{
std::ifstream input(argv[1]);
if (!input)
{
std::cerr
return 3;
}
do
{
char label[64], value[64];
input >> label >> value;
if (input)
{
sdds::PairSummable<:string std::string> record(label, value);
products += record;
}
} while (input);
input.close();
}
std::cout
for (size_t i = 0; i
std::cout
std::cout
std::cout
std::cout
std::cout
std::cout
std::cout
std::cout
std::cout
}
// Process the second file
// The values in this file will be interpreted as numbers
// Sumation means mathematical addition of numbers.
{
sdds::SetSummable<:pairsummable int>, 25, std::string, int> ticketSales;
// get the data from the file
{
std::ifstream input(argv[2]);
if (!input)
{
std::cerr
return 4;
}
do
{
char ticketType[64];
int number;
input >> ticketType >> number;
if (input)
{
sdds::PairSummable<:string int> record(ticketType, number);
ticketSales += record;
}
} while (input);
input.close();
}
std::cout
for (size_t i = 0; i
std::cout
std::cout
double studentFare = 2.06;
double adultFare = 3.33;
double seniorFare = 2.5;
std::cout
std::cout
std::cout
std::cout
std::cout
}
// done
return 0;
}
#ifndef _SDDS_PAIRSUMMABLE_H
#define _SDDS_PAIRSUMMABLE_H
#include
#include "Pair.h"
namespace sdds
{
template
class PairSummable : public Pair
{
static V m_initialVal;
static size_t m_minField;
public:
static const V& getInitialValue() {
return m_initialVal;
}
PairSummable() {
}
//PairSummable(const K& key, const V& value) :Pair::Pair(key, value) {
// if (m_minField
// m_minField = key.size();
// }
//}
PairSummable(const K& m_m_key, const V& value) : Pair(m_m_key, value)
{
if (m_minField
m_minField = m_m_key.size()+1 ;
}
/* If the m_m_key of the pair stored in the current instance is m_m_key, then
add the value of the pair and val together and return the result.Use + for addition.
Otherwise, return val.*/
V sum(const K& m_m_key, const V& val) const {
if (m_m_key == Pair::key()) {
return Pair::value() + val;
}
else {
return val;
}
}
void display(std::ostream& os) const
{
os.setf(std::ios::left);
os.width(m_minField);
os ::key() ::value()
os.unsetf(std::ios::left);
}
};
template
std::string PairSummable<:string std::string>::m_initialVal = "";
template
int PairSummable<:string int>::m_initialVal = 0;
template
std::string PairSummable<:string std::string>::sum(const std::string& m_m_key, const std::string& val)const {
std::string temp="k";
if (m_m_key == key()) {
temp = value() + val;
}
else {
temp = val;
}
return temp;
}
template
V PairSummable::m_initialVal = 0u;
template
size_t PairSummable::m_minField = 0U;
}
#endif
#ifndef _SDDS_SETSUMMABLE_H
#define _SDDS_SETSUMMABLE_H
#include "Set.h"
namespace sdds {
template
class SetSummable : public Set {
public:
V accumulate(const K& key) {
T get;
V temp= get.getInitialValue();
for (size_t i = 0; i ::size(); i++) {
temp = ((Set&) *this)[i].sum(key, temp);
}
return temp;
}
};
}
#endif
ifndef SDDS_PAIR_H
#define SDDS_PAIR_H
#include
namespace sdds
{
template
class Pair
{
private:
K m_key;
V Value;
public:
Pair() {
}
Pair(const K& key, const V& value) {
m_key = key;
Value = value;
}
const K& key()const {
return m_key;
}
const V& value()const {
return Value;
}
virtual void display(std::ostream& os) const {
os
}
friend std::ostream& operator& pair) {
pair.display(os);
return os;
}
};
}
#endif
#ifndef SDDS_SET_H
#define SDDS_SET_H
namespace sdds
{
template
class Set
{
T m_array[N];
static size_t counter;
public:
Set() {
}
size_t size() const {
return counter;
}
const T& operator[](size_t idx) const {
if (idx
idx = 0;
}
return m_array[idx];
}
void operator+=(const T& item) {
if (counter
m_array[counter] = item;
counter++;
}
}
};
template
size_t Set::counter = 0u;
}
#endif
products.txt
Groceries tomatoes
Electronics computer
Tools hammer
Groceries lettuce
Groceries potatoes
Electronics Multimedia_Player
Electronics HDD
Groceries meat
Tools jigsaw
sales.txt
Student 25
Adult 13
Student 12
Adult 6
Student 5
Adult 15
Adult 1
Adult 2
Adult 3
Student 1
Student 2
Adult 5
Adult 6
output should be like this(see sreenshot) image text in transcribed
image text in transcribed
Sample Output When the program is started with the command (the files are provided): w3.exe products.txt sales.txt the output should look like: Command Line: 1: W3.exe 2: products.txt 3: sales.txt Individual Index Entries Groceries : tomatoes Electronics : computer Tools : hammer Groceries : lettuce Groceries : potatoes Electronics : Multimedia_player Electronics : HDD Groceries : meat Tools : jigsaw Collated Index Entries Tools: hammer, jigsaw Groceries: tomatoes, lettuce, pota Electrnics: Electronics: computer, Multimedia_pl Detail Ticket Sales Student : 25 Groceries : tomatoes Electronics : computer Tools : hammer Groceries : lettuce Groceries : potatoes Electronics : Multimedia_player Electronics : HDD Groceries : meat Tools : jigsaw Collated Index Entries Tools: hammer, jigsaw Groceries: tomatoes, lettuce, pota Electrnics: Electronics: computer, Multimedia_P1 Detail Ticket Sales Student : 25 Adult : 13 Student : 12 Adult : 6 Student : 5 Adult 15 Adult : 1 Adult : 2 Adult : 3 Student : 1 Student : 2 Adult : 5 Adult : 6 Summary of Ticket Sales Student Tickets = Adult Tickets = Senior Tickets = 92.70 169.83 0.00 Sample Output When the program is started with the command (the files are provided): w3.exe products.txt sales.txt the output should look like: Command Line: 1: W3.exe 2: products.txt 3: sales.txt Individual Index Entries Groceries : tomatoes Electronics : computer Tools : hammer Groceries : lettuce Groceries : potatoes Electronics : Multimedia_player Electronics : HDD Groceries : meat Tools : jigsaw Collated Index Entries Tools: hammer, jigsaw Groceries: tomatoes, lettuce, pota Electrnics: Electronics: computer, Multimedia_pl Detail Ticket Sales Student : 25 Groceries : tomatoes Electronics : computer Tools : hammer Groceries : lettuce Groceries : potatoes Electronics : Multimedia_player Electronics : HDD Groceries : meat Tools : jigsaw Collated Index Entries Tools: hammer, jigsaw Groceries: tomatoes, lettuce, pota Electrnics: Electronics: computer, Multimedia_P1 Detail Ticket Sales Student : 25 Adult : 13 Student : 12 Adult : 6 Student : 5 Adult 15 Adult : 1 Adult : 2 Adult : 3 Student : 1 Student : 2 Adult : 5 Adult : 6 Summary of Ticket Sales Student Tickets = Adult Tickets = Senior Tickets = 92.70 169.83 0.00

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Evaluate the importance of diversity in the workforce.

Answered: 1 week ago

Question

Identify the legal standards of the recruitment process.

Answered: 1 week ago