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
Yuki888 [10]
3 years ago
13

Write a program, named sortlist, that reads three to four integers from the command line arguments and returns the sorted list o

f the integers on the standard output screen. You need to use strtok() function to convert a string to a long integer. For instance,
Computers and Technology
1 answer:
yawa3891 [41]3 years ago
7 0

Answer:

In C++:

void sortlist(char nums[],int charlent){    

   int Myarr[charlent];

const char s[4] = " ";  

char* tok;  

tok = strtok(nums, s);  

int i = 0;  

while (tok != 0) {  

 int y = atoi(tok);

 Myarr[i] = y;

 tok = strtok(0, s);  

 i++;

}  

int a;  

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

for (int j = i + 1; j < charlent; ++j) {

 if (Myarr[i] > Myarr[j]) {

  a =  Myarr[i];

  Myarr[i] = Myarr[j];

  Myarr[j] = a;

       }   }  }

 

for(int j = 0;j<charlent;j++){ printf(" %d",Myarr[j]); }  

}

Explanation:

This line defines the sortlist function. It receives chararray and its length as arguments

void sortlist(char nums[],int charlent){    

This declares an array

   int Myarr[len];

This declares a constant char s and also initializes it to space

const char s[4] = " ";  

This declares a token as a char pointer

char* tok;

This line gets the first token from the char

tok = strtok(nums, s);

This initializes variable i to 0

int i = 0;

The following while loop passes converts each token to integer and then passes the tokens to the array  

<em> while (tok != 0) {  </em>

<em>  int y = atoi(tok); </em><em>-> Convert token to integer</em><em> </em>

<em>  Myarr[i] = y; </em><em>-> Pass token to array</em><em> </em>

<em>  tok = strtok(0, s); </em><em>-> Read token</em><em> </em>

<em>  i++; </em>

<em> }  </em>

Next, is to sort the list.

int a;

This iterates through the list  

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

This iterates through every other elements of the list

for (int j = i + 1; j < charlent; ++j) {

This condition checks if the current element is greater than next element

 if (Myarr[i] > Myarr[j]) {

If true, swap both elements

<em>   a =  Myarr[i]; </em>

<em>   Myarr[i] = Myarr[j]; </em>

<em>   Myarr[j] = a; </em>

       }   }  }

The following iteration prints the sorted array

<em>for(int j = 0;j<charlent;j++){ printf(" %d",Myarr[j]); }  </em>

}

<em>See attachment for illustration of how to call the function from main</em>

Download cpp
You might be interested in
Can you please look through this code and see wants wrong with it? its in python
Ivanshal [37]
I’m confused what are you trying to ask? What is the python?
3 0
2 years ago
Which wireless communication technology is most likely used when synchronizing device information to an automobile?
seropon [69]
Bluetooth is the most reasonable answer
8 0
3 years ago
Which process improves the life of a computer?
arlik [135]

maintenance is the answer

3 0
3 years ago
Double any element's value that is less than controlValue. Ex: If controlValue = 10, then dataPoints = {2, 12, 9, 20} becomes {4
Aleksandr [31]

Answer:

import java.util.Scanner;

public class StudentScores

{

public static void main(String[] args) {

 Scanner scnr = new Scanner(System.in);

 final int NUM_POINTS = 4;

 int[] dataPoints = new int[NUM_POINTS];

 int controlValue;

 int i;

 controlValue = scnr.nextInt();

 for (i = 0; i < dataPoints.length; ++i) {

     dataPoints[i] = scnr.nextInt();

 }

 for (i = 0; i < dataPoints.length; ++i) {

     System.out.print(dataPoints[i] + " ");

 }

 System.out.println();

 for (i = 0; i < dataPoints.length; ++i) {

     if(dataPoints[i] < controlValue){

         dataPoints[i] = dataPoints[i] * 2;          

     }

     System.out.print(dataPoints[i] + " ");

 }

}

}

Explanation:

*Added parts highligted.

After getting the control value and values for the array, you printed them.

Create a for loop that iterates through the dataPoints. Inside the loop, check if a value in dataPoints is smaller than the contorolValue. If it is, multiply that value with 2 and assign it to the dataPoints array. Print the elements of the dataPoints

5 0
3 years ago
Read 2 more answers
If you posted an advertisement for your research study on marriage on the Internet and the couples who responded (i.e., the coup
WITCHER [35]

Answer:

B. volunteer bias.

Explanation:

-Experimenter bias is when the expectations of the experimenter in regards to the outcome are communicated to the participants in any form.

-Volunteer bias refers to a situation in which the people that volunteer to take place in a study doesn't represent the general public.

-Research bias is when the experimenter influence the result to get a specific outcome.

-Social desirability bias is when the people taking part in a study give their responses in a way that is viewed as favorable.

According to this, the answer is that the situation would be an example of volunteer bias.

3 0
2 years ago
Other questions:
  • Assume arr2 is declared as a two-dimensional array of integers. Which of the following segments of code successfully calculates
    6·1 answer
  • ________ is the application of statistical techniques to find patterns and relationships among data for classification and predi
    14·1 answer
  • Type the correct answer in the box spell all words correctly
    8·1 answer
  • PLEASE HELP ASAP
    10·2 answers
  • Please help me please
    6·1 answer
  • Data that are collected on large populations of individuals and stored in databases are referred to as _____.
    15·1 answer
  • What tasks should a laptop accomplish?
    15·1 answer
  • 1) "Information systems are revolutionizing the way businesses function in the 21st century," Do you agree or disagree with this
    5·1 answer
  • c++ 4.17 LAB: Count characters Write a program whose input is a character and a string, and whose output indicates the number of
    14·1 answer
  • The _____ describes how data actually moves from an application on one computer to an application on another networked computer.
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!