Question

In: Computer Science

C++ The txt file is not showing up in my output #include <iostream> #include <fstream> #include...

C++

The txt file is not showing up in my output

#include <iostream>
#include <fstream>
#include <string>
#include "Classroom.h"


using namespace std;

Classroom myLib;

void loadDataset(string fileName) 
{
        ifstream myFile;
        myFile.open(fileName.c_str());
}


void continueMessage(string message) {
        cout << message << endl;
        cout << "Press Enter to continue.." << endl; cin.get();
}

int main() 
{       
        
        string fileName = "dataset.txt";
        loadDataset(fileName);

        myLib.print();
        continueMessage;

        string ID = "Janet Newman";
        myLib.removeStudent (ID);
        continueMessage("Janet Newman has been removed.");
        //---------------------------------------------------------------------------
        myLib.print();
        continueMessage("All students are listed!");

        return 0;
}

Solutions

Expert Solution

There is a minor mistake, you forget to read data from the file in LoadDataset() function, I commented there so just add code to read the file then it will work nicely,

PLEASE GIVE THUMBS UP, THANKS

CODE:

#include <iostream>
#include <fstream>
#include <string>
#include "Classroom.h"

using namespace std;

Classroom myLib;

void loadDataset(string fileName)
{
ifstream myFile;
myFile.open(fileName.c_str());
//The txt file not showing up in your output because, you are not reading the data from file, you just opened the input file in read mode but you are not reading.
//So read your input file into myLib object from file, then only use myLib object to print.

}


void continueMessage(string message) {
cout << message << endl;
cout << "Press Enter to continue.." << endl; cin.get();
}

int main()
{   
  
string fileName = "dataset.txt";
loadDataset(fileName);

myLib.print();
continueMessage;

string ID = "Janet Newman";
myLib.removeStudent (ID);
continueMessage("Janet Newman has been removed.");
//---------------------------------------------------------------------------
myLib.print();
continueMessage("All students are listed!");

return 0;
}


Related Solutions

Add Bubble Sorting & Binary Search Functions to the following code (C++) #include<iostream> #include<fstream> #include<string> #include<iomanip>...
Add Bubble Sorting & Binary Search Functions to the following code (C++) #include<iostream> #include<fstream> #include<string> #include<iomanip> #include<algorithm> using namespace std; const int row = 10; const int col = 7;   ifstream name; ifstream grade; ofstream out; void readData(string stname[row], int stgrade[row][col]); void stsum(int stgrade[row][col], int total[row]); void staverage(int total[row], double average[row]); void stlettergrade(double average[row],char ltrgrade[row]); void displayData(string stname[row], int stgrade[row][col], int total[row], double staverage[row], char ltrgrade[row]); void swapltrgrade(char* xp, char* yp); int main() {    int STG[row][col] = { {0},{0}...
#include <iostream> #include <string> #include <fstream> #include <vector> #include <sstream> using namespace std; int main() {...
#include <iostream> #include <string> #include <fstream> #include <vector> #include <sstream> using namespace std; int main() { ifstream infile("worldpop.txt"); vector<pair<string, int>> population_directory; string line; while(getline(infile, line)){ if(line.size()>0){ stringstream ss(line); string country; int population; ss>>country; ss>>population; population_directory.push_back(make_pair(country, population)); } } cout<<"Task 1"<<endl; cout<<"Names of countries with population>=1000,000,000"<<endl; for(int i=0;i<population_directory.size();i++){ if(population_directory[i].second>=1000000000){ cout<<population_directory[i].first<<endl; } } cout<<"Names of countries with population<=1000,000"<<endl; for(int i=0;i<population_directory.size();i++){ if(population_directory[i].second<=1000000){ cout<<population_directory[i].first<<endl; } } } can u pls explain the logic behind this code up to 10 lines pls, many thanks
*****MUST ONLY USE****** #include <iostream> #include <fstream> #include <string.h> #include <stdio.h> Description The word bank system...
*****MUST ONLY USE****** #include <iostream> #include <fstream> #include <string.h> #include <stdio.h> Description The word bank system maintains all words in a text file named words.txt. Each line in the text file stores a word while all words are kept in an ascending order. You may assume that the word length is less than 20. The system should support the following three functions: Word lookup: to check whether a given word exists in the word bank. Word insertion: to insert a...
C++ code Why my code is not compiling? :( #include <iostream> #include <iomanip> #include <string> using...
C++ code Why my code is not compiling? :( #include <iostream> #include <iomanip> #include <string> using namespace std; const int CWIDTH = 26; int main() {    int choice;    double convertFoC, converCtoF;    double starting, endvalue, incrementvalue;    const int CWIDTH = 13;    do {       cin >> choice;    switch (choice)    {        cin >> starting;    if (starting == 28){       cout << "Invalid range. Try again.";    }    while (!(cin >> starting)){       string  garbage;       cin.clear();       getline(cin, garbage);       cout << "Invalid data Type, must be a number....
#include <iostream> #include <fstream> #include <string> using namespace std; const int QUIZSIZE = 10; const int...
#include <iostream> #include <fstream> #include <string> using namespace std; const int QUIZSIZE = 10; const int LABSIZE = 10; const int PROJSIZE = 3; const int EXAMSIZE = 3; float getAverage(float arr[], int size) { float total = 0; for (int i = 0; i < size; i++) { total += arr[i]; } return total/size; } // the following main function do.... int main() { ifstream dataIn; string headingLine; string firstName, lastName; float quiz[QUIZSIZE]; float lab[LABSIZE]; float project[PROJSIZE]; float midExam[EXAMSIZE];...
Complete the following program #include<iostream> #include<iomanip> #include<fstream> using namespace std; int main() { // I -...
Complete the following program #include<iostream> #include<iomanip> #include<fstream> using namespace std; int main() { // I - Declaring a five by five array /* II - Read data from data.txt and use them to create the matrix in the previous step*/    // III - Count and print the number of even integers in the matrix. /* IV - Calculate and print the sum of all integers in the columns with an even index value. Please note the column index begins...
Array based application #include <iostream> #include <string> #include <fstream> using namespace std; // Function prototypes void...
Array based application #include <iostream> #include <string> #include <fstream> using namespace std; // Function prototypes void selectionSort(string [], int); void displayArray(string [], int); void readNames(string[], int); int main() {    const int NUM_NAMES = 20;    string names[NUM_NAMES];    // Read the names from the file.    readNames(names, NUM_NAMES);    // Display the unsorted array.    cout << "Here are the unsorted names:\n";    cout << "--------------------------\n";    displayArray(names, NUM_NAMES);    // Sort the array.    selectionSort(names, NUM_NAMES);    //...
C++ and Java Zoo File Manager I need to complete these files: #include <iostream> #include <jni.h>...
C++ and Java Zoo File Manager I need to complete these files: #include <iostream> #include <jni.h> using namespace std; void GenerateData() //DO NOT TOUCH CODE IN THIS METHOD { JavaVM *jvm; // Pointer to the JVM (Java Virtual Machine) JNIEnv *env; // Pointer to native interface //================== prepare loading of Java VM ============================ JavaVMInitArgs vm_args; // Initialization arguments JavaVMOption* options = new JavaVMOption[1]; // JVM invocation options options[0].optionString = (char*) "-Djava.class.path="; // where to find java .class vm_args.version = JNI_VERSION_1_6;...
#include <iostream> #include <fstream> #include <vector> using namespace std; struct Point{ int x, y; bool operator==(const...
#include <iostream> #include <fstream> #include <vector> using namespace std; struct Point{ int x, y; bool operator==(const Point& p2) { return this->x == p2.x and this->y == p2.y; } bool operator!=(const Point& p2) { return this->x != p2.x or this->y != p2.y; } friend ostream &operator<<( ostream &out, const Point &P ) { out << "(" << P.x << ", " << P.y << ")"; return out; } friend istream &operator>>( istream &in, Point &P ) { char d1, d2, d3;...
Please in C++, show screenshots of output plus .txt file. thanks Breakfast Billing System Write a...
Please in C++, show screenshots of output plus .txt file. thanks Breakfast Billing System Write a program to help a local restaurant automate its breakfast billing system. The program should do the following: Show the customer the different breakfast items offered by the restaurant. Allow the customer to select more than one item from the menu. Calculate and print the bill Assume that the restaurant offers the following breakfast items (the price of each item is shown to the right...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT