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
klio [65]
1 year ago
11

c g given an array, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero eleme

nts
Computers and Technology
1 answer:
o-na [289]1 year ago
6 0

The output for an array of elements [0,1,0,3,12] is  [1,3,12,0,0]

<h3>What is the function to get the desired output?</h3>
  • Let us consider an array of elements,

          Input = [0,1,0,3,12]

  • The function code is given by,

class Solution {

public:

   void moveZeroes(vector<int>& nums) {

       int count=0;

       for(int i=0;i<nums.size();i++)

       {

           if(nums[i]==0)

           {

               nums.erase(nums.begin()+i);

               ++count; //This is to count number of zeroes.

           }

       }

      for(int i = 0 ; i<count ; i ++)

          nums . push_back(0);  //To input zero at the end of the vector count times.      

}

};

The output for an array of elements [0,1,0,3,12] is  [1,3,12,0,0] where all 0's are moved to the end,  while maintaining the relative order of the non-zero elements,

<h3>What is an array?</h3>
  • A collection of items that are either values or variables is referred to as an array in computer science.
  • Each element is identifiable by at least one array index or key.
  • Each element of an array is recorded such that a mathematical formula can be used to determine its position from its index tuple.
  • A linear array, often known as a one-dimensional array, is the simplest sort of data structure.

To learn more about array, refer:

brainly.com/question/19634243

#SPJ4

You might be interested in
Please help with this coding question
snow_tiger [21]
Answer: the variable called errors is tested to see if it is less than it equal to 4
8 0
3 years ago
Read 2 more answers
________ hackers break into systems for non-malicious reasons such as to test system security vulnerabilities. black-hat gray-ha
Masteriza [31]
<span>These are white-hat hackers. They are typically hired by the company doing the testing as a way of making sure that there are no bugs or holes in the code or program that could be exploited. The ethical hacker would look for ways to get around these issues and helps the company strengthen their programs or sites.</span>
3 0
2 years ago
Helpppppp me please cuz its due rn. put the correct word in the correct spot
tiny-mole [99]

Answer:

Inside air pressure goes on the top in the inside.

Air moves goes into the bottom box.

Outside air pressure goes on the top.

Balloon moves goes on the inside bottom.

6 0
3 years ago
Create a SavingsAccount class. Use a static data member annualInterestRate to store the annual interest rate for each of the sav
andrew-mc [135]

Answer:

see explaination

Explanation:

SavingsAccount.h

#pragma once

#ifndef SAVINGS_H

#define SAVINGS_H

//SavingsAccount class declaration

class SavingsAccount

{

//declare data members

private:

//set annualInterestRate to 0.0 default value

static double annualInterestRate;

double savingsBalance;

public:

//set the balance

void setBalance(double);

//modify interest rates

static void modifyInterestRate(double);

//retruns total balance with interest

double calculateMonthInt();

};

#endif

SavingsAccount.cpp

//include required header files

#include<iostream>

#include"SavingsAccount.h"

using namespace std;

//set the annualInterestRate to 0

double SavingsAccount::annualInterestRate = 0;

//static funtion modify interest rate

void SavingsAccount::modifyInterestRate(double iRate)

{

annualInterestRate = iRate;

}

//set the balance

void SavingsAccount::setBalance(double bal)

{

savingsBalance = bal;

}

//calculating savings balance with monthly interest

double SavingsAccount::calculateMonthInt()

{

double monthInt = 0;

monthInt += savingsBalance*annualInterestRate / 12;

return savingsBalance += monthInt;

}

DriverProgram.cpp

//include required header files

#include<iostream>

#include "SavingsAccount.h"

using namespace std;

//main methods

int main()

{

//delcare class objects

SavingsAccount saver1, saver2;

//setter functions of balance

saver1.setBalance(2000.00);

saver2.setBalance(3000.00);

//Setting annual interset 0.03 to static variable

saver1.modifyInterestRate(0.03);

//finding the balance in saver1 and saver2 account

cout << "Balance of saver1 and saver2 on 3% interest Rate\n";

cout << "--------------------------------------------------\n";

cout << "Balance of saver1 = " << saver1.calculateMonthInt()

<< endl;

cout << "Balance of saver2 = " << saver2.calculateMonthInt()

<< endl << endl;

//Setting annual interset 0.04 to static variable

saver1.modifyInterestRate(0.04);

cout << "Balance of saver1 and saver2 on 4% interest Rate\n";

cout << "---------------------------------------------------\n";

cout << "New Balance of saver1 = " << saver1.calculateMonthInt() << endl;

cout << "New Balance of saver2 = " << saver2.calculateMonthInt() << endl<<endl;

return 0;

}

4 0
3 years ago
In which situation is coauthoring of presentations primarily utilized?
fenix001 [56]

Answer:

C) Multiple reviewers have to be able to view one another's changes after they are made.

Explanation:

5 0
3 years ago
Other questions:
  • WILL GIVE BRAINLIEST! A rent payment is an example of which type of expense?
    14·2 answers
  • Writenames of eight output device.​
    8·1 answer
  • I dopped my Fujifilm Instax mini 8 and now the case won't close and it takes blank pictures can anyone tell me what to do, pleas
    6·2 answers
  • This library function returns a random floating point number within a specified range of values. The function returns a random f
    12·1 answer
  • Match these items. 1 . Naturalization Act stated that a foreigner had to live in the United States fourteen years to become a ci
    5·1 answer
  • A girl scout troop with 10 girl scouts and 2 leaders goes on a hike. When the path narrows, they must walk in single file with a
    12·1 answer
  • Okay, guys, I know this one will be very hard however while trying to finish this assignment I got overwhelmed and lost by the s
    9·1 answer
  • PLZ HELP What will be the output? class num: def init (self.a): self. number = a mul* __(self. b) return self. number + b. numbe
    7·1 answer
  • Which one is better AMD Ryzen 5 Or Nvidia Gtx 2080 ti
    6·1 answer
  • I need help now with YT
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!