C ++ Declare a data structure name TANS PORT to store the following data about a
ID: 3776981 • Letter: C
Question
C ++
Declare a data structure name TANS PORT to store the following data about a transport: type (eg. Car), weight (eg. 200.40 kg), solar energy available (eg. 'Y' or 'N') and year of manufactured (eg. 2016). Use appropriate name and data type for each field of the structure. (b) For the TRANSPORT structure declared in part (a), define a new transport named newCar and initialize it with the following data: type: "Car" weight: 350.883kg solar energy available: true (or 1) year of manufactured: 2016 (c) Write a program which include the TRANSPORT structure declared in part (b). Write the C++ statement that produces the following output. Note that you must make use of the data fields as defined and declared in part (a) and (b). The output must follow exactly the same format as shown below. The new transport registered: Type = "Car" Weight = 350.88kg Solar energy available = true Year of manufactured = 2016 (d) Create a new program which includes the TRANSPORT structure designed from (a), write the C++ statement that will create an array name transports which includes 3 TRANSPORT structures. Next, fill up the array with the data as follow. (e) Continue from (d), declare and define a function which accepts the structure array created in (d) and return the lightest transport among the 3. The sample statement to call the function in the main() function is written as below: TRANSPORT lightest = getLightest(transports); The program should display the info of the lightest transport as below: The lightest transport registered: Type = "Bike" Weight = 150.70kg Solar energy available = false Year of manufactured = 2015Explanation / Answer
c 8 class exercise
a)
struct TRANSPORT
{
char type[20];
float weight;
bool solarEnergyAvalaible;
yearOfManufactured int;
};
b) struct TRANSPORT newCar;
newCar.weight=350.883;
newCar.solarEnergyAvalaible='Y';
newCar.yearOfManufactured=2016
c)
# include<stdio.h>
# include<conio.h>
using namespace std;
struct TRANSPORT
{
char type[20];
float weight;
bool solarEnergyAvalaible;
yearOfManufactured int;
};
void main()
{
//creating structure object
struct TRANSPORT newCar;
//initialise weight
newCar.weight=350.883;
//initialise boolEnergyAvalaible value
newCar.solarEnergyAvalaible='Y';
//initialise year of manufactured
newCar.yearOfManufactured=2016
getch();
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.