Question

assume we have the following constant declarations const int MAXIMUM = 60; const int letters_Size =...

assume we have the following constant declarations
const int MAXIMUM = 60;
const int letters_Size = 15;
we then have the function
void Adjusting(char C_string[ ] [ ], int amount_words);
assume that youve taken in a string from the user now just simply read the input wnd analyze the sentence into its parts and describe its roles basically parse into words and save it and sort into an array of C-strings.
note code is in C++


complete the function definition according to the instructions provided.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the code for the above program:

#include<iostream>
#include<string>
#include<string.h>
using namespace std;
const int MAXIMUM = 60;
const int letters_Size = 15;
void Adjusting(char C_string[][MAXIMUM], int amount_words)
{

int i, j;
for (i = 0; i < amount_words-1; i++)   
  
// Last i elements are already in place
for (j = 0; j < amount_words-i-1; j++)
if (strcmp(C_string[j],C_string[j+1])>0)
swap(C_string[j],C_string[j+1]);
  
}
int main()
{
string s;
getline(cin,s);
int amount_words=0;
char C_string[100][MAXIMUM];
int j=0;
int k=0;
for(int i=0;i<s.length();i++)
{
if(s[i] ==' ') //whenever space occurs means word is completed
{
C_string[j][k]='\0';
k=0;
j++;
}
else //just add the character to the word
{
C_string[j][k]=s[i];
k++;
}
}
C_string[j][k]='\0'; //at last word we encountered no space that is why add '\0' at the end
amount_words=j;
Adjusting(C_string,amount_words);
cout<<"After adjusting string becomes\n";
for(int i=0;i<amount_words;i++)
cout<<C_string[i]<<" ";
}

here is the output of the program:

I hope this will help you so please give positive ratings :)))

Add a comment
Know the answer?
Add Answer to:
assume we have the following constant declarations const int MAXIMUM = 60; const int letters_Size =...
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
  • Part1. Write a C program contains the following declarations: char customer_name[N_CUSTOMERS][MAX...

    Part1. Write a C program contains the following declarations: char customer_name[N_CUSTOMERS][MAX_NAME_LENGTH]; int customer_number[N_CUSTOMERS] A program uses a text file that contains the following data on each line: The customer number is an int, and the first and last names are alphabetic strings that contain no whitespace. The last and first names themselves are however separated by whitespace. Write a C function with the following prototype: void read_customer (char name[][MAX_NAME_LENGTH], int number[], int position, FILE *cust_file) Your function should read a...

  • Program this in C There is a lot of sorting algorithms. So far, we have covered...

    Program this in C There is a lot of sorting algorithms. So far, we have covered selection and insertion sort. However, we only covered how selection sort is implemented using an array. Every sorting algorithm implemented using an array can also be implemented using a linked list. In this assignment, you will implement the selection sort algorithm using a linked list instead of an array. You will first create an interface for handling string items. Basically, you will need to...

  • Please help me with those 2 question problem, please help, thanks!! Code (Please use visual studio):...

    Please help me with those 2 question problem, please help, thanks!! Code (Please use visual studio): #include <stdio.h> #include <string.h> #pragma warning(disable : 4996) // compiler directive for Visual Studio only // Read before you start: // You are given a partially complete program. Your job is to complete the functions in order for this program to work successfully. // All instructions are given above the required functions, please read them and follow them carefully. // You shoud not modify...

  • Consider the following function definition and variable declarations: void square(int &n){n= n*n;} int arr[] = {1,...

    Consider the following function definition and variable declarations: void square(int &n){n= n*n;} int arr[] = {1, 2, 3}; int number = 4; Which of the following function calls are acceptable? (can have multiple answer) a.square(1); b.square(2); c.square(arr[number]); d.square(number); What is the output of the following code segment? int arr[] = {1, 4, 1, 0}; for (int i=0; i < 4; ++i)     cout<<arr[i]*2; a.1014 b.1 4 1 0 (space in between each number) c.1410 d.0140 e.None of the above Given...

  • Assume you have the following variable declarations and assignments: int j2: int k3; char c'h float...

    Assume you have the following variable declarations and assignments: int j2: int k3; char c'h float x2.3 Write single printf command to print the following output. The value of j is 2, and the value of x is -2.30, and the character c contains the value h. Note: You must make use of the variables as indicated by the desired output. For example, if the required output is: The value of j is 2. Then the following answer would be...

  • Hi this is C++, I'm really struggle with it please help me.... ************************ Here is the...

    Hi this is C++, I'm really struggle with it please help me.... ************************ Here is the original high score program,: Write a program that records high-score data for a fictitious game. The program will ask the user to enter five names, and five scores. It will store the data in memory, and print it back out sorted by score. The output from your program should look exactly like this: Enter the name for score #1: Suzy Enter the score for...

  • 4. [8] Write a C function with prototype void letter_freq(const char wordll, int freaq ); This...

    4. [8] Write a C function with prototype void letter_freq(const char wordll, int freaq ); This function computes the number of appearances of each letter in the string word and stores them irn array freq of size 26. The letters are the 26 letters of the Latin alphabet whose ASCII values are in the range 97-122 for the lower case letters, and in the range 65-90 for the uppercase letters. You must account for uppercase and lowercase letter variants, which...

  • QUESTION 1 Using the following declarations and a member of the Array class, int [ ]...

    QUESTION 1 Using the following declarations and a member of the Array class, int [ ] bArray = new int [10]; int location; Using a method in the Array class, write a statement that would change the order of the elements in the bArray array. The contents of the first cell should hold what was in the last cell. The second cell should hold what was in the next to last cell. __________________________ HINT: You must write the full statement...

  • Assume the following declarations have been made in main(): int howmany; Scanner kb = new Scanner(System.in);...

    Assume the following declarations have been made in main(): int howmany; Scanner kb = new Scanner(System.in); Random r = new Random(); Write code to do the following: Use a while loop to prompt the user for how many numbers are to be entered. If the user does not enter a positive number (a number greater than 0), display a message saying the number must be positive and to try again. Store this value in the howmany variable. Declare an integer...

  • Please use Visual Studio! Let me know if you need anything else <3 #include <stdio.h> #include...

    Please use Visual Studio! Let me know if you need anything else <3 #include <stdio.h> #include <string.h> #pragma warning(disable : 4996) // compiler directive for Visual Studio only // Read before you start: // You are given a partially complete program. Complete the functions in order for this program to work successfully. // All instructions are given above the required functions, please read them and follow them carefully. // You shoud not modify the function return types or parameters. //...

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