Question

Hi please help with c++ programming.

CIS 22B Lab 3 Itty Bitty Airfreight (IBA) 200 Points Topics: Friend functions Copy constructor Lab 3.1 Create your objects in

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>
#include <string>
using namespace std;

// class to define the parameters of the load;

class load

{

//private members
private:
string uId;
string abbreviation;
string uldid;
string aircraft;
double weight;
string destination;

//public functions
public:

//default constructor

//doesn't require any function body

load()

{

;

}

//copy constructor
load(const load &l);

//mutator function
void input();

//this function prints the elements in object
void output();

//friend function to convert kilo to pounds SOLUTION TO LAB 3.1
friend void kilotopound(load &l);

};

/******************************* main ****************************************/

int main ()
{

load container;
container.input(); // Calling separate function for taking input.
container.output(); // Calling separate function for displaying output.

//defining a new object on stack
//using copy constructor
load obj2(container);
cout << "\n\nobject 2 made using copy constructor: ";

//output second object
obj2.output();

return 0;

}

//copy constructor definintion
   load::load(const load &l)

{
uId = l.uId;
abbreviation = l.abbreviation;
uldid = l.uldid;
aircraft = l.aircraft;
weight = l.weight;
destination = l.destination;
}

/**************************** Input ******************************

Read all the data from the user.

After all the data has been read, put all this data into the object.

*/

void load::input()
{

string x="";
double w=0;
char ch;
cout<<"Enter uId: "; cin>>x;
this->uId = x;
cout<<"Enter abbreviation: "; cin>>x;
this->abbreviation = x;
cout<<"Enter uldid: "; cin>>x;
this->uldid = x;
cout<<"Enter aircraft: "; cin>>x;
this->aircraft = x;
cout<<"Enter weight: "; cin>>w;
cout << "Is this weight in kilograms? (y/n): ";
cin >> ch;
this->weight = w;
cout<<"Enter destination: "; cin>>x;
this->destination = x;

//if the user wants weight to be converted to pounds
//call kilotopound and pass the current object

if(ch == 'y' || ch == 'Y')
kilotopound(*this);

}

/******************************** Output ********************************
Print the data in a neat format
*/

void load::output()
{
cout<<"\nuId:"<< uId ;
cout<<"\nabbreviation: " << abbreviation;
cout<<"\nuldid: " << uldid;
cout<<"\naircraft: " << aircraft;
cout<<"\nweight: " << weight;
cout<<"\ndestination: " << destination;
}

//friend function of load class
  
//it accepts an object of type load

//and converts its weight member to

//weight in pounds

void kilotopound(load &l)

{

l.weight = l.weight * 2.2;

/* Execution Results
LAB 3.1 SOLUTION
Enter uId: Container
Enter abbreviation: AYK   
Enter uldid: AYK68943IB   
Enter aircraft: 737   
Enter weight: 1654
Is this weight in kilograms? (y/n): y   
Enter destination: PDX

uId:Container   
abbreviation: AYK   
uldid: AYK68943IB   
aircraft: 737   
weight: 3638.8
destination: PDX

LAB 3.2 SOLUTION
Enter uId: Container
Enter abbreviation: ABB   
Enter uldid: ABB31545IB   
Enter aircraft: 737   
Enter weight: 1156
Is this weight in kilograms? (y/n): y   
Enter destination: BUR

uId:Container   
abbreviation: ABB   
uldid: ABB31545IB   
aircraft: 737   
weight: 2543.2
destination: BUR

object 2 made using copy constructor:   
uId:Container   
abbreviation: ABB   
uldid: ABB31545IB   
aircraft: 737   
weight: 2543.2
destination: BUR


...Program finished with exit code 0   
Press ENTER to exit console.   
*/

0 0
Add a comment Improve this question Transcribed image text
Answer #1
  • there is a missing } at the end of the kilotopound() funciton definition.
  • That is the only error, the program runs perfectly once that modified.

Modified program:

  • Note: the only change being is made is a } bracket being added at the end of the program

#include <iostream>
#include <string>
using namespace std;

// class to define the parameters of the load;

class load

{

//private members
private:
string uId;
string abbreviation;
string uldid;
string aircraft;
double weight;
string destination;

//public functions
public:

//default constructor

//doesn't require any function body

load()

{
;
}

//copy constructor
load(const load &l);

//mutator function
void input();

//this function prints the elements in object
void output();

//friend function to convert kilo to pounds SOLUTION TO LAB 3.1
friend void kilotopound(load &l);

};

/******************************* main ****************************************/

int main ()
{

load container;
container.input(); // Calling separate function for taking input.
container.output(); // Calling separate function for displaying output.

//defining a new object on stack
//using copy constructor
load obj2(container);
cout << "\n\nobject 2 made using copy constructor: ";

//output second object
obj2.output();

return 0;

}

//copy constructor definintion
load::load(const load &l)

{
uId = l.uId;
abbreviation = l.abbreviation;
uldid = l.uldid;
aircraft = l.aircraft;
weight = l.weight;
destination = l.destination;
}

/**************************** Input ******************************

Read all the data from the user.

After all the data has been read, put all this data into the object.

*/

void load::input()
{

string x="";
double w=0;
char ch;
cout<<"Enter uId: "; cin>>x;
this->uId = x;
cout<<"Enter abbreviation: "; cin>>x;
this->abbreviation = x;
cout<<"Enter uldid: "; cin>>x;
this->uldid = x;
cout<<"Enter aircraft: "; cin>>x;
this->aircraft = x;
cout<<"Enter weight: "; cin>>w;
cout << "Is this weight in kilograms? (y/n): ";
cin >> ch;
this->weight = w;
cout<<"Enter destination: "; cin>>x;
this->destination = x;

//if the user wants weight to be converted to pounds
//call kilotopound and pass the current object

if(ch == 'y' || ch == 'Y')
kilotopound(*this);

}

/******************************** Output ********************************
Print the data in a neat format
*/

void load::output()
{
cout<<"\nuId:"<< uId ;
cout<<"\nabbreviation: " << abbreviation;
cout<<"\nuldid: " << uldid;
cout<<"\naircraft: " << aircraft;
cout<<"\nweight: " << weight;
cout<<"\ndestination: " << destination;
cout<<"\n";
}

//friend function of load class
  
//it accepts an object of type load

//and converts its weight member to

//weight in pounds

void kilotopound(load &l)

{

l.weight = l.weight * 2.2;
}

sample input and output:

Enter uId: 3452 Enter abbreviation: ghf Enter uldid: 2424424 Enter aircraft: flyemrt Enter weight: 2352.43 Is this weight in

Add a comment
Know the answer?
Add Answer to:
Hi please help with c++ programming. This is my code. there's a syntax error. PLEASE FIX...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • CIS 22B Lab 3 Itty Bitty Airfreight (IBA) Topics: Friend functions Copy constructor ----------------------------------------------------------------------------------------------------------------------------------------- Lab 3.1...

    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...

  • Lab 4.1 Utilizing the code from Lab 3.2, add an overloaded operator == which will be...

    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...

  • Please use my Lab 3.2 code for this assignment Lab 4.2 instruction Using the code from...

    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...

  • Lab 5.1 C++ Utilizing the code from Lab 4.2, replace your Cargo class with a new...

    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...

  • Please help fix my code C++, I get 2 errors when running. The code should be...

    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...

  • Hi, I need some help with the following question. I need the answer in Python please....

    Hi, I need some help with the following question. I need the answer in Python please. 10.23 LAB: Warm up: People's weights (Lists) (1) Prompt the user to enter four numbers, each corresponding to a person's weight in pounds. Store all weights in a list. Output the list. (2 pts) Ex: Enter weight 1: 236.0 Enter weight 2: 89.5 Enter weight 3: 176.0 Enter weight 4: 166.3 Weights: [236.0, 89.5, 176.0, 166.3] (2) Output the average of the list's elements...

  • c++ Please help! i keep getting an error message. I think my main problem is not...

    c++ Please help! i keep getting an error message. I think my main problem is not understanding the circle calculations function and how both the area and the circumference is returned from the function. I know & needs to be used, but I am unsure how to use it. Copy the following code and run it. You should break it into the following 3 functions getValidinput - which asks the user to enter the radius and then make sure that...

  • Need help doing program In bold is problem E2 #include<iostream> #include<string> #include<vector> using namespace std; //Car...

    Need help doing program In bold is problem E2 #include<iostream> #include<string> #include<vector> using namespace std; //Car class //Defined enum here enum Kind{business,maintenance,other,box,tank,flat,otherFreight,chair,seater,otherPassenger}; //Defined array of strings string KIND_ARRAY[]={"business","maintenance","other,box","tank,flat","otherFreight","chair","seater","otherPassenger"}; class Car { private: string reportingMark; int carNumber; Kind kind; //changed to Kind bool loaded; string destination; public: //Defined setKind function Kind setKind(string knd) { for(int i=0;i<8;i++) //repeat upto 8 kinds { if(knd.compare(KIND_ARRAY[i])==0) //if matched in Array kind=(Kind)i; //setup that kind } return kind; } //Default constructor Car() { } //Parameterized constructor...

  • In this lab, you will need to implement the following functions in Text ADT with C++...

    In this lab, you will need to implement the following functions in Text ADT with C++ language(Not C#, Not Java please!): PS: The program I'm using is Visual Studio just to be aware of the format. And I have provided all informations already! Please finish step 1, 2, 3, 4. Code is the correct format of C++ code. a. Constructors and operator = b. Destructor c. Text operations (length, subscript, clear) 1. Implement the aforementioned operations in the Text ADT...

  • I need help with this C++ problem so far my algorithm is looking like this. #include...

    I need help with this C++ problem so far my algorithm is looking like this. #include using namespace std; void input(char fullname[35], int weight, int distance); double totalcharges(); main() { char fullname[35]; int weight; int distance; for(int i = 1; i <= 3; i++) {   input(fullname, weight, distance); } } void input(char fullname[35], int weight, int distance) { char f[35]; //full name int w; // weight int d; // distance cout << "What is your full name? Please enter `...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT