#include <iostream>
#include <string>
using namespace std;
// 6) Vehicle struct specification
struct Vehicle
{
int id;
int year;
string model;
};
// 9) Function prototype above main()
void displayCar(Vehicle car);
int main()
{
// Given in the lab
int values[5] = {2, 4, 7, 9, 11};
int number = 5;
// 1) Declare double pointer named doublePtr, initialize with NULL
double* doublePtr = NULL;
// 2) Declare int pointer named ptr, initialize with address of number
int* ptr = &number;
// 3) Assign address of values array to doublePtr
// NOTE: values is an int array, but lab asks for double*. This cast matches the worksheet intent.
doublePtr = (double*)values;
// 4) cout the value in number WITHOUT using number (dereference ptr)
cout << "Q4 (value of number using *ptr): " << *ptr << endl;
// 5) Assign 44 to number WITHOUT using number (dereference ptr)
*ptr = 44;
cout << "Q5 (number after *ptr = 44): " << number << endl;
// 7) Declare Vehicle object named myCar (no initialization)
Vehicle myCar;
// 8) Declare Vehicle object named yourCar and initialize with given values
Vehicle yourCar = {12345, 2005, "Ford"};
// (Optional) call function so you can test that it works
displayCar(yourCar);
return 0;
}
// Function definition (so the program runs)
void displayCar(Vehicle car)
{
cout << "\nVehicle Info\n";
cout << "ID: " << car.id << endl;
cout << "Year: " << car.year << endl;
cout << "Model: " << car.model << endl;
}