I am in need of some help pretty badly on a intro c++ program. please only do th
ID: 3859754 • Letter: I
Question
I am in need of some help pretty badly on a intro c++ program. please only do this if you can complete the whole assignment.
//////Template to go by
#include <iostream>
#include <ostream>
#include <istream>
#include <ostream>
#include <fstream>
#include <sstream>
#include <string>
#include <iomanip>
bool GetInputFileStream(std::ifstream * fin, std::string filename);
void GetOutputFileStream(std::ofstream * fout, std::string filename);
void SetGetPointer(std::istream & fin, int location);
void SetPutPointer(std::ostream & fout, int location);
void AnalyzeFile(std::istream & fin,
int & numUsed,
int & numNew,
double & newTotalPrice,
double & newTotalMileage,
double & usedTotalPrice,
double & usedTotalMileage);
void PrintLine(std::ostream & sout, std::string s);
void PrintNew(std::istream & fin, std::ostream & fout);
void PrintUsed(std::istream & fin, std::ostream & fout);
void PrintStatistics(std::ostream & fout,
int numUsed,
int numNew,
double newTotalPrice,
double newTotalMileage,
double usedTotalPrice,
double usedTotalMileage);
std::string FormatCarInfo(std::string year,
std::string make,
std::string model,
double price,
double mileage);
// DO NOT REMOVE THESE COMMENTS -- these comments are actually
// commands to the assessment tool.
//@include(main)
//@addRule(commentAll)
int main()
{
// You will need to put the provided cars.txt into
// the working directory of this program
std::string filename = "cars.txt";
std::ifstream fin;
bool isOpen = GetInputFileStream(&fin, filename);
if (isOpen == false)
{
std::cout << "Couldn't find file " << filename << "!" << std::endl;
}
else
{
double newTotalPrice = 0;
double newTotalMileage = 0;
double usedTotalPrice = 0;
double usedTotalMileage = 0;
int numUsed = 0;
int numNew = 0;
AnalyzeFile(fin, numUsed, numNew, newTotalPrice, newTotalMileage,
usedTotalPrice, usedTotalMileage);
PrintStatistics(std::cout, numUsed, numNew, newTotalPrice, newTotalMileage,
usedTotalPrice, usedTotalMileage);
}
// Now work on tests to make sure the rest of your functions work properly
std::cout << "Press ENTER to continue";
std::cin.get();
return 0;
}
// DO NOT REMOVE THESE COMMENTS -- these comments are actually
// commands to the assessment tool.
//@removeRule(commentAll)
// The function prototypes are provided above
// Copy them here, remove the semicolons at the end
// Add braces, and fill in the functionality
/////////////////////////////////////////// This is the first paragraph in pdf.......
This assignment will introduce you to the capabilities of streams. We are mainly concerned with file streams but there are a couple of others worth noting as well. Strangely enough, you already know everything you need to know about them. You have been using them this entire semester since the very first assignment. Do you recall reading about cin and cout streams? Behind the scenes, cin and cout take care of a lot complicated things. For example, when you send cout a string (i.e. cout << “My string!”) it’s pretty obvious what needs to happen. Cout formats your string into its ASCII representation and makes it appear in the console. What about integers and doubles, though? Under the covers, cout converts your digits to ASCII and prints them as well. In this assignment, instead of sending all of our input to a console input or output (cin and cout, respectively), we will be sending it to either a ‘string’ stream or a ‘file’ stream. The difference now is that the information you send to the stream will show up either inside of a string or a file.
//////////////////////////////////////////////////////////////////////////////////////
now the rest is the break down of sample tests and the outputs, outputs have to say what he wants it to is how i took it.
------>>>>> It provides the function prototypes for you. The assignment is to create and fill the functions with the necessary logic.
Another file named cars.txt is provided for you to test with. The format of the file is as follows:
[year] [make] [model] [price] [mileage] [category]
I have 3 txt files that come with this (below), and a pdf walkthrough.
Notes and Hints
1. Use the main() function provided in the template to develop any tests you think are necessary.
////////////////////////////////////////////////stats.txt
Category| Number| Total Price| Total Mileage|
New| 1| 33000| 250|
Used| 2| 7000| 254000|
///////////////////////////////////////////car.txt
1999 Ford Ranger 3000 156000 used
2000 Mazda Miata 4000 98000 used
2015 Jeep Wrangler 33000 250 new
///////////////////////new.txt
2015 Jeep Wrangler 33000 250
///////////////////////////////
Basically its a make a file and then his auto compiler tests to see if it can be opened and then read from and I'm assuming have ability to alter the info in the file once its saved......
Explanation / Answer
#include<iostream.h>
#include<fstream.h>
#include<conio.h>
#include<stdlib.h>
class student
{
char name[20];
char grade;
float marks;
public:
void getdata(void);
void display(void);
};
void student::getdata(void)
{
char ch;
cincountt.get(ch);
countt<<"Enter name: ";
cin.getline(name, 20);
countt<<"Enter grade: ";
cin>>grade;
countt<<"Enter marks: ";
cin>>marks;
countt<<" ";
}
void student::display(void)
{
countt<<"Name: "<<name<<" Grade: "<<grade<<" Marks: "<<marks<<" ";
}
void main()
{
clrscr();
char fname[20];
student cse[3]; // declare array of 3 objects
fstream fio; // input and output file
countt<<"Enter file name: ";
cin.get(fname, 20);
fio.open(fname, ios::in || ios::out);
if(!fio)
{
countt<<"Error occurred in opening the file..!! ";
countt<<"Press any key to exit... ";
getch();
exit(1);
}
countt<<"Enter details for 3 students: ";
for(int i=0; i<3; i++)
{
cse[i].getdata();
fio.write((char *)&cse[i], sizeof(cse[i]));
}
fio.seekg(0); /* seekg(0) resets the file to start, to access the file
* from the beginning */
countt<<"The content of "<<fname<<" file are shown below: ";
for(i=0; i<3; i++)
{
fio.read((char *)&cse[i], sizeof(cse[i]));
cse[i].display();
}
fio.close();
countt<<" Press any key to exit... ";
getch();
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.