ll Make a C/C++ or Java program which creates two child processes/threads. Each
ID: 3843553 • Letter: L
Question
ll
Make a C/C++ or Java program which creates two child processes/threads. Each child has a loop in it (do the loop 10 times). The loop consists of a print statement and a sleep (x) statement (wherexis a random number from 1 to 3; you must compute a new random number for each call). If you do not know how to create child processes in C or a thread in Java, you can look on the Internet to find examples of how to do it (use fork0 for C/C++) that is part of the assignment. You must run the program twice, producing two output files. Write the code in either "C" or Java and e- mail the source code and a copy of the output to me from each of your two runs for grading (the output file must be a data file and not a screen shot). Note that the data files will almost certainly be different if you have written your program correctly. Also send me a word or text file with your observations on the assignment: what did you notice about the runs? Use a constant for xinstead of a random number and comment on how this affects the output of your program. Lastly, roughly how long (in hours) did the assignment take? Please put comments at the top of your program with your name, the date, the assignment number, and a brief description of the program. also want to see comments within the program. The first items in your data file must be your name and the assignment number (have your main program print these into the file).Explanation / Answer
#include <iostream>
#include <string>
using namespace std;
class polymorph{
string strVar; //string variable to store value.
public:
//Default Constructor
polymorph(){
strVar = "ABC";
}
//Parameterized Constructor
polymorph(string temp){
strVar = temp;
}
//Method to Return String from Class Variable.
public:string returnString(){
return strVar;
}
};
int main()
{
string tempString;
//First Object Creation
polymorph obj1; .
//Prints First String
cout <<" First String : "<<obj1.returnString();
cout <<" Enter String : ";
//getline (cin, tempString);
cin>>tempString; // Takes input from User
polymorph obj2(tempString); //Second Object Creation.
cout <<obj2.returnString(); //Prints Second String
cout <<" Second String : "<<obj2.returnString();
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.