15,311,151 members
See more:
```Input: S= set of cameras; T = set of targets; P= set of discrete
pans; K= No. of set covers
Output: C=Collection of Set Covers C1, C2....CK
1: SENSORS= S
2: /*SENSORS keeps track of the list of unused sensors */
3: k = 0
4: while SENSORS 6= ∅ do
5: /* a new set cover Ck will be formed */
6: k= k + 1
7: Ck=∅
8: TARGETS= T
9: /*TARGETS contains the uncovered targets */
10: while TARGETS 6= ∅ do
11: /* more targets have to be covered */
12: Find Dmin = minD(t) : t ∈ T
13: if |Dmin| = 0 then
14: /*TARGETS contains some uncoverable targets*/
15: goto marker
16: else
17: S′ = ∅
18: Find the targets having cardinality equals Dmin
and create a set T ′
19: for each t ∈ T ′
20: for each (si, pj) ∈ −1(t)
21: S′ = S′ ∪ {(si, pj)}
22: Find the most contributing (su, pv) such that:
23: (su, pv)←argmaxsu∈S’,1≤v≤quv∩TARGETS
24: /* selects (su, pv) covering maximum targets */
25: In case of tie, create a subset S′′ ⊆ S′ with
all sensor-pan pairs having same contribution
26: Let (si, pj) ∈ S′′ has the maximum force F′
ij
among all sensor-pan pairs in S′′, i.e.:
27: F′
ij = argmaxvFuv; ∀su ∈ S; ∀pv ∈ P;
∀si ∈ S; ∀pj ∈ P;
28: Ck = Ck ∪{(si, pj)}
29: SENSORS = SENSORS \ {si}
30: TARGETS = TARGETS \ {ij}
31: end if
32: end while
33: C = C ∪ Ck
34: end while
35: marker: return the collection of set covers C```

What I have tried:

need help to understand how to convert this algorithm into c++
Posted
Updated 7-Jul-21 21:40pm
CPallini 21-Mar-19 14:10pm

You can convert it... Coding!
CodeWraith 22-Mar-19 6:32am

Just what I thought. :-)
That's what some people mean by saying 'programming'.
RedDk 22-Mar-19 14:19pm

Actually what all these guys down here are saying is true and there's good suggestions as to how to start but looking at this code ... it almost looks as simple as QBASIC (since it's numbered). You might try just pasting it into an empty C# project module then fill in the function declarations. Been there done that.

I know, not C++ ...

## Solution 2

1. write a C++ main function
2. define a C++ function to implement your pseudo code: you need to decide what values need to passed to this function, and what is the desired output
3. create or construct the inputs to your function in the main function (just as an example to be able to test your code)
4. Implement the function: Analyze each statement in your pseudo code and translate them into C++ statements; don't forget to properly define any variables introduced in a pseudo code statement.
5. test and correct your code as needed; if you run into a specific problem that you don't know how to solve, come back here and ask

## Solution 1

The way you implement any new project:

1) Study the pseudo code and extract the algorithm.
2) Design the code (preferably eliminating the goto's) to implement the algorithm.
3) Code the design.
4) Test the code.
At any point, go back to an earlier stage as necessary until it works.
Stefan_Lang 22-Mar-19 6:00am

Suggesting to design the code before actually coding it is a great suggestion, but it's a bit like trying to run before learning to walk ;-)

## Solution 3

Quote:
How can I convert a pseudo code into source code ?

Pseudo code is a convention used by your teacher to describe how the program would work, it is not specific to a programming language, it is rather specific to the domain it is related to.

This code is a function:
- make C++ skeleton.
- paste pseudo code in empty function skeleton.
- make each line a comment.
- after each line of pseudo code, add the C++ code that match the pseudo code.

If you have specific question, show what you have done.