C++ 1) Implement a class named StarWars; Class StarWars has a class named World;
ID: 3670190 • Letter: C
Question
C++
1) Implement a class named StarWars; Class StarWars has a class named World;
2) The object starWarsOBJ created the Class Moon as a tool that Darth Vader uses to control the Class World; Therefore, having the object worldOBJ within your starWarsOBJ, pass the object moonOBJ as an argument to the worldOBJ;
3) The moonOBJ has a huge tower that is represented as the struct data_tower tower comprised of: int total_antennas, float *sending_signal, string message.
4) Create the method Input asking the user what is the value for total_antennas, and then make the dynamic allocation of your array of float sending_signal[total_antennas], using the commands new and delete accordingly;
5) Run a simulation showing for each hour the sending_signal[total_antennas], is sending the string message that is printed on worldOBJ the following phrase, as ordered by Darth Vader: “... Darth Vader is the Great!...”. This message is repeated for each of the sending_signal[total_antennas], i.e. if you have 10 antennas, the message will be repeated 10 antennas x 24 hours a day; when printing the message, inform also what time in the simulator and which antenna is sending the signal.
Explanation / Answer
class StarWars{
//inner class world for starwars
class World{
//moonclass object creation
moonClass moonOBJ;
//inputtowerdetails method call
moonOBJ.inputTowerDetails();
};
World w;
};
struct data_tower{
int total_antennas;
float *seneding_signal;
string message;
};
class moonClass{
data_tower *tower;
int num;
int n;
public:
//accept the details in moon class
void inputTowerDetails(){
cout<<"Enter the what is value of antennas";
cin>>tower->total_antennas;
cout<<"dynamic allocation of float array";
cout<<"How many number of elements";
cin>>num;
tower->sending_signals[total_antennas] = new sending_signals[num];
if(tower->seneding_signal ==null){
cout << "Error: memory could not be allocated";
}
else
{
for (n=0; n<num; n++)
{
cout << "Enter number: ";
cin >> tower->seneding_signal[n];
}
cout << "You have entered: ";
for (n=0; n<num; n++)
cout << tower->seneding_signal [n] << ", ";
delete[] tower->seneding_signal ;
}
}
};
int main(){
cout<<"From main class";
cout<<endl;
starWars s;
s(w);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.