Need help drawing a UML sequence diagram for how the objects interact. Show main
ID: 3777662 • Letter: N
Question
Need help drawing a UML sequence diagram for how the objects interact. Show main as an object, even though it isn't one. Below is the code for a program that contains a main() and uses classes Name, LanId, and ScheduledActivity.
IActivity.h
MainControl.cpp
class IActivity
{
public:
virtual void requestValue() = 0;
virtual void displayValue() = 0;
virtual ~IActivity() { };
};
#include "ScheduledActivity.h"
#include "Name.h"
#include "LanId.h"
#include <iostream>
int main(int argc, char* argv[]) {
ScheduledActivity *a1, *a2;
a1 = new ScheduledActivity(new Name());
a2 = new ScheduledActivity(new LanId());
std::cout << "The activity ids are " << a1->getActivityId() <<
" and " << a2->getActivityId() << std::endl;
a1->getActivity()->displayValue();
delete a1;
a2->getActivity()->displayValue();
delete a2;
return 0;
}
ScheduledActivity.h
ScheduledActivity.cpp
class IActivity;
class ScheduledActivity
{
public:
ScheduledActivity(IActivity*);
IActivity *getActivity();
int getActivityId();
virtual ~ScheduledActivity();
private:
static int IdNum;
IActivity *activity;
int activityId;
};
#include "ScheduledActivity.h"
#include "IActivity.h"
int ScheduledActivity::IdNum = 33;
ScheduledActivity::ScheduledActivity(IActivity* a) {
activity = a;
activityId = IdNum++;
}
ScheduledActivity::~ScheduledActivity() {
delete activity;
}
IActivity *ScheduledActivity::getActivity() {
return activity;
}
int ScheduledActivity::getActivityId() {
return activityId;
}
LanId.h
LanId.cpp
#include "IActivity.h"
#include <string>
class LanId : public IActivity
{
public:
LanId();
void displayValue();
virtual ~LanId();
private:
void requestValue();
std::string lanId;
};
#include "LanId.h"
#include <iostream>
LanId::LanId() {
requestValue();
}
LanId::~LanId() { }
void LanId::requestValue () {
std::cout << "Please enter a lanid: ";
std::cin >> lanId;
}
void LanId::displayValue () {
std::cout << "The lanid is " << lanId << std::endl;
}
Name.h
Name.cpp
#include "IActivity.h"
#include <string>
class Name : public IActivity
{
public:
Name();
void displayValue();
virtual ~Name();
private:
void requestValue();
std::string firstName;
std::string lastName;
};
#include "Name.h"
#include <iostream>
Name::Name() {
requestValue();
}
Name::~Name() { }
void Name::requestValue () {
std::cout << "Please enter your first name: ";
std::cin >> firstName;
std::cout << "Please enter your last name: ";
std::cin >> lastName;
}
void Name::displayValue () {
std::cout << "The name is " << firstName << " " << lastName << std::endl;
}
IActivity.h
MainControl.cpp
class IActivity
{
public:
virtual void requestValue() = 0;
virtual void displayValue() = 0;
virtual ~IActivity() { };
};
#include "ScheduledActivity.h"
#include "Name.h"
#include "LanId.h"
#include <iostream>
int main(int argc, char* argv[]) {
ScheduledActivity *a1, *a2;
a1 = new ScheduledActivity(new Name());
a2 = new ScheduledActivity(new LanId());
std::cout << "The activity ids are " << a1->getActivityId() <<
" and " << a2->getActivityId() << std::endl;
a1->getActivity()->displayValue();
delete a1;
a2->getActivity()->displayValue();
delete a2;
return 0;
}
IActivity.i ass Activi public oid. Virtua oid. Virtua virtual IActivity MainControl.cpp #include "Schedule dActivity,h #include #include #include iostream int main unt argc, char argy D ScheduledActivity, al, a al new ScheduledActivity ne Name0) w 00 ne ne std::cout The activity ids are al-> and std::endl: al-C get Activity0- displayValue0 delete al a2 get Activity0- displayValue0 delete a retum Scheduled Activity-cpp ScheduledActivity.h class IActivity. #include "Schedule dActivity,h #include class ScheduledActivity int ScheduledActivity: IdNum 33 public Scheduled Activity :ScheduledActivity IActivity IActivity getActivity0 activity activity Id IdNum virtual Scheduled Activity0 Scheduled Activity: ScheduledActivity0 delete activity; private static int IdNum: IActivity activity, IActivity ScheduledActivity: getActiwity0 int activity Id: retum activity: Scheduled Activity: get Activity Id0 retum activity Id: Land Landopp #include "TActivityh #include #include string #include iostream class LanId public IActivity Lanld:LanId public LanId:: Lanld0 oid. displayValue0 void LanId: request Value 0 virtual Land0 cout Please enter a std::cin lanId: private oid. void Lanld: displayValue 0 std::string lanId: std::cout The lanid landExplanation / Answer
11
down vote
accepted
The point of 3CNF is that it's a "normal form" for formulas: as you mention, each formula is equivalent, up to a quadratic (linear?) blowup, to a 3CNF formula. 3CNF formulas square measure "simple", and then easier to touch upon. specially, if you ever examine NP-completeness, you may conclude that we wish our to place our "challenging problems" in as easy a type as potential. This makes it easier each to style and analyze algorithms determination these issues, associated to prove that alternative issues also are troublesome by reducing 3CNF to them (showing a way to solve 3CNF victimization an rule for them).
We care specifically concerning 3CNF for historical reasons, it had been the primary (or one in every of the first) NP-complete issues (check out Cook's paper or Karp's paper on their various pages). Also, 2CNF isn't "complete" (arbitrary formulas cannot aren't such as a 2CNF), and it's straightforward to work out whether or not they square measure satiable or not (google if interested).
The conversion from CNF to 3CNF is best explained by associate example. we have a tendency to convert every clause one by one. The clause ABCDEABCDE is such as the 3CNF
(ABx1)(¬x1Cx2)(¬x2DE),
(ABx1)(¬x1Cx2)(¬x2DE),
in the sense that the initial formula (in this case, one clause) is satiable iff the born-again formula is. you change every of the clauses, and take their conjunction.
Suppose you've got associate discretionary formula victimization the connectives ¬,,¬,,. image it as a tree, wherever inner nodes square measure labelled with ¬,,¬,,, and every node has either one (¬¬) or 2 (,,) youngsters. i am sorry i am unable to give an image. the primary step is "pushing the negations to the leaves" victimization DE Morgan's rules (q.v.). That rids USA of all ¬¬ nodes, however currently leaves is also literals (variables or negations of variables). currently we have a tendency to convert the formula to a CNF recursively.
Denote by the perform we're constructing, that takes a formula as higher than (with ,, and presumably negated variables) and returns a CNF. For the bottom case, we've got (x)=x(x)=x and (¬x)=¬x(¬x)=¬x. For a formula of the shape ABAB, we do not have to be compelled to work hard: we have a tendency to outline (AB)=(A)(B)(AB)=(A)(B). the toughest case is formulas of the shape ABAB: a somewhat economical selection is
(AB)=(y(A))((¬y)(B)),
(AB)=(y(A))((¬y)(B)),
where yy could be a new variable, and y(A)y(A) suggests that adding yy to any or all the clauses.
General formulas with discretionary connectives may be handled by expressing the connectives victimization ,,¬,,¬, as an example by writing a truth-table; this could be quite wasteful, though.
The entire construction leads to a quadratic blowup in formula size (your "occurrences of variables"; there square measure several alternative ways that to outline formula size). However, the result you are quoting is simply a linear blowup (indeed, by an element of 2424). it's entirely potential that such a construction exists, however i am not attentive to it; maybe one in every of the readers is. The Sabbatum to 3SAT half features a linear blowup with an element of thirty three.
If you are doing not enable adding new variables, then no easy conversion is feasible. whereas it's continually potential to convert associate discretionary formula into a CNF (using the "truth table" approach), not each formula is convertible to a 3CNF while not adding new variables. associate example is parity on forty four variables. Also, the conversion from associate discretionary formula to a CNF may result in exponential blow-up, as an example for parity on nn variables we have a tendency to go from (n2)(n2) to (n2n)(n2n).
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.