Question

In: Computer Science

HI, I hope you are doing well. I really don't understand this question and don't know...

HI, I hope you are doing well. I really don't understand this question and don't know how to solve it at all because I am completely new to this c++ programming. can you please explain each line of code with long and clear comments? please think of me as someone who doesn't know to code at all. and I want this code to be written in c++

thank you very much and I will make sure to leave thumbs up.

For this problem, you will write a program using two queues.

Generate n random numbers between 10 and 100 (both inclusive), where n>9.

The value of n should be taken as input from the user and n should be >9.

The numbers could be duplicated.

Enqueue all these numbers to the first queue.

The objective is to find the numbers whose sum of digits is odd and enqueue them to the second queue.

The remaining numbers (whose sum of digits is even) should stay in the first queue.

You need to print the generated random numbers and content of both queues.

Solutions

Expert Solution

C++ Code

#include <iostream>
#include<queue>
using namespace std;
void show_queue(queue <int> q)
{
while(!q.empty())
{
cout<<q.front()<<" ";
q.pop();
}
cout<<"\n";
}
int digit_sum(int n)
{
int sum = 0;
while(n>0)
{
sum += (n%10);
n/=10;
}
return sum;
}
int main()
{
int n , arr[10000],i;
queue <int> q1,q2;
cout<<"Enter the value of n : ";
cin>>n;
cout<<"Random generated numbers are: ";
for(i=0;i<n;i++)
{
arr[i] = (rand()%(100-10+1))+10;
cout<<arr[i]<<" ";
q1.push(arr[i]);
}
for(i=0;i<n;i++)
{
q1.pop();
if(digit_sum(arr[i])%2!=0)
{
q2.push(arr[i]);
}
else
{
q1.push(arr[i]);
}
}
cout<<"\nqueue 1 elements : ";
show_queue(q1);
cout<<"\nqueue 2 elements : ";
show_queue(q2);
return 0;
}

ask if u have any query


Related Solutions

please I don't really know how to start answering this question I really need to understand...
please I don't really know how to start answering this question I really need to understand it please show the work with a clear handwriting A collision in one dimension A mass m1 = 2 kg moving at v1i = 3 ms−1 collides with another mass m2 = 4 kg moving at v2i = −2 ms−1. After the collision the mass m1 moves at v1f = −3.66 ms−1. (a) Calculate the final velocity of the mass m2. (b) After the...
Hi, the following is the question that I have been facing now and I really hope...
Hi, the following is the question that I have been facing now and I really hope if someone can help me with that. Problem analysis: This section is your analysis of the issues surrounding greenhouse gases and a carbon tax. You need spell out what the main problems of issues are facing Canadians. Use specific references when making your arguements. If more than one solution exists, then make an argument for focusing on just that one solution. In addition, how...
Hi, the following is the question that I have been facing now and I really hope...
Hi, the following is the question that I have been facing now and I really hope somebody can help me with it.    Problem analysis: This section is your analysis of the issues surrounding greenhouse gases and a carbon tax. You need to spell out what are the main problems or issues facing Canadians. Use specific references when making your arguments. If more than one solution exists, then make an argument for focusing on just that one solution. In addition,...
hello and hope you doing well. I plan to be a civil engineer as senior but...
hello and hope you doing well. I plan to be a civil engineer as senior but I have question hope you help me thanks: I know Civil Engineer need PE license but if I do not pass many time and if I give up. I will not officially call as engineer. But if you know which job high pay salaries if I have BS degree and not pass PE ? Hope you lists some good job without PE degree related...
I really don't understand what the following question is trying to ask. In regards to medical...
I really don't understand what the following question is trying to ask. In regards to medical marijuana was there a trade-off between science and politics?
I have a homework class, but I don't really understand anything and I have to submit...
I have a homework class, but I don't really understand anything and I have to submit my homework next week. Homework must be written in C ++ program language. Can someone help me please... Working with classes (everything written below is one task): Define a class Date that contains integer variables for day, month, and year. 1.1. Create the necessary methods for the class: set, get, default constructor, constructor with arguments. 1.2. Create a method that calculates the number of...
hi i don't understand for question b #3 & 4 Having thought about Mr. James’s suggestion,...
hi i don't understand for question b #3 & 4 Having thought about Mr. James’s suggestion, you consider several options as an estimate of lost profits. These include 1) the full year, 2) the last six months only, 3) a weighted average that gives twice the weight to the last six months as to the first six months, or 4) some other weighted average. Which method do you think gives the most accurate estimate of lost profits?
Hi, I have the answers, but I don't understand how to get the answers. Please explain...
Hi, I have the answers, but I don't understand how to get the answers. Please explain thoroughly. Bob earns ($25,000) in passive losses from BHI partnership. He has an outside basis of $40,000 of which $30,000 comes from non-recourse debt, and he has passive income of $50,000. What are the tax consequences to Bob? $10,000 deductible loss What basis does Bob take in his partnership interest? $15,000 How much is Bob at-risk after the allocation? 0 How much, if any...
How well do you really know your customers? And how well did they want to know...
How well do you really know your customers? And how well did they want to know you right?
I don't know to do ii) for letter a, as well as letter d, e and...
I don't know to do ii) for letter a, as well as letter d, e and the EC . Can you help? The combustion of carbon monoxide is represented by the equation below: CO(g) + ½O 2 (g) → CO 2 (g) (a) (i) Determine the value of the standard enthalpy change, ΔH o rxn, for the combustion of CO(g) at 298 K using the following information. (3 pts) C(s) + ½O 2 (g) → CO(g) ΔH o 298 =...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT