1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
elixir [45]
3 years ago
5

Write a C++ console program to do the following: 1. Define an array of ints with the ten elements { 0, 1,2,3, 4, 5, 6, 7, 8, 9 }

. 2. Define a vector with those ten elements. 3. Define a list with those ten elements. 4. Define a second array, vect
Computers and Technology
1 answer:
Gemiola [76]3 years ago
7 0

Answer:

#include<iostream>

#include <vector>

#include <list>

using namespace std;

int main(){

int a[10]={0,1,2,3, 4, 5, 6, 7, 8, 9 };

std::vector<int> v (&a[0],&a[0]+10);

std::list<int> l (&a[0],&a[0]+10);

int b[10];

for(int i=0;i<10;i++){

b[i]=a[i];

}

std::vector<int> v2(v);

std::list<int> l2(l);

for(int i=0;i<10;i++){

b[i]+=2;

}

for(int i=0;i<10;i++){

v2[i]+=3;

}

for (std::list<int>::iterator it = l2.begin(); it != l2.end(); it++)

*it=*it+5;

cout<<"Each containers value are: "<<endl;

cout<<"1st array: "<<endl;

for(int i=0;i<10;i++){

cout<<a[i]<<" ";

}

cout<<"\n 1st vector: \n";

for(int i=0;i<10;i++){

cout<<v[i]<<" ";

}

cout<<"\n 1st List is:\n";

for (std::list<int>::iterator it = l.begin(); it != l.end(); it++)

cout << *it << ' ';

cout<<"\n 2nd array: "<<endl;

for(int i=0;i<10;i++){

cout<<b[i]<<" ";

}

cout<<"\n 2nd vector:\n";

for(int i=0;i<10;i++){

cout<<v2[i]<<" ";

}

cout<<"\n 2nd list:\n";

for (std::list<int>::iterator it = l2.begin(); it != l2.end(); it++)

cout << *it << ' ';  

return 0;

}

Explanation:

  • Initialize an array, a vector and a list of type integer .
  • Create a 2nd array, vector, and list as a copy of the first array, vector, and list.
  • Increase the value of each element in the array by 2 , vector by 3 and list by 5.
  • Finally display the relevant results.
You might be interested in
Assuming a user enters 25 as input, what is the output of the following code snippet? int i = 0; Scanner in = new Scanner(System
Dmitry_Shevchenko [17]

Answer:

The correct answer for the given question is 24

Explanation:

In the given  question the value of variable i entered by the user is 25 i.e the value of i is 25 control checks the condition of if block which is false .So control moves to the else block and executed the condition inside the else block means it executed i-- decrements the value of i by 1 means i is 24

Following are the program of java :

import java.util.*;// import package

public class Main // main class

{

// main method

public static void main(String[] args)

{

int i = 0;  // variable declaration

Scanner in = new Scanner(System.in); // creating class of scanner class

System.out.print("Enter a number: ");

i = in.nextInt();  //  user input

if (i > 25)  // check if block

{

i++; // increment the value of i

}

else

{

   i--; // decrement the value of i

}

System.out.println(i);  // display i

}

}

Output:

Enter a number:25

24

8 0
4 years ago
Define a function setheight, with int parameters feetval and inchesval, that returns a struct of type heightftin. the function s
ehidna [41]

It is given that the feetVal and inchesVal are parameters of the SetHeight() function. Since the return type of the function is structute, so we need to define a structure.

After that, we need to create a structure variable within the function definition. Now, assign the feet and inches with the feetVal and inchesVal respectively. Finally return the structure variable.

Further explanation:

#include<stdio.h>

//define the structure

typedef struct HeightFtIn_struct {

int feet;

int inches;

} HeightFtIn;

//define the function

HeightFtIn SetHeight(int feetVal, int inchesVal)

{

HeightFtIn Htft; //creating a structure variable of type HeightFtIn

//assign the value of feetVal

Htft.feet = feetVal;  

Htft.inches = inchesVal; //assigning the value of inchesval

//return the structure variable

return Htft;

}

int main(void) {

HeightFtIn studentHeight;

int feet;

 int inches;

printf("Enter the values of feet and the inches: ");

scanf("%d %d", &feet, &inches);

studentHeight = SetHeight(feet, inches);

printf("The student's height is %d feet and %d inches.\n", studentHeight.feet, studentHeight.inches);

return 0;

}

Output:

Enter the values of feet and the inches: 5 9

The student's height is 5 feet and 9 inches.

Learn more:

1. A company that allows you to license software monthly to use online is an example of ? brainly.com/question/10410011  

2. How does coding work on computers?  brainly.com/question/2257971 

Answer details:

Grade: College Engineering

Subject: Computer Science

Chapter: C  Programming

Keyword:

C++, input, output, programming, statements,  loops, if, else, statements, firstname, lastname, base class, derive class, vector, print

6 0
3 years ago
Pleas help with this question: Which statement about word processing software is true?
deff fn [24]
Short Answer C

The Primary use of any word processor is to create word documents (like this editor) with the ability to format it with bold letters or <u>underlining</u> or <em>italics</em>. There are many other choices of things to do. All your choices are true but the main one is the third one down.

It can do very simple mathematical calculations if it can create tables (neither of which is possible with this editor. A is incorrect.

D is mostly incorrect. Very few word processors have built in capabilities that would help you with word games. There are some that do. Most don't.

I would hate to create fonts using a word processor. It's remotely possible, but anyone in his right mind would try using a program designed for that.. B is incorrect.
8 0
4 years ago
If my 98 dodge ram 1500 truck is dropping RPM's when i stop does that mean i need new throttle body sensors or does it mean i ne
geniusboy [140]
You might need a new 02 sensor and i really dont know about the vacuum leak.
6 0
3 years ago
Read 2 more answers
Look at the following assignment statements:
ziro4ka [17]

Answer: number 2 is the correct way to do it

Explanation:

3 0
3 years ago
Other questions:
  • Information storage:Select one:a. Eliminates the need for professional judgment.b. Keeps data in a form accessible to informatio
    9·1 answer
  • Which best describes the differences between a resume and a CV?
    13·2 answers
  • : Show that the propositions (p ∨ q) ∧ (¬p ∨ r) and (p ∧ r) ⊕ (¬p ∧ q) are logically equivalent.
    6·1 answer
  • Google Glass, glasses that allow you to take pictures and search online by speaking commands, are introduced at a technology tra
    8·1 answer
  • The problem analysis phase typically includes which of the following tasks? (Points : 2) Negotiate baseline scope.
    10·1 answer
  • Mencione algunos ejemplos en donde sean utilizadas las máquinas de aire comprimido. Justifique su respuesta.
    7·1 answer
  • Different between I time and E time​
    12·1 answer
  • You have been trying all day to check your direct messages on social media. The site is really slow to load and sometimes you ca
    13·1 answer
  • after adding a sound to a slide, the audio tools tab will allow you to apply artistic effects and quick styles to your sound ico
    7·1 answer
  • attackers typically use ack scans to get past a firewall or other filtering device. how does the process of an ack scan work to
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!