Skip to content
Permalink
434b47eb87
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
77 lines (61 sloc) 2.54 KB
// SandOnABarGraph.cpp : This file contains the 'main' function. Program execution begins and ends there.
// This file is given as a starting point to help you with your coursework :).
// You will want to split this single file into multiple classes, objects and methods fairly early on.
// Author: Chris Bass
// SID: 1234567890
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <sstream>
using namespace std;
int main()
{
cout << "Sand On A Bar Graph Problem Program Title!" << endl;
cout << "Author: Chris Bass" << endl;
cout << "SID: 1234567890" << endl << endl;
// Read input data from .txt file.
// Assumes the data is in a particular format
// Note that immediately after reading each field, we simply write them to the console.
// For the coursework you will want to change this, so that the values are stored
// in some form of temporary data-structure for further processing later on.
// We should be checking for errors in the input file e.g. formatting at every point after a read.
// I.e. read line, check, read line, check... or read field, check, read field, check.
// However, I have only checked for some of the input file reading errors at each point.
ifstream inputFileStream;
inputFileStream.open("bargraph1.txt"); // hardcoded filename, for now...
if (inputFileStream.good())
{
cout << "Input file is good start processing..." << endl << endl;
int bar;
inputFileStream >> bar;
while (!inputFileStream.fail()) // check for failbit
{
cout << bar << "; ";
inputFileStream >> bar;
}
cout << endl;
if (inputFileStream.eof()) {
cout << "Reached the end of file marker. File data read sucessfully." << endl;
}
else {
cout << "Error in input file." << endl;
}
}
else
{
cout << "Error opening input file, ";
cout << "check 'bargraph1.txt' exists in correct directory." << endl;
}
inputFileStream.close();
return 0;
}
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu
// Tips for Getting Started:
// 1. Use the Solution Explorer window to add/manage files
// 2. Use the Team Explorer window to connect to source control
// 3. Use the Output window to see build output and other messages
// 4. Use the Error List window to view errors
// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file