Question

In: Computer Science

Convert this C++ to js/html and run in browser. ///////////////////////////////////////////////// #include <cstdlib> #include <ctime> #include <sstream>...

Convert this C++ to js/html and run in browser.

/////////////////////////////////////////////////

#include <cstdlib>
#include <ctime>
#include <sstream>
#include <iostream>
using namespace std;

/*
*
*/
class Dice{
private:
static const int MAXDICE=6;
static const int MINDICE=1;
int faceVal;
public:
Dice(int);
void setFace(int);
int getFace();
string toString();
};
Dice::Dice(int faceVal)
{
if(faceVal<MINDICE&&faceVal>MAXDICE)
{
setFace(1);
}
else
{
this->faceVal=faceVal;
}
}
void Dice::setFace(int faceVal)
{
this->faceVal=faceVal;
}
int Dice::getFace()
{
return faceVal;
}
string Dice::toString()
{
stringstream ss;
ss<<faceVal;
string str="face value is ";
str+=ss.str();
return str;
}
int main(int argc, char** argv) {
srand((unsigned)time(NULL));
Dice dice((rand()%(6))+1);
cout<<dice.toString()<<endl;
return 0;
}

Solutions

Expert Solution

<script language="JavaScript">

var nl = getNewLine()

function getNewLine() {
   var agent = navigator.userAgent

   if (agent.indexOf("Win") >= 0)
       return "\r\n"
   else
       if (agent.indexOf("Mac") >= 0)
           return "\r"

    return "\r"

}

pagecode = '#include <cstdlib>
#include <ctime>
#include <sstream>
#include <iostream>
using namespace std;

/*
*
*/
class Dice{
private:
static const int MAXDICE=6;
static const int MINDICE=1;
int faceVal;
public:
Dice(int);
void setFace(int);
int getFace();
string toString();
};
Dice::Dice(int faceVal)
{
if(faceVal<MINDICE&&faceVal>MAXDICE)
{
setFace(1);
}
else
{
this->faceVal=faceVal;
}
}
void Dice::setFace(int faceVal)
{
this->faceVal=faceVal;
}
int Dice::getFace()
{
return faceVal;
}
string Dice::toString()
{
stringstream ss;
ss<<faceVal;
string str="face value is ";
str+=ss.str();
return str;
}
int main(int argc, char** argv) {
srand((unsigned)time(NULL));
Dice dice((rand()%(6))+1);
cout<<dice.toString()<<endl;
return 0;
}'

document.write(pagecode);

</script>


Related Solutions

An HTML file is a text file that contains text to be displayed in a browser...
An HTML file is a text file that contains text to be displayed in a browser and __________ to be interpreted (read) by the browser formatting and styling the document Both C++ and javascript are computer programing languages; what are their differences? What HTML tag can let you insert javascript in to document Which attributes of the <script> tag tells the brorwser what kind of scripting language is insterted? (give an example) in the javascript section of the HTML file,...
JS Bin / Tax Calculator / using HTML | CSS | JavaScript ------------------------------------------------------------------------------------------- How can I...
JS Bin / Tax Calculator / using HTML | CSS | JavaScript ------------------------------------------------------------------------------------------- How can I edit the JavaScript below so that when the calculate button is clicked the total price only shows two decimal places by using the toFixed() method? ----------------------------------------------------------------------------------------------------------- JavaScript: // Variables var tax = "tax"; // Tax percentage var taxRate = document.getElementById('tax'); // Selecting tax element // On the time of loading the DOM we are setting the tax rate window.addEventListener('DOMContentLoaded', (event) => { taxRate.value =...
Create a Web Page Using HTML, CSS, JS, jQuery • Create a web profile, including any...
Create a Web Page Using HTML, CSS, JS, jQuery • Create a web profile, including any of the following: • Your hobbies, likes/dislikes, career aspirations, dream job, favorite animals/ pets, favorite superhero, etc. • You do not have to share personal information that you are uncomfortable with sharing. Follow these guidelines when creating your page: • Include at least one heading (h1, h2, etc.) in your web page. • Provide a quote from a book, movie, etc. • Include at...
Assignment - Store Design and code a HTML/CSS/JS based web application for your online store. Assignment...
Assignment - Store Design and code a HTML/CSS/JS based web application for your online store. Assignment Specification · Minimum of SIX web pages are required for this assignment: § One Landing/Container Page ( a page with logo) § One Home Page § Three or more Product Line Pages (pages with product and it information ) § One Order Page (for customer to order a product after view the profuct on the product page) · Build internal CSS style sheets in...
Need C++ code to be able to run, keep getting a constant value error #include #include...
Need C++ code to be able to run, keep getting a constant value error #include #include #include #include #include #include using namespace std; using namespace std::chrono; int c; void insertionSort(int* arr, int n) { for (int i = 1;i < n;i++) { int v = arr[i]; int j; for (j = i - 1;j > -1;j--) { c++; if (arr[j] > v) { arr[j + 1] = arr[j]; } else { break; } } arr[j + 1] = v; }...
How to do in C++ HTML Converter Create a program that reads an HTML file and...
How to do in C++ HTML Converter Create a program that reads an HTML file and converts it to plain text. Console HTML Converter Grocery List * Eggs * Milk * Butter Specifications Your instructor should provide an HTML file named groceries.html that contains these HTML tags: <h1>Grocery List</h1> <ul>     <li>Eggs</li>     <li>Milk</li>     <li>Butter</li> </ul> When the program starts, it should read the contents of the file, remove the HTML tags, remove any spaces to the left of the tags, add...
convert this program that is for string into character input data #include "stdafx.h" #include <string.h> #include...
convert this program that is for string into character input data #include "stdafx.h" #include <string.h> #include <stdlib.h> unsigned int putIntoHashTable(char *ptrInputData, unsigned int bufferLength); // function to add to hash table unsigned int getFromHashTable(char *ptrOutputData, unsigned int bufferLength); // function to retrieve data from hash table #define INPUT_BUFFER_SIZE 200 // local buffer used for adding data to the hash table (there is no reason in this assignment to change this value) #define HASH_SIZE 100 // size of hash table to...
Plz convert this C++ code into JAVA code thanks #include<iostream> using namespace std; //function for calculating...
Plz convert this C++ code into JAVA code thanks #include<iostream> using namespace std; //function for calculating the average sightings from the Total Sightings array float calcAverage(float totalSightings[],int n) {    int i;    float sum=0.0;    for(i=0;i<n;i++)    sum=sum+totalSightings[i];    return sum/n; } int main() {    // n is no. of bird watchers    //flag , flag2 and flag3 are for validating using while loops    int n,i,flag,flag2,flag3;       //ch also helps in validating    char ch;   ...
Please convert the following C program into the RISC-V assembly code 1) #include <stdio.h> int main()...
Please convert the following C program into the RISC-V assembly code 1) #include <stdio.h> int main() { int i = 2, j = 2 + i, k; k = i * j; printf("%d\n", k + j); return 0; } 2) #include <stdio.h> int main() { int i = 2, j = 2 + i, k = j / 2; if (k == 1) { printf("%d\n", j) k = k * 2; if ( k == j) { printf("%d\n|, j); }...
(a) Create a HTML page for a single faceted search selector. It will include the name...
(a) Create a HTML page for a single faceted search selector. It will include the name of the facet and a list of radio buttons or tick boxes for each category. (b) Add a button called filter. When the button is clicked the radio button or tick boxes will be read to determine if a selection has been made. The selection will be written to a div element located under the filterbutton. If no selection was made, then an appropriate...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT