Question

In addition to these 10 functions, youll have 6 more functions void incDouble(double al], unsigned els); incDoubles job is can anyone help me with this 6 function as c++ language. It is not required to return in main.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

//C++ program

#include<iostream>
#include<vector>
using namespace std;

void incDouble(double a[] , unsigned els){
   for(int i=els-1;i>=0;i--){
       for(int j=0;j<i;j++){
           if(a[j]>a[j+1]){
               double temp=a[j];
               a[j]=a[j+1];
               a[j+1]=temp;
           }
       }
   }
}
void decDouble(double a[] , unsigned els){
   for(int i=els-1;i>=0;i--){
       for(int j=0;j<i;j++){
           if(a[j]<a[j+1]){
               double temp=a[j];
               a[j]=a[j+1];
               a[j+1]=temp;
           }
       }
   }
}
void incVec(vector<double> &v){
   int els=v.size();
   for(int i=els-1;i>=0;i--){
       for(int j=0;j<i;j++){
           if(v[j]>v[j+1]){
               double temp=v[j];
               v[j]=v[j+1];
               v[j+1]=temp;
           }
       }
   }
}

void decVec(vector<double> &v){
   int els=v.size();
   for(int i=els-1;i>=0;i--){
       for(int j=0;j<i;j++){
           if(v[j]<v[j+1]){
               double temp=v[j];
               v[j]=v[j+1];
               v[j+1]=temp;
           }
       }
   }
}

void weiredVec(vector<double>&v){
   incVec(v);
   int countless =0, equal =0,greater=0;
  
   for(int i=0;i<v.size();i++){
       if(v[i]<=-1)countless++;
       if(v[i]>-1 &&v[i]<1)equal++;
       else greater++;
   }
  
   int i=0,j=countless-1;
   while(i<j){
       double temp=v[j];
               v[j]=v[i];
               v[i]=temp;
               i++;
               j--;
   }
   i=countless;
   j=countless+equal-1;
   while(i<j){
       double temp=v[j];
               v[j]=v[i];
               v[i]=temp;
               i++;
               j--;
   }
   i=countless+equal;j=v.size()-1;
   while(i<j){
       double temp=v[j];
               v[j]=v[i];
               v[i]=temp;
               i++;
               j--;
   }
}

int main(){
   vector<double> vec;
   double arr[] = {7,3,0.5,-2,-4,.2,.7,-1,3};
   for(int i=0;i<sizeof(arr)/sizeof(arr[0]);i++)vec.push_back(arr[i]);
   weiredVec(vec);
  
   for(int i=0;i<vec.size();i++)cout<<vec[i]<<" ";
   return 0;
}

Add a comment
Know the answer?
Add Answer to:
can anyone help me with this 6 function as c++ language. It is not required to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • can anyone help me with this 6 function as c++ language. It is not required to return in main. In addition to these...

    can anyone help me with this 6 function as c++ language. It is not required to return in main. In addition to these 10 functions, you'll have 6 more functions void incDouble(double al], unsigned els); incDouble's job is to sort the array so that the values are in increasing order void decDouble(double al], unsigned els); decDouble's job is to sort the array so that the values are in decreasing order void inc Vec(vector<double> & v); incVec's job is to sort...

  • 28. Implement an overloaded member function of the IntVector class named assign. This version of assign passes in an ar...

    28. Implement an overloaded member function of the IntVector class named assign. This version of assign passes in an array of integers, along with 2 unsigned index values. This function may assume the indices are valid (i.e., does no bounds error checking on the array passed in). For example, if you have an array of integers named iarr with a size of 10, you can call assign on an IntVector named v like this: int iarr[] 1, 2, 3, 4,...

  • I need a c++ code please. 32. Program. Write a program that creates an integer constant...

    I need a c++ code please. 32. Program. Write a program that creates an integer constant called SIZE and initialize to the size of the array you will be creating. Use this constant throughout your functions you will implement for the next parts and your main program. Also, in your main program create an integer array called numbers and initialize it with the following values (Please see demo program below): 68, 100, 43, 58, 76, 72, 46, 55, 92, 94,...

  • help me solving this both please in c++ language 6 Write function max(int al Lint n)...

    help me solving this both please in c++ language 6 Write function max(int al Lint n) that receives an array of integer and its length, it returns the maximum number in that array. Test your function in main. 7) Write functin reverse (char x[ .int n) that reieves an array of characters and reverse the order of its elements. Test this function in main.

  • In below C++ sort.cpp 1- Implement the insertion_sort function. 2- Implement the compareSensorPtr function and the...

    In below C++ sort.cpp 1- Implement the insertion_sort function. 2- Implement the compareSensorPtr function and the code in main to create and sort the array of pointers. The places to make modifications are indicated by TODO: comments. You should not have to make modifications anywhere else. 3- what's big O and runtime for 100000 items. #include <iostream> #include <algorithm> #include <numeric> #include <vector> #include <string> #include <cstdlib> #include <cassert> using namespace std; // Set this to false to skip the...

  • In C please Write a function so that the main() code below can be replaced by...

    In C please Write a function so that the main() code below can be replaced by the simpler code that calls function MphAndMinutesToMiles(). Original maino: int main(void) { double milesPerHour, double minutes Traveled; double hours Traveled; double miles Traveled; scanf("%f", &milesPerHour); scanf("%lf", &minutes Traveled); hours Traveled = minutes Traveled / 60.0; miles Traveled = hours Traveled * milesPerHour; printf("Miles: %1f\n", miles Traveled); return 0; 1 #include <stdio.h> 3/* Your solution goes here */ 1 test passed 4 All tests passed...

  • this is c code. please answer all questions on a piece of paper and show work....

    this is c code. please answer all questions on a piece of paper and show work. i need to prepare as i have a midterm i will have to be completing on paper 1) Bit Operators: This C program compiles and runs. What is its output? 1) #include <stdio.h> 2) void main (void) 3) unsigned char x =60; 4) 5) 6) 7) 8 ) 9) 10) 11) 12) 13) unsigned char a = x < 1; unsigned char b unsigned...

  • Can anyone help me with this code? I've never worked with insertion sort and I'm having...

    Can anyone help me with this code? I've never worked with insertion sort and I'm having trouble. I posted the instructions and the included code. Thank you! Insertion Sort Given an array of integers, sort the array in ascending/descending order by using Insertion sort. Reference: http://www.algolist.net/Algorithms/Sorting/Insertion_sort Input 4368 92157 Where, • First line represents the type of ordering. • Second line represents the size of the array. • Third line represents the array elements. Output 123456789 + Test Case(s) DriverMain.java...

  • Use c++ as programming language. The file needs to be created ourselves (ARRAYS) Write a program...

    Use c++ as programming language. The file needs to be created ourselves (ARRAYS) Write a program that contains the following functions: 1. A function to read integer values into a one-dimensional array of size N. 2. A function to sort a one-dimensional array of size N of integers in descending order. 3. A function to find and output the average of the values in a one dimensional array of size N of integers. 4. A function to output a one-dimensional...

  • C++ Assignment - Only Implementation file( VectorDouble.cpp file) required. The header file is already given. Please help, thumbs up guaranteed. Chapter 8 discussed vectors, which are like arrays that...

    C++ Assignment - Only Implementation file( VectorDouble.cpp file) required. The header file is already given. Please help, thumbs up guaranteed. Chapter 8 discussed vectors, which are like arrays that can grow in size. Suppose that vectors were not defined in C++. Define a class called VectorDoublethat is like a class for a vector with base type double. Your class VectorDoublewill have a private member variable for a dynamic array of doubles. It will also have two member variables of type...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT