Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Needs to be in c++ with no use of system pause ---------------------------------

ID: 3691186 • Letter: N

Question

Needs to be in c++ with no use of system pause

--------------------------------------------------------

1). Structure declaration and member access – (3 points)

Look at the following structure declaration.

struct Point

{

int x;

int y;

};

Write statements that:

a) Define a Point structure variable named center

b) Assign 12 to the x member of center

c) Assign 7 to the y member of center

d) Display the contents of the x and y members of center

2). Structure arrays

Look at the following code.

struct PartData

{

string partName;

int idNumber;

};

PartData inventory[100];

Write a statement that displays the content of the partName member of element 49 in the inventory array.

3). Structure initialization

Look at the following code.

struct Town

{

string townName;

string countyName;

souble population

souble elevation

};

Town t = { “Independence”, “Freedom”, 9478 };

a) What value is stored in t.townName?

b) What value is stored in t.countyName?

c) What value is stored in t.population?

d) What value is stored in t.elevation?

4. Structure initialization

The structure Car is declared as follows:

struct Car

{

string carMake;

string carModel;

int yearModel;

double cost;

};

Write a definition statement that defines a car structure variable initialized with the following data:

Make: Ford

Model: Mustang

Year Model: 1968

Cost: $20,000

5). Correct the following code.

#include <iostream>

using namespace std;

struct ThreeVals

{

int a, b, c;

};

int main( )

{

ThreeVals vals = {1, 2, 3};

cout << vals << endl;

return 0;

}

Explanation / Answer

1).
struct Point
{
int x;
int y;
};
a) Point centre;
b) centre.x = 12;
c) centre.y = 7
d) cout << centre.x << endl;
cout << centre.y << endl;

2).
struct PartData
{
string partName;
int idNumber;
};
PartData inventory[100];
array starts from 0 , so 49th element will be index 48 in array
cout << inventory[48].partName << endl;

3).
struct Town
{
string townName;
string countyName;
souble population
souble elevation
};
Town t = { “Independence”, “Freedom”, 9478 };
a) value is stored in t.townName = “Independence”
b) value is stored in t.countyName = “Freedom”
c) value is stored in t.population = 9478
d) value is stored in t.elevation = 0


4.
struct Car
{
string carMake;
string carModel;
int yearModel;
double cost;
};

Car C;
C.carMake = "Ford";
Make: Ford

C.carModel = "Mustang";
Model: Mustang

C.yearModel = 1968
Year Model: 1968

C.cost = 20000;
Cost: $20,000


5).
#include <iostream>
using namespace std;
struct ThreeVals
{
int a, b, c;
};
int main()
{
ThreeVals vals = {1, 2, 3};
cout << vals.a << endl;
cout << vals.b << endl;
cout << vals.c << endl;

return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote