Objectives: The aim of this series of sessions is to familiarize with abstractio
ID: 3903614 • Letter: O
Question
Objectives: The aim of this series of sessions is to familiarize with abstraction of data, explore memory-efficient data representation using Structs and its pointers in the context of embedded systems Utilize bit-field access for manipulating register bits. Background on Data Structures and Structs in C++ A data structure is a group of data elements grouped together under one name. These data elements, known as members, can have different types and different lengths. Data structures can be declared in C++ using the following syntax: struct type_namet member type1 member_name1; member type2 member_name2; member_type3 member _name3; object_names;Explanation / Answer
Answer:
In C++ data abstraction means only displaying the essential details and hiding rest of the information. Data abstraction can be implemented using classes (group data members and functions by using class specifiers)and header files(call a method in header files)
For memory efficient data structures we can use std::map ( create holding class and define comparision function)and std::unordered_map.(define a hash function). It will have an advantage over sorted vectors that insertion and deletion from/to tables will be logarithmic rather than linear.Use of hash table woud be a better choice if you are ready to trade off memory with search speed. implementation complexity wise std::map would be much easier as compared to hash tables and sorted vectors.
Bit bashing or bit wise manipulation of registers can be implemented using AND and OR operators.OR is used to set one or more bits without impacting others in the register. AND is used to clear the bits. For toggling a bit XOR is used.
An example of arduino code for data structures is as below:
List of data members can be identified using a type and identifier.
struct Classroom {
int subjectstaught;
int numberofstudents;
} classone,classtwo,classthree;
The objects defined can be operated on any of the variables defined
classone.numberofstudents
classone.subjectstaught
The data type of each of them refers to the members they refer to. Here for example it is int.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.