Question

In: Computer Science

Directions: Convert the following problems below to c++ equivalent code Problem 3: Take any 2 digit...

Directions: Convert the following problems below to c++ equivalent code

Problem 3:

  1. Take any 2 digit number from 31 to 99. (You do not have to check the numbers just assume the user will enter a valid number so long as you tell them to).
  2. Store an extra copy of this number for later

3.   Add 82 to the number.

4.    Remove the hundreds place from your number

5.    Add 1 to the number.

6.    Subtract this from your original number (stored in step 2).
7.    Output the result obtained

Problem 4:

1.   Select two, single digit, numbers, the first being in the range 2 to 6 and the second being in the range 1 to 9.

2.   Multiply the first number by five.

3.   Add three to that number.

4.   Double the number.

5.   Add the second number to your previous step.

6.   Subtract 6 from the new total and:

The tens place should be the first number given and the ones place should be the second.

Solutions

Expert Solution

#include <iostream>

using namespace std;

int main() {
   int num;

   // read number
   cout << "Enter a two digit number from 31 to 99: ";
   cin >> num;

   // store copy
   int copy = num;

   // perform operations
   num = num + 82;
   num = num % 100;
   num = num + 1;
   num = copy - num;

   // display result
   cout << "Result: " << num;
}

#include <iostream>

using namespace std;

int main() {
   int n1, n2;

   // reading user inputs
   cout << "Enter a single digit number between 2 to 6: ";
   cin >> n1;
   cout << "Enter another single digit number between 1 to 9: ";
   cin >> n2;

   // storing copy of first number
   int copy_n1 = n1;

   // perform the operations on copy_n1
   copy_n1 = n1 * 5;
   copy_n1 = copy_n1 + 3;
   copy_n1 = 2 * copy_n1;
   copy_n1 = copy_n1 + n2;
   copy_n1 = copy_n1 - 6;

   // calculate the ones place and store in variable
   int ones = copy_n1 % 10;
   copy_n1 = copy_n1 / 10;

   // calculate the tens place and store in variable
   int tens = copy_n1 % 10;

   // display the results
   cout << "First digit entered is '" << n1 << "' and tens place is also '" << tens << "'" << endl;
   cout << "Second digit entered is '" << n2 << "' and ones place is also '" << "'" << ones;
}

FOR ANY MODIFICATIONS PLEASE LET US KNOW THROUGH COMMENTS.
FOR HELP PLEASE COMMENT.
THANK YOU.


Related Solutions

Directions: Convert the following problems below to c++ equivalent Problem 2: Enter a random number Store...
Directions: Convert the following problems below to c++ equivalent Problem 2: Enter a random number Store the original number for later use Multiply the number by 3 Add 45 to the number Multiply the number by 2 Divide the number by 6 Subtract the original number from your previous answer The result should be 15
Need this in C#. Below is my code for Problem 3 of Assignment 2. Just have...
Need this in C#. Below is my code for Problem 3 of Assignment 2. Just have to add the below requirement of calculating the expected winning probability of VCU. Revisit the program you developed for Problem 3 of Assignment 2. Now your program must calculate the expected winning probability of VCU through simulation. Run the simulation 10,000 times (i.e., play the games 10,000 times) and count the number of wins by VCU. And then, calculate the winning probability by using...
Take the Java program Pretty.java and convert it to the equivalent C program. You can use...
Take the Java program Pretty.java and convert it to the equivalent C program. You can use the file in.txt as sample input for your program. v import java.io.*; import java.util.*; public class Pretty { public static final int LINE_SIZE = 50; public static void main(String[] parms) { String inputLine; int position = 1; Scanner fileIn = new Scanner(System.in); while (fileIn.hasNextLine()) { inputLine = fileIn.nextLine(); if (inputLine.equals("")) { if (position > 1) { System.out.println(); } System.out.println(); position = 1; } else...
1. Convert the following code shown below to C++ code: public class HighwayBillboard { public int...
1. Convert the following code shown below to C++ code: public class HighwayBillboard { public int maxRevenue(int[] billboard, int[] revenue, int distance, int milesRes) { int[] MR = new int[distance + 1]; //Next billboard which can be used will start from index 0 in billboard[] int nextBillBoard = 0; //example if milesRes = 5 miles then any 2 bill boards has to be more than //5 miles away so actually we can put at 6th mile so we can add...
In C program. Read and convert a sequence of digits to its equivalent integer. Any leading...
In C program. Read and convert a sequence of digits to its equivalent integer. Any leading white space should be skipped. The conversion should include digit characters until a non-digit character is encountered. Modify the program so it can read and convert a sequence of digit characters preceded by a sign, + or -.
Problem set Rewrite the following if statement as an equivalent switch statement. The variable digit is...
Problem set Rewrite the following if statement as an equivalent switch statement. The variable digit is of type int. if (digit == 0) value = 3; else if (digit == 1) value = 3; else if (digit == 2) value = 6; else if (digit == 3)     value = 9; The decision table below shows fines imposed for speeding violations. Write a code segment that assigns the correct fine to type double variable fine based on the value of...
Evaluate (3b/2+c)*(6b-a) by writing the code in assembly. where a=2, b=3 and c=5. Write the equivalent...
Evaluate (3b/2+c)*(6b-a) by writing the code in assembly. where a=2, b=3 and c=5. Write the equivalent C++ code in assembly language. if (bx<= ax) && ( cx > dx ) { ax = 5; dx = 6; } NOTE: Only use 16 bit or 8 bit registers like ax,bx,cx,dx or al,bl,cl,dl. You can either do this using loop statement or conditional or unconditional jmps in assembly language. Keep the code as simple as possible. For question you need to use...
convert following C++ code into MIPS assembly: int main() {                                 &
convert following C++ code into MIPS assembly: int main() {                                         int x[10], occur, count = 0;                                                              cout << "Type in array numbers:" << endl; for (int i=0; i<10; i++) // reading in integers                               { cin >> x[i];        } cout << "Type in occurrence value:" << endl;                                 cin >> occur;                                                 // Finding and printing out occurrence indexes in the array                                  cout << "Occurrences indices are:" <<...
C++ Directions: Follow the insttructions of implementation and then fill in the following code for QueueArray...
C++ Directions: Follow the insttructions of implementation and then fill in the following code for QueueArray class Both given below: 5.1 Implement QueueArray<DataType>::QueueArray(int maxNumber) 5.2 Implement QueueArray<DataType>::QueueArray(const QueueArray& other) 5.3 Implement QueueArray<DataType>::~QueueArray() 5.4 Implement void QueueArray<DataType>::enqueue(const DataType& newDataItem) throw (logic_error) 5.5 Implement DataType QueueArray<DataType>::dequeue() throw (logic_error) 5.6 Implement void void QueueArray<DataType>::clear() throw (logic_error) 5.7 Implement bool QueueArray<DataType>::isEmpty() const 5.8 Implement bool QueueArray<DataType>::isFull() const 5.9 Implement void QueueArray<DataType>::putFront(const DataType& newDataItem) throw (logic_error) 5.10 Implement DataType QueueArray<DataType>::getRear() throw (logic_error) 5.11 Implement int...
3. Variable and Absorption Costing Follow the directions below and answer the following problem. Maxwell Company...
3. Variable and Absorption Costing Follow the directions below and answer the following problem. Maxwell Company manufactures and sells a single product. The following costs were incurred during 2014, the company’s first year of operations: Variable Costs per Unit: Production: Direct Materials $16 Direct Labor 8 Variable Manufacturing Overhead 2 Selling and Administrative 4 Fixed Costs per Year: Manufacturing Overhead $ 140,000 Selling and Administrative 110,000 During 2014, the company produced 20,000 units and sold 18,000 units. The selling price...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT