Please use my Lab 3.2 code for this assignment
Lab 4.2 instruction
Using the code from lab 4.1, add the ability to read from a file.
Modify the input function:
* Move the input function out of the Cargo class to just below the end of the Cargo class
* At the bottom of the input function, declare a Cargo object named
temp using the constructor that takes the six parameters.
* Use the Cargo output function to print the Cargo object.
* Call the input function from the main function with no arguments. Remove the rest of the code
from main
3. Create a file and use it for input. This is good because you will be
using the input many times.
* Create a file named cardata4.txt (or use the one provided),
containing the following three lines of data.
If you create your own, make sure to follow the format
below:
Pallet PAG PAG45982IB 737 4978 OAK
Container AYF AYF23409AA 737 2209 LAS
Container AAA AAA89023DL 737 5932 DFW
* All weights are in pounds, don’t worry about kilograms. You may
comment out that code.
* In the input function, declare an object of type ifstream named
inputFile, which we will use to read from the file.
* At the beginning of the code for the input function, open the
file. If the open fails, send a message to stderr and exit the
program.
* In all the reads within the input function, remove the user
prompt and read from the inputFile object, rather than reading
from the stdin object.
* Hint: We need to use getline when reading the strings.
using >> skips leading white space before reading the data.
getline does not skip this leading whitespace. So, before using
getline use the following code:
while(inputFile.peek() == ' ')
inputFile.get();
peek looks at the next character you are about to read. If it is
a space, get is used to read the space character, to get it out
of the way. Your output will then be much neater.
* Use a loop to read each line from the file. To do this use a
while loop including all the reading in the input function, as
well building and output of the Car.
Hint: you can do this with the following while statement:
while(inputFile.peek() != EOF) or use this form while(inputFile >> type)
The peek function will return EOF if there is no next character.
* At the bottom of the input function, close the file.
Put an eye catcher before the beginning of each function, class, and the
global area:
// class name function name comment(if any)
*************************************************
my 3.2 code
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
class item
{
public:
string uid;
string abbrev;
string uluid;
int aircraft;
double weight;
string destination;
void print()
{
cout <<
"UID -- "<< uid << endl;
cout <<
"abbreviation -- " << abbrev << endl;
cout <<
"UID ID -- " << uluid << endl;
cout <<
"Aircraft -- " << aircraft << endl;
cout <<
"Weight -- " << weight << endl;
cout <<
"Destination -- " << destination << endl;
}
friend void
kilotopound(item);
};
void kilotopound(item i)
{
cout <<
"Weight in pound is: " << i.weight * 2.2 << " Pounds"
<< endl;
}
int main()
{
item i;
i.uid = " Container";
i.uluid = "ABB";
i.abbrev = "ABB315451B";
i.aircraft = 737;
i.weight = 1156;
i.destination = "BUR";
item i2(i);
i.print();
kilotopound(i);
cout << " Second Object " << endl;
i2.print();
kilotopound(i2);
return 0;
}
Code:-
#include <iostream>
#include<fstream>
#include<sstream>
#include <cstdlib>
#define MAX 100
using namespace std;
class Cargo
{
string uld;
string abbreviation;
string uldid;
int aircraft;
int weight;
string destination;
bool valid(int no, int min, int max)
{
if(no >= min && no <= max)
return true;
else
return false;
}
public:
Cargo()
{
}
Cargo(string Uld,string abb,string Uldid,int craft, int Weight,
string dest)
{
uld = Uld;
abbreviation = abb;
uldid = Uldid;
aircraft = craft;
weight = Weight;
destination = dest;
}
Cargo(const Cargo &c2)
{
uld = c2.uld;
abbreviation = c2.abbreviation;
uldid = c2.uldid;
aircraft = c2.aircraft;
weight = c2.weight;
destination = c2.destination;
}
friend int kilotopound(Cargo c)
{
return (c.weight * 2.2);
}
void output()
{
cout<<"\n *******************************************";
cout<<"\n\t Unit Load: "<<uld;
cout<<"\n\t Abbreviation: "<<abbreviation;
cout<<"\n\t Unit ID: "<<uldid;
cout<<"\n\t Aircraft Type: "<<aircraft;
cout<<"\n\t Weight: "<<weight;
cout<<"\n\t Destination: "<<destination;
cout<<"\n *******************************************";
}
};
void input()
{
ifstream inputFile;
string line,uld,abb,uldid,dest;
int craft,weight;
inputFile.open("cardata4.txt");
if(!inputFile)
{
cerr << "cannot be opened." << endl;
exit(0);
}
while(inputFile.peek() != EOF)
{
getline(inputFile,line);
stringstream linestream(line);
linestream >> uld >> abb >> uldid >> craft
>> weight >> dest;
Cargo temp(uld,abb,uldid,craft,weight,dest);
temp.output();
}
inputFile.close();
}
int main()
{
cout << "Cargo details from input file ";
input();
return 0;
}
cardata4.txt
Pallet PAG PAG45982IB 737 4978 OAK
Container AYF AYF23409AA 737 2209 LAS
Container AAA AAA89023DL 737 5932 DFW
Code Screenshots:-
Output:-
Please UPVOTE thank you...!!!
Please use my Lab 3.2 code for this assignment Lab 4.2 instruction Using the code from...
Lab 4.1 Utilizing the code from Lab 3.2, add an overloaded operator == which will be used to compare two objects to see if they are equal. For our purposes, two objects are equal if their abbreviation and uldid are the same. You’ll need to make your overloaded operator a friend of the Cargo class. Create a unit1 object and load it with this data: uld – Pallet abbreviation – PAG uldid – PAG32597IB aircraft - 737 weight – 3321...
Lab 5.1 C++ Utilizing the code from Lab 4.2, replace your Cargo class with a new base class. This will be the base for two classes created through inheritance. The Cargo class will need to have virtual functions in order to have them redefined in the child classes. You will be able to use many parts of the new Cargo class in the child classes since they will have the same arguments/parameters and the same functionality. Child class one will...
Hi please help with c++ programming. This is my code. there's a syntax error. PLEASE FIX MY CODE instead of re-designing the program. Thanks /* Description of problem: Introduction to Friends functions. Create objects in the stack (not on the heap) 3.1: Add a friend function, kilotopound, which will convert kilograms to pounds. 3.2: Add a copy constructor utilizing Lab 3.1 code. Copy the fist object using a copy constructor. Output the contents of both objects. */ #include <iostream>...
Please help fix my code C++, I get 2 errors when running. The code should be able to open this file: labdata.txt Pallet PAG PAG45982IB 737 4978 OAK Container AYF AYF23409AA 737 2209 LAS Container AAA AAA89023DL 737 5932 DFW Here is my code: #include <iostream> #include <string> #include <fstream> #include <vector> #include <cstdlib> #include <iomanip> using namespace std; const int MAXLOAD737 = 46000; const int MAXLOAD767 = 116000; class Cargo { protected: string uldtype; string abbreviation; string uldid; int...
CIS 22B Lab 3 Itty Bitty Airfreight (IBA) Topics: Friend functions Copy constructor ----------------------------------------------------------------------------------------------------------------------------------------- Lab 3.1 Utilizing Lab 2.2 code Create your objects in the stack (not on the heap). Add a friend function, kilotopound, which will convert kilograms to pounds. Change your weight mutator to ask whether weight is input in kilograms or pounds. If it is kilograms, call the friend function kilotopound to convert it to pounds and return pounds.There are 2.2 pounds in one kilogram. Create an...
My C++ program is not compiling. Please explain how you fixed with detailed inline comments. I am using Visual Studio 2017. It's a character count program that keeps and displays a count of all the upper, lower case and digits in a .txt file. The requirement is to use classes to implement it. -----------------------------------------------------------------HEADER FILE - Text.h--------------------------------------------------------------------------------------------- /* Header file contains only the class declarations and method prototypes. Comple class definitions will be in the class file.*/ #ifndef TEXT_H #define...
#include<iostream> #include<string> #include<iomanip> using namespace std; /* ********* Class Car ************* ********************************* */ class Car { private: string reportingMark; int carNumber; string kind; bool loaded; string choice; string destination; public: Car() { reportingMark = ""; carNumber = 0; kind = "Others"; loaded = 0; destination = "NONE"; } ~Car() { } void setUpCar(string &reportingMark, int &carNumber, string &kind, bool &loaded, string &destination); }; void input(string &reportingMark, int &carNumber, string &kind, bool &loaded,string choice, string &destination); void output(string &reportingMark, int &carNumber,...
13.5 LAB: Zip code and population (class templates) Define a class StatePair with two template types (T1 and T2), a constructor, mutators, accessors, and a Printlnfo0 method. Three vectors have been pre-filled with StatePair data in main: . vector<StatePair <int, string>> zipCodeState: ZIP code - state abbreviation pairs . vector<StatePair<string, string>> abbrevState: state abbreviation - state name pairs • vector<StatePair<string, int>> statePopulation: state name - population pairs Complete mainO to use an input ZIP code to retrieve the correct state abbreviation from the vector zipCodeState. Then use...
IP requirements: Load an exam Take an exam Show exam results Quit Choice 1: No functionality change. Load the exam based upon the user's prompt for an exam file. Choice 2: The program should display a single question at a time and prompt the user for an answer. Based upon the answer, it should track the score based upon a successful answer. Once a user answers the question, it should also display the correct answer with an appropriate message (e.g.,...
I keep getting errors and i am so confused can someone please help and show the input and output ive tried so many times cant seem to get it. main.cpp #include <iostream> #include <vector> #include <string> #include "functions.h" int main() { char option; vector<movie> movies; while (true) { printMenu(); cin >> option; cin.ignore(); switch (option) { case 'A': { string nm; int year; string genre; cout << "Movie Name: "; getline(cin, nm); cout << "Year: "; cin >> year; cout << "Genre: "; cin >> genre; //call you addMovie() here addMovie(nm, year, genre, &movies); cout << "Added " << nm << " to the catalog" << endl; break; } case 'R': { string mn; cout << "Movie Name:"; getline(cin, mn); bool found; //call you removeMovie() here found = removeMovie(mn, &movies); if (found == false) cout << "Cannot find " << mn << endl; else cout << "Removed " << mn << " from catalog" << endl; break; } case 'O': { string mn; cout << "Movie Name: "; getline(cin, mn); cout << endl; //call you movieInfo function here movieInfo(mn, movies); break; } case 'C': { cout << "There are " << movies.size() << " movies in the catalog" << endl; // Call the printCatalog function here printCatalog(movies); break; } case 'F': { string inputFile; bool isOpen; cin >> inputFile; cout << "Reading catalog info from " << inputFile << endl; //call you readFromFile() in here isOpen = readFile(inputFile, &movies); if (isOpen == false) cout << "File not found" << endl;...