Pointers

Program 1

Create an array of 15 ints and place a random number into each slot in the array.  Then loop through that array and print out the value and memory address of each item.

Program 2

Create a new array of 15 ints and place a random number into each slot in the array. Create a function with parameters for both a int and an int pointer.  This function should print out the data attached to each item as well as the memory address of each item.  Loop through the array and pass each item in the array to this function.

Note:  This will require you to pass the same variable to the same function twice.  Once by value and once by address;

Program 3

Part 1

Create a struct of cars that holds a char array of size 32 for a make, a char array of size 32 for a model, an enum for color (this will need to be created), and an int for year. Create an statically sized array of 3 cars and ask the user to input the make, model, color, year, and mileage. The color question should provide a list of color options that links to the color enum. The mileage should be a random number. Once that is done, loop through the structs and display all the data to the screen.

Example Output

Car 1 – 2003 Gray Ford Mustang with 4,000 miles

Car 2 – 2016 White Ford Fusion with 567 miles

Car 3 - 2019 Silver Tesla Cybertruck with 127,204 miles

Part 2

Add a menu that provides an option to repaint a car after they have been created. You will need to implement the repaintCar function.

void repaintCar(Car* car, Color color);

C/C++

Part 3

Let's move our display logic into a separate function.  We will make two versions.  One will use a static Car and the other will use a Car pointer.  Implement both functions and print the cars out to the console using both versions.

void printCar(Car c);
void printCarPointer(Car* c);

C/C++

Example Output

Car 1 – 2003 Gray Ford Mustang with 4,000 miles

Car 2 – 2016 White Ford Fusion with 567 miles

Car 3 - 2019 Silver Tesla Cybertruck with 127,204 miles

Car* 1 – 2003 Gray Ford Mustang with 4,000 miles

Car* 2 – 2016 White Ford Fusion with 567 miles

Car* 3 - 2019 Silver Tesla Cybertruck with 127,204 miles

Part 4

We need to add the ability to add mileage to the car.  Create a function that will work with the for loop below to add mileage to the car.

for(int i = 0; i < 3; i++){
     addMileage(&cars[i], 500);
}


Get Help With a similar task to - Pointers

Login to view and/or buy answers.. or post an answer

Related Questions

Similar orders to Pointers
8
Views
0
Answers
Inter-Process Communication (IPC) with Pipes in C
This is a C programming assignment to implement the parallel processing of input files using the fork(), waitpid(), and pipe() system calls. You will also use stat() and write() in each child process, and you will use read() in the parent process. Overa...
16
Views
0
Answers
The third programming project involves writing a program that allows the user to enter a binary tree.
Use original java code as well as original work for test plans and documentation. The third programming project involves writing a program that allows the user to enter a binary tree in a parenthesized prefix format and then allows it to be categorized a...
25
Views
0
Answers
Jupyter notebook tasks. Create a Python file dmv_record.py that contains the definition of a class named DmvCarRecord.
Create a Python file dmv_record.py that contains the definition of a class named DmvCarRecord. The class should include an __init__ method that initializes the following fields using optional parameters: license_num maker model year owner_id reg_ex...
24
Views
0
Answers
software design & development using flask
The objective of this exercise is to create a database-driven Flask application to keep track of guest attendance to an event. The application should enable users to perform the following 3 actions, which should be implemented as links in a navbar: 1. V...