Question: I need help with removing an empty line from my code and i don't know how too. Under I will post the code I have
I need help with removing an empty line from my code and i don't know how too. Under I will post the code I have along with the output that I have vs the output i need. Cstring.h is just used for str functions so its not necessary to include here
My output
==124122== Memcheck, a memory error detector ==124122== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. ==124122== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info ==124122== Command: ws ==124122== EmptyOne1 EmptyOne2 /----------------------------------------\ | | | Professor's Label Maker Program Tester | | | \----------------------------------------/ Enter the follwing information: # of Labels > 6 1> Applied Problem Solving 2> Computer Principles for Programmers 3> Communicating Across Contexts (Enriched) 4> Introduction to Programming Using C 5> Introduction to UNIX/Linux and the Internet 6> Computer Programming and Analysis, Co-op (Work-Integrated Learning option only) Number of labels to create: 6 Enter 6 labels: Enter label number 1 > Applied Problem Solving Enter label number 2 > Computer Principles for Programmers Enter label number 3 > Communicating Across Contexts (Enriched) Enter label number 4 > Introduction to Programming Using C Enter label number 5 > Introduction to UNIX/Linux and the Internet Enter label number 6 > Computer Programming and Analysis, Co-op (Work-Integrated Learning option only) +-------------------------+ | | | Applied Problem Solving | | | +-------------------------+ +-------------------------------------+ | | | Computer Principles for Programmers | | | +-------------------------------------+ +------------------------------------------+ | | | Communicating Across Contexts (Enriched) | | | +------------------------------------------+ +-------------------------------------+ | | | Introduction to Programming Using C | | | +-------------------------------------+ +---------------------------------------------+ | | | Introduction to UNIX/Linux and the Internet | | | +---------------------------------------------+ +------------------------------------------------------------------------+ | | | Computer Programming and Analysis, Co-op (Work-Integrated Learning opt | | | +------------------------------------------------------------------------+ ==124122== ==124122== HEAP SUMMARY: ==124122== in use at exit: 0 bytes in 0 blocks ==124122== total heap usage: 9 allocs, 9 frees, 73,147 bytes allocated ==124122== ==124122== All heap blocks were freed -- no leaks are possible ==124122== ==124122== For lists of detected and suppressed errors, rerun with: -s ==124122== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) Script done, file is student_output.txt Checking output: In line number 17 of your output: The output should be: Enter the follwing information: ^ But your output is: ^ Unmatched character details: The character in column 2 is supposed to be: [E] ASCII code(69) but you printed [Empty Line] ASCII code(0) Outputs don't match. Submission aborted! The correct output
Script started on Sat 06 Feb 2021 09:38:00 AM EST ==67026== Memcheck, a memory error detector ==67026== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. ==67026== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info ==67026== Command: ws ==67026== EmptyOne1 EmptyOne2 /----------------------------------------\ | | | Professor's Label Maker Program Tester | | | \----------------------------------------/ Enter the follwing information: # of Labels > 6 1> Applied Problem Solving 2> Computer Principles for Programmers 3> Communicating Across Contexts (Enriched) 4> Introduction to Programming Using C 5> Introduction to UNIX/Linux and the Internet 6> Computer Programming and Analysis, Co-op (Work-Integrated Learning option only) Number of labels to create: 6 Enter 6 labels: Enter label number 1 > Applied Problem Solving Enter label number 2 > Computer Principles for Programmers Enter label number 3 > Communicating Across Contexts (Enriched) Enter label number 4 > Introduction to Programming Using C Enter label number 5 > Introduction to UNIX/Linux and the Internet Enter label number 6 > Computer Programming and Analysis, Co-op (Work-Integrated Learning option only) +-------------------------+ | | | Applied Problem Solving | | | +-------------------------+ +-------------------------------------+ | | | Computer Principles for Programmers | | | +-------------------------------------+ +------------------------------------------+ | | | Communicating Across Contexts (Enriched) | | | +------------------------------------------+ +-------------------------------------+ | | | Introduction to Programming Using C | | | +-------------------------------------+ +---------------------------------------------+ | | | Introduction to UNIX/Linux and the Internet | | | +---------------------------------------------+ +------------------------------------------------------------------------+ | | | Computer Programming and Analysis, Co-op (Work-Integrated Learning opt | | | +------------------------------------------------------------------------+ ==67026== ==67026== HEAP SUMMARY: ==67026== in use at exit: 0 bytes in 0 blocks ==67026== total heap usage: 9 allocs, 9 frees, 73,147 bytes allocated ==67026== ==67026== All heap blocks were freed -- no leaks are possible ==67026== ==67026== For lists of detected and suppressed errors, rerun with: -s ==67026== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) Here are my files:
LabelMaker.cpp
#include #include #include #include "cstring.h" // using strLen, strCpy and strCmp #include "LabelMaker.h" using namespace std; namespace sdds { LabelMaker::LabelMaker(int noOfLabels) { // creates a dynamic array of Labels to the size of noOfLabels m_noOfLabels = noOfLabels; m_labels = new Label[m_noOfLabels]; } void LabelMaker::readLabels() { // Gets the contents of the Labels as // demonstrated in the Execution sample cout << "Enter " << m_noOfLabels << " labels:" << endl; for (int i = 0; i < m_noOfLabels; i++) { cout << "Enter label number " << (i + 1) << endl; cout << "> "; m_labels[i].readLabel(); } } void LabelMaker::printLabels() { // Prints the Labels as demonstrated in the Execution sample for (int i = 0; i < m_noOfLabels; i++) { m_labels[i].printLabel() << endl; } } LabelMaker::~LabelMaker() { // Deallocates the memory when LabelMaker goes out of scope. delete[] m_labels; } } LabelMaker.h
#pragma once #ifndef SDDS_LABELMAKER_H_ #define SDDS_LABELMAKER_H_ #include "Label.h" namespace sdds { class LabelMaker { Label* m_labels; int m_noOfLabels; public: LabelMaker(int noOfLabels); void readLabels(); void printLabels(); ~LabelMaker(); }; } #endif // SDDS_LABELMAKER_H_ Label.cpp #include #include #include #include "Label.h" #include #define SDDS_DEBUG using namespace std; namespace sdds { void Label::setToDefault() { m_label = nullptr; m_frame[0] = 0; } void Label::setLable(const char *theLable) { delete[] m_label; m_label = nullptr; int maxLen = 70; int len = (size_t) strlen(theLable) > (size_t) maxLen ? maxLen : strlen(theLable); m_label = new char[len + 1]; strncpy(m_label, theLable, len); m_label[len] = 0; } void Label::setFrame(const char *theFrame) { //m_frame[0] = 0; strcpy(m_frame, theFrame); m_frame[8] = 0; } Label::Label() { setToDefault(); setFrame("+-+|+-+|"); } Label::Label(const char *frameArg) { setToDefault(); setFrame(frameArg); } Label::Label(const char *frameArg, const char *content) { setToDefault(); setFrame(frameArg); setLable(content); } Label::~Label() { delete[] m_label; m_label = nullptr; } void Label::readLabel() { char inputLabel[71]; cin.getline(inputLabel, 71); setLable(inputLabel); } std::ostream & Label::printLabel() const { if (m_label) { int len = (size_t) strlen(m_label) + 3; cout << m_frame[0] << setw(len) << setfill(m_frame[1]) << m_frame[2] << endl; //A cout << m_frame[7] << setw(len) << setfill(' ') << m_frame[3] << endl; //h d cout << m_frame[7] << ' ' << m_label << ' ' << m_frame[3] << endl; //h d cout << m_frame[7] << setw(len) << setfill(' ') << m_frame[3] << endl; //h d cout << m_frame[6] << setw(len) << setfill(m_frame[5]) << m_frame[4] << endl; //A } return cout; } } Label.h #ifndef SDDS_BOX_H #define SDDS_BOX_H #include // The label class creates a label by drawing a // frame around a one - line text with an unknown // size(maximum of 70 chars, must be kept dynamically). namespace sdds { class Label { char * m_label; char m_frame[9]; public: void setToDefault(); void setLable(const char * theLable); void setFrame(const char * theFrame); Label(); Label(const char * frameArg); Label(const char * frameArg, const char * content); ~Label(); void readLabel(); std::ostream & printLabel() const; }; } #endif // !SDDS_BOX_H
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
