## c++ – Number Conversion System Using Inheritance

I have a problem in my code. It’s just the class. The whole code is under one class.Can it be converted to inheritance?like can it be converted to base and derive classes?

Here is the requirement of the question below…

Implement a class hierarchy in C++ with Number System as a base class and four derived classes to represent each of the four number systems mentioned above. Use this class hierarchy to implement a Number Conversion Calculator.

Your calculator should have the following features:

• Take a number (in any of the four bases) and be able to convert it into a specified base.

• To add, subtract, multiply and divide numbers (in any of the four bases) using operator overloading.

``````class NumberSystem
{
public:
int BinarytoDecimal()
{
long long num;
int decimalNum, i, rem;

cout << "Enter any binary number: ";
cin >> num;

decimalNum = 0;
i = 0;

//converting binary to decimal
while (num != 0)
{
rem = num % 10;
num /= 10;
decimalNum += rem * pow(2, i);
++i;
}

cout << "Equivalent Decimal number: " << decimalNum << endl;

return decimalNum;
}
{

long num, temp;
int oct(50), i = 1, j;
cout << "Enter a decimal number : ";
cin >> num;
temp = num;
while (temp != 0)
{
oct(i++) = temp % 8;
temp = temp / 8;
}
cout << "nOctal equivalent of " << num << " is : "<<oct(2)<<oct(1)<<endl;
for (j = i - 1; j >= 0; j--)
cout << oct(j);
return 0;
}
void OctaltoHexa()
{
int ar1(20), ar2(20), ar3(20);
int h, i, j, k, l, x, fr, flg, rem, n1, n3;
float rem1, n2, n4, dno;
char octal_num(20);
x = fr = flg = rem = 0;
rem1 = 0.0;
cout << "nn Convert any octal number to a hexadecimal number:n";
cout << "------------------------------------------------------n";
cout << " Input any octal number: ";
cin >> octal_num;

for (i = 0, j = 0, k = 0; i < strlen(octal_num); i++)
{
if (octal_num(i) == '.')
{
flg = 1;
}
else if (flg == 0)
ar1(j++) = octal_num(i) - 48;
else if (flg == 1)
ar2(k++) = octal_num(i) - 48;
}
x = j;
fr = k;
for (j = 0, i = x - 1; j < x; j++, i--)
{
rem = rem + (ar1(j) * pow(8, i));
}
for (k = 0, i = 1; k < fr; k++, i++)
{
rem1 = rem1 + (ar2(k) / pow(8, i));
}
rem1 = rem + rem1;
dno = rem1;
n1 = (int)dno;
n2 = dno - n1;

i = 0;
while (n1 != 0)
{
rem = n1 % 16;
ar3(i) = rem;
n1 = n1 / 16;
i++;
}
j = 0;
while (n2 != 0.0)
{
n2 = n2 * 16;
n3 = (int)n2;
n4 = n2 - n3;
n2 = n4;
ar1(j) = n3;
j++;
if (j == 4)
{
break;
}
}
l = i;
cout << " The hexadecimal value of " << octal_num << " is: ";
for (i = l - 1; i >= 0; i--)
{
if (ar3(i) == 10)
cout << "A";
else if (ar3(i) == 11)
cout << "B";
else if (ar3(i) == 12)
cout << "C";
else if (ar3(i) == 13)
cout << "D";
else if (ar3(i) == 14)
cout << "E";
else if (ar3(i) == 15)
cout << "F";
else
cout << ar3(i);
}
h = j;
cout << ".";
for (k = 0; k < h; k++)
{
if (ar1(k) == 10)
cout << "A";
else if (ar1(k) == 11)
cout << "B";
else if (ar1(k) == 12)
cout << "C";
else if (ar1(k) == 13)
cout << "D";
else if (ar1(k) == 14)
cout << "E";
else if (ar1(k) == 15)
cout << "F";
else
cout << ar1(k);
}
cout << endl;
}

};

``````

## Inheritance or structure in structure

I wonder what the difference is between:

structure A

{

struct B {};

};

and:

struct A {};

structure B: A {};

## python: multiple inheritance of class divided into modules

I have a class `Main` what do you use `fn(cls, ...)` multi-module methods; are used exclusively by `Main`. Each module is 500-1000 lines long (without docstrings); the idea is to "break" several `Main` methods to facilitate debugging and readability, instead of grouping them into a single class and creating a file of more than 9000 lines.

Everything works correctly. However, a main asset is sacrificed: introspection; `help(Main.method)`, or even `Main.method()` They are no longer an option. So the goal is as follows: keep methods in separate files, but make them behave like normal class methods.

My approach: & # 39; packaging & # 39; the module methods in classes, then the module classes in a class & # 39; unifier & # 39 ;, then inherit the unifier in `Main`. Code below. Points to consider:

• No major problems; `Module` classes only have methods, their `__init__` is as minimal as shown
• Without attributes, according to the above, and therefore the same for `Unifier`
• There are no duplicate attributes / methods; All methods have a unique name (and there are no attributes to duplicate)

Question: any warning to keep in mind? What can be done better? Some particular concerns are:

1. Is `pickle.dump`, `.load` affected? I pickle alone without method `Main` attributes.
2. It is a dynamic `to_unify` Trustworthy? I guess it "depends" on how all the classes involved change.
3. Any metaclass complexity of the inheritance scheme?

Code: live demo

``````# module_a.py
class ModuleA():
def __init__(self):
super(ModuleA, self).__init__()

def woof(self):
"""I'm a dog"""
self.do_woofing()  # dependency on ModuleB

def do_dooting(self):
print("DOOT")
``````
``````# module_b.py
class ModuleB():
def __init__(self):
super(ModuleB, self).__init__()

def doot(self):
"""I'm a skeleton"""
self.do_dooting()  # dependency on ModuleA

def do_woofing(self):
print("WOOF")
``````
``````# main_module.py
from module_a import ModuleA
from module_b import ModuleB

to_unify = ModuleA, ModuleB  # can add modules later

class Unifier(*to_unify):
def __init__(self):
super(Unifier, self).__init__()

class Main(Unifier):
def __init__(self, *args, **kwargs):
super().__init__()
# ...
``````
``````# main.py
from main_module import Main

m = Main()
m.woof()
m.doot()
help(m.doot)
``````
``````WOOF
DOOT
Help on method doot in module module_b:

doot() method of main_module.Main instance
I'm a skeleton
``````

## layout: module-class multiple inheritance

I have a class `Main` what do you use `fn(cls, ...)` multi-module methods; are used exclusively by `Main`. Each module is 500-1000 lines long (without docstrings); the idea is to "break" several `Main` methods to facilitate debugging and readability, instead of grouping them into a single class and creating a file of more than 9000 lines.

Everything works correctly. However, a main asset is sacrificed: introspection; `help(Main.method)`, or even `Main.method()` They are no longer an option. So the goal is as follows: keep methods in separate files, but make them behave like normal class methods.

My approach: & # 39; packaging & # 39; the module methods in classes, then the module classes in a class & # 39; unifier & # 39 ;, then inherit the unifier in `Main`. Code below. Points to consider:

• No major problems; `Module` classes only have methods, their `__init__` is as minimal as shown
• Without attributes, according to the above, and therefore the same for `Unifier`
• There are no duplicate attributes / methods; All methods have a unique name (and there are no attributes to duplicate)

Question: any warning to keep in mind? What can be done better? Some particular concerns are:

1. Is `pickle.dump`, `.load` affected? I pickle alone without method `Main` attributes.
2. It is a dynamic `to_unify` Trustworthy? I guess it "depends" on how all the classes involved change.
3. Any metaclass complexity of the inheritance scheme?

Code: live demo

``````# module_a.py
class ModuleA():
def __init__(self):
super(ModuleA, self).__init__()

def woof(self):
"""I'm a dog"""
self.do_woofing()  # dependency on ModuleB

def do_dooting(self):
print("DOOT")
``````
``````# module_b.py
class ModuleB():
def __init__(self):
super(ModuleB, self).__init__()

def doot(self):
"""I'm a skeleton"""
self.do_dooting()  # dependency on ModuleA

def do_woofing(self):
print("WOOF")
``````
``````# main_module.py
from module_a import ModuleA
from module_b import ModuleB

to_unify = ModuleA, ModuleB  # can add modules later

class Unifier(*to_unify):
def __init__(self):
super(Unifier, self).__init__()

class Main(Unifier):
def __init__(self, *args, **kwargs):
super().__init__()
# ...
``````
``````# main.py
from main_module import Main

m = Main()
m.woof()
m.doot()
help(m.doot)
``````
``````WOOF
DOOT
Help on method doot in module module_b:

doot() method of main_module.Main instance
I'm a skeleton
``````

## Break inheritance of subsite permissions with a workflow

I have an SP workflow that creates a new project subsite when a new project is created in the master list, but I can't see how to break the permission inheritance of the primary site.

Each subsite in the project is required to have a specific user group access requirement in addition to others that can see all subsites. I have found multiple sources of how to break / set permissions for items eg lists, document libraries and documents but not how to control child site.

I suppose it will be some kind of REST api command but I can't solve it. Any help received with gratitude

## c ++ – Regarding inheritance of singleton class

I have come across a code where a class inherits the singleton class. The Singleton class has its constructor, destructor as protected, and copy constructor, = operator overload as private. This Singleton class uses ScopedLock to hold only 1 instance. The derived class has its constructor in Public and that constructor initializes some of its private members. My question is, what is the purpose of inheriting from the Singleton class if the derived class has its constructor in Public and multiple objects can be created?

Correct me if I was wrong.

## c # – PreserveIds using inheritance

I am working on this project where I like PreserveIds once that object is created. I would like to know if there is a better way to use inheritance instead of using one for each cycle and check if the value is 0.

``````class Program
{
static void Main(string() args)
{
var States = new List();
var CaliforniaCity = new List();
CaliforniaCity.Add(new CityModel() { Id = 2, Name = "Los Angeles" });
CaliforniaCity.Add(new CityModel() { Id = 3, Name = "Sacramento" });
CaliforniaCity.Add(new CityModel() { Id = 4, Name = "San Francisco" });
States.Add(new StatesModel() { Id = 1, Name = "California", CityModels = CaliforniaCity });

States.Add(new StatesModel() { Id = 8, Name = "Pennsylvania", CityModels = PhiladelphiaCity });

var MichiganCity = new List();
MichiganCity.Add(new CityModel() { Id = 9, Name = "Detroit" });
MichiganCity.Add(new CityModel() { Id = 10, Name = "Lansing" });
MichiganCity.Add(new CityModel() { Id = 11, Name = "Grand Rapids" });
States.Add(new StatesModel() { Id = 12, Name = "Michigan", CityModels = MichiganCity });

PreserveIds(States);

foreach (var State in States)
{
Console.WriteLine(string.Format("{0}", State.Name));
Console.WriteLine(string.Format("{0} = {1}", State.Id ,State.OriginaId));
foreach (var city in State.CityModels)
{
Console.WriteLine(string.Format("{0}", city.Name));
Console.WriteLine(string.Format("{0} = {1}", city.Id, city.OriginaId));
}
}

}

public static void PreserveIds(IEnumerable States)
{
if (States != null)
{
foreach (var State in States)
{
if (State.OriginaId == 0)
{
State.OriginaId = State.Id;
}

foreach (var city in State.CityModels)
{
if (city.OriginaId == 0)
{
city.OriginaId = city.Id;
}
}
}
}
}
}
``````

Model

``````public class StatesModel
{
public int Id { get; set; }
public int OriginaId { get; set; }
public string Name { get; set; }
public List CityModels { get; set; }
public StatesModel()
{
CityModels = new List();
}
}

public class CityModel
{
public int Id { get; set; }
public int OriginaId { get; set; }
public string Name { get; set; }
}
``````

## python: is it a proper use of abstract classes and inheritance?

This is a simple application that launches the webcam in color or in grayscale mode, depending on what the user wants:

I wanted to have a common `show_current_frame` so much for him `ColorVideo` and `GrayVideo` objects. That `show_current_frame` fetches the current framework of the process method and displays it in the GUI. Since color and grayscale videos need different frame processing, I needed to have different `process` methods for `ColorVideo` and `GrayVideo`. So, I thought about having a `Video` class with a summary `process` method.

Is this a decent use of abstract classes and inheritance?
What other problems and possible improvements do you see in my code?
Or is the design wrong in the first place?

``````import cv2
from abc import ABC, abstractmethod

class Video(ABC):

def __init__(self, source):
self.capture = cv2.VideoCapture(source) # If source = 0 the webcam starts

def get_raw_frame(self):
# Get a bolean and current frame (numpy array) from the webcam
if ret:
return frame

@abstractmethod
def process(self):
# Method to process frames.
# Method will be overwritten by subclasses
pass

def show_current_frame(self):
# Get processed frame and show it in the GUI
current_frame = self.process()
cv2.imshow('Live', current_frame)

def end(self):
# Releases webcam and closes GUI window
self.capture.release()
cv2.destroyAllWindows()

class ColorVideo(Video):

def process(self):
# Since raw frames are in color, there's no processing needed
return self.get_raw_frame()

class GrayVideo(ColorVideo):

def process(self):
# Grayscaling the raw frames
raw_frame = self.get_raw_frame()
gray = cv2.cvtColor(raw_frame, cv2.COLOR_BGR2GRAY)
return gray

user_preference = input('Enter "c" for color, or "g" for grayscale: ')

if user_preference == 'c':
video = ColorVideo(source=0)
if user_preference == 'g':
video = GrayVideo(source=0)

while True:
video.show_current_frame()

if cv2.waitKey(1) & 0xFF == ord('q'):
video.end()
``````

## object-oriented: inheritance but with two different shared traits?

I am faced with a dilemma with the design of an api gateway. Currently, I am using the pipeline pattern, with different stages that are the requests made to various services (http, sockets, amqp, …).

I have a base class, RequestStage, with some subclasses, HttpStage, SocketStage, AmqpStage. These classes extend RequestStage because they can have different unique parameters for each of your requests.

The problem is that each stage / event (subclass) must be a call to a middleware API or a downstream API. If it is a middleware API, then a failure response condition must exist to short the pipe.

How can I fit into this additional field / trait? If the stage / event class is calling a middleware API request, then it must contain an additional "failCondition" field, but how could I implement this cleanly since my inheritance is based on the request protocol type and not on the type of service?

## java – Design pattern with one class and 2 subclasses but without using inheritance

I need to implement a class and 2 subclasses in which the main class contains the go and send it to the 2 subclasses, but the first subclass can change the value of the go and the main class must know this since it has to be updated to use the search methods of the second subclass. I cannot use inheritance because the subclasses cannot be anchored to the main class, because later these subclasses I will use them with other superior classes. I think I have to use interfaces but it is not clear to me.

Here I leave the sample code.

``````//Main principal
public class App {
public static void main(String() args) {
PanelPrincipal panel = PanelPrincipal(20);
}
}

//Panel principal

public class PanelPrincipal {
int id;

public PanelGeneralController(int id){
this.id = id;
}
}

//Subpanel Persona
public class SubPanelPersona {
int id;

public SubPanelPersona() { }

public void cambiarValor() {
this.id = 30;
}
}

//Subpanel Socio
public class SubPanelSocio {
int id;

public SubPanelSocio() {}

public void buscarSocio() {
//MÃ©todo el cual buscarÃ¡ en la base de datos el socio con ese id.
buscar(id);
}
}
``````