Computer Science-C++ Programming Check
Sadikshya Shrestha
Prof George Driscoll
COSC 1436-71701
14 November 2021
COSC-1436, Lab Assignment 11
Submit your answers to the following questions in a word processing document that is compatible with Microsoft Word. The name of the file you submit should be “XYLab11”, where “X” and “Y” are your first and last initials.
Questions (50 points):
1. Given the following C++ code:
struct Address
{
int houseNumber;
string streetName;
string city;
string state;
int zip;
};
Address location1;
Write the C++ code that would display the house number and street name for the location1 occurrence of the Address structure.
using namespace std;
#include<iostream>
//Address structure
struct Address
{
int houseNumber; //house number
string streetName; //street name
string city; //city name
string state; //state name
int zip; //zip code
};
//driver code
int main()
{
//structure variable
Address location1;
//take input from user
cout<<"Enter the house number : ";
cin>>location1.houseNumber;
cout<<"Enter the street Name : ";
cin>>location1.streetName;
//print information
cout<<"Address is \n The house number : " <<location1.houseNumber;
cout<<"\nThe street name : "<<location1.streetName;
}
2. Write a C++ definition statement that defines a structure named Plane
that contains the following members:
• manufacturer : (string)
• model : (string)
• engineType : (string)
• numEngines : (integer)
• grossWeight : (double)
struct Plane{
string manufacturer;
string model;
string engineType;
int numEngines;
double grossWeight;
};
3. Given the following C++ code:
struct Panel
{
double length;
double width;
double xPosition;
double yPosition;
string backgroundColor;
bool isFilled;
};
Write the C++ programming statements that will assign the color “salmon1” to the backgroundColor member of a Panel structure named section4.
Panel section4;
section4.backgroundColor="salmon1";
4. Given the following C++ code:
struct RetailItem
{
string sku; // Stock Keeping Unit
string name; // Description
int quantity; // Quantity on hand
double unitCost; // Unit value in dollars
};
RetailItem inventory[20];
Write the C++ programming statement that will assign the value 638 to the quantity member of the fourth entry in the array of RetailItem structures named inventory.
RetailItem inventory[20];
inventory[3].quantity=638;
5. The sku for the retail item named Hammer is 34598. This retail item has a quantity of 542 and a unit value of $34.89. Using the RetailItem structure and array definition in question 4, write the C++ statements necessary to load the second entry in the array of RetailItem structures called inventory with the Hammer member values.
inventory[1].name = "Hammer";
inventory[1].sku = "34598";
inventory[1].quantity = 542;
inventory[1].unitCost = 34.89;
Programming Exercise (50 points):
Flight Tracker
Commercial airliners record four events for each flight:
• Out is the time brakes are released and the airplane begins to move for the purpose of flight.
• Off is the time weight is removed from the landing gear indicating that the airplane has taken off.
• On is the time the airplane touches down to land.
• In is the time the brakes are set and the cabin door is opened.
All times are reported as four digit numbers representing the time in military format (24-hour clock). For example, 4:30 AM would be represented as 0430 and 9:45 PM would be 2145.
Airborne time would be the difference between the On time and the Off times. Pilots are responsible for the safe operation of the airplane from the Out time until the plane is parked at the gate, marked by the In time.
Create a C++ struct that contains the flight identification as a string, usually a combination of letters and numbers, as well as the four operational times:
Out, Off, On, and In as integers.
Write a C++ program that prompts the user for the flight identification and the four operational times: Out, Off, On, and In and stores those values in the C++ struct you created. The program will also ask the user for the scheduled arrival time. Calculate and report the amount of time in hours and minutes the pilots are responsible for operating the plane as well as whether or not the plane made an on-time arrival. On-time arrivals are defined as pulling up to the gate within 15 minutes of the scheduled arrival time.
NOTES:
• Converting the time in military format to the number of minutes past midnight may make it easier to make calculations.
• Some planes takeoff late at night and do not land until past midnight, the next morning.
#include<iostream>
using namespace std;
struct airline
{
string identity;
int out;
int off;
int on;
int in;
};
int
main ()
{
int arrh, arrm, airbh, airbm;
airline min;
airline hr;
cout << "enter the flight identification number\n";
cin >> hr.identity;
cout << "enter the hr of the 'Out time' in military format\n";
cin >> hr.out;
cout << "enter the minute of the 'Out time' in military format\n";
cin >> min.out;
cout << "enter the hr of the 'Off time' in military format\n";
cin >> hr.off;
cout << "enter the minute of the 'Off time' in military format\n";
cin >> min.off;
cout << "enter the hr of the 'On time' in military format\n";
cin >> hr.on;
cout << "enter the minute of the 'On time' in military format\n";
cin >> min.on;
cout << "enter the hr of the 'In time' in military format\n";
cin >> hr.in;
cout << "enter the minute of the 'In time' in military format\n";
cin >> min.in;
cout << "enter the scheduled arrival hour and min\n";
cin >> arrh >> arrm;
airbh = hr.off - hr.on;
airbm = min.off - min.on;
if (airbh > 0)
cout << "The airbourne time in hours and minute is " << airbh << ":" <<abs(airbm)<<endl;
else
{
airbm = (((24 - hr.off) * 60) - 3) + ((hr.on * 60) + min.on);
airbh = airbm / 60;
airbm = airbm % 60;
cout << "The airbourne time in hours and minute is " << airbh << ":"<< abs(airbm)<<endl;
}
arrm=arrm+15;
if(arrm>60)
{
arrh+=1;
arrm-=60;
}
if(hr.in>arrh || min.in>arrm)
cout<<"flight not on time\n";
else
cout<<"flight on time\n";
return 0;
}