Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write in C++ A lot of low-level API's have c-style interfaces because that allows both C and C++ code to use them. The following code

Write in C++

A lot of low-level API's have c-style interfaces because that allows both C and C++ code to use them. The following code illustrates what such n interface might look like. Add a function as described in the comments that allows the user to set the isActive state of the device. This function should have reference semantics via a DeviceInterface pointer.

Starter Code:

#include  struct DeviceInterface { uint32_t deviceId; uint32_t driverVersion; bool enableDataTransfer; bool isActive; }; DeviceInterface* device_interface_create(bool transferEnabled); void device_interface_destroy(DeviceInterface* device); // TODO: add the new function 'device_interface_activate' here int main() { DeviceInterface* interfacePtr = device_interface_create(false); // TODO: call 'device_interface_activate' on the deviceInterface device_interface_destroy(interfacePtr); } DeviceInterface* device_interface_create(bool transferEnabled) { DeviceInterface* ptr = new DeviceInterface{}; ptr->deviceId = 0x01; ptr->driverVersion = 0x01; ptr->enableDataTransfer = transferEnabled; ptr->isActive = false; return ptr; } void device_interface_destroy(DeviceInterface* device) { delete device; } // TODO: implement 'device_interface_activate' such that it sets the isActive value to 'true'

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Mining Concepts And Techniques

Authors: Jiawei Han, Micheline Kamber, Jian Pei

3rd Edition

0123814790, 9780123814791

More Books

Students also viewed these Databases questions