C++ data strucs aglorithms. Please do both parts short code tasks. attach output as well, both are very similar tasks . thank you i will give thumbs up .
task 1:
Second part (similar);
Please find below the required solution for above problem:
#include<iostream>
#include<vector>
#include<stdlib.h>
#include<iterator>
using namespace std;
//please use c++ 11 complier
int main()
{
//initial array delcared with 10 elements
int array[10];
int i;
//initia;ized the array with random elements
for(i=0;i<10;i++)
{
//rand function will generate
random no between 1 and 1000
array[i]=rand() % 1000 + 1;
}
//printed the old values from
cout<<"printing from array with 10 elements :
\n";
for(i=0;i<10;i++)
{
cout<<array[i]<<"
";
}
//declared the new array of size 20
int newarray[20];
//using dynamic copy copied the element from old to
new
copy(begin(array), end(array),
begin(newarray));
for(i=10;i<20;i++)
{
//filling the rest position of
array with random variables
newarray[i]=rand() % 1000 +
1;
}
//dispalying the values of new array
cout<<"\nprinting from array with 20 elements :
\n";
for(i=0;i<20;i++)
{
cout<<array[i]<<"
";
}
//declared the vector of initial size of 10
vector<int> vectorarray(10);
for(i=0;i<10;i++)
{
//initialized the vector to some
random values
vectorarray[i]=rand() % 1000 +
1;
}
//print out the values of vector from old
cout<<"\n\nprinting from old vector with 10
elements : \n";
for(i=0;i<10;i++)
{
cout<<vectorarray[i]<<"
";
}
//resized vector to store 20 elements
vectorarray.resize(20);
//initialized the rest place with some random values
for(i=10;i<20;i++)
{
vectorarray[i]=rand() % 1000 +
1;
}
//displaying all 20 values from a vector
cout<<"\nprinting from resized vector with 20
elements : \n";
for(i=0;i<20;i++)
{
cout<<vectorarray[i]<<"
";
}
delete[] array;
return 0;
}
OUTPUT:
please do let me know if u any
doubts related to above solution....
C++ data strucs aglorithms. Please do both parts short code tasks. attach output as well, both...
Need helps on C++ attach. Thanks
Pointers with classes a) A user-defined class named Timer has a constructor that takes two integer parameters to initialize hour and minute data members. Write a single C++ statement to create an object of the Timer class using dynamic memory allocation and assign it to a pointer variable named timePt r. It should call the constructor with two parameters. Use values of 10 and 20 for hour and minute respectively. b) Write the definition...
Write a C++ program named, gradeProcessor.cpp, that will do the following tasks: -Print welcome message -Generate the number of test scores the user enters; have scores fall into a normal distribution for grades -Display all of the generated scores - no more than 10 per line -Calculate and display the average of all scores -Find and display the number of scores above the overall average (previous output) -Find and display the letter grade that corresponds to the average above (overall...
(This program is to be done on Java) 7.5 ArrayLists Part 1 A significant limitation of the array is you cannot add or delete elements from the array. The size is fixed and you can only do workarounds. An example is the following: public class Ex_7_5_Prep { public static void main(String[] args) { int[] intArray = { 5, 10, 15, 20 }; printArray(intArray); intArray = addNewElement(intArray, 25); printArray(intArray); } public static int[] addNewElement(int[] originalArray, int newInt) { // Create new...
c++. please show screenshots of output
This project will continue to familiarize the student with using arrays. Store all the function proto-types in project11_funch and store all the functions in project11_func.cpp. Make sure you have proper header comments in each.h,.cpp file. When you run your program, your sample output should show your name. Your report should include the following: 1) project11_func.h 2) project11_func.cpp 3) project11.cpp 4) sample output Write the following functions: a) void fill_array_with_random_nums(int array(), int N): Fill array...
Please write below code in C++ using Visual
Studio.
Write program that uses a class template to create a set of items. The program should: 1. add items to the set (there shouldn't be any duplicates) • Example: if your codes is adding three integers, 10, 5, 10, then your program will add only two values 10 and 5 • Hint: Use vectors and vector functions to store the set of items 2. Get the number of items in the...
what would be the solution code to this problem in c++?
The Problem Write program that uses a class template to create a set of items. The program should: 1. add items to the set (there shouldn't be any duplicates) • Example: if your codes is adding three integers, 10, 5, 10, then your program will add only two values 10 and 5 Hint: Use vectors and vector functions to store the set of items 2. Get the number of...
Hello I need help with this program. Should programmed in C!
Program 2: Sorting with Pointers Sometimes we're given an array of data that we need to be able to view in sorted order while leaving the original order unchanged. In such cases we could sort the data set, but then we would lose the information contained in the original order. We need a better solution. One solution might be to create a duplicate of the data set, perhaps make...
Please solve only if you know how to do it. Write the code using
C++ (not Python or Java). Show and explain everything neatly.
COMMENTS (7.5% of programming assignment grade): Your program should have at least ten (10) different detailed comments explaining the different parts of your program. Each individual comment should be, at a minimum, a sentence explaining a particular part of your code. You should make each comment as detailed as necessary to fully explain your code. You...
Lab 3 – Array-Based Stack and Queue Overview In this assignment, you will be implementing your own Array-Based Stack (ABS) and Array-Based Queue (ABQ). A stack is a linear data structure which follows the Last-In, First-Out (LIFO) property. LIFO means that the data most recently added is the first data to be removed. (Imagine a stack of books, or a stack of papers on a desk—the first one to be removed is the last one placed on top.) A queue...
8.9 Coding lab #5: create a dynamic array ADT and a singly linked list ADT. Honor Code Your answers to this homework must be your own work.You are not allowed to share your solutions.You may not engage in any other activities that will dishonestly improve your results or dishonestly improve or damage the results of others. Plagiarism Plagiarism is when you copy words, ideas, or any other materials from another source without giving credit. Plagiarism is unacceptable in any academic environment....