Question

In: Computer Science

Please write code in c++. Use iostream (and any string library if you need it). Create...

Please write code in c++.

Use iostream (and any string library if you need it).

Create s structure plane :

First line contains n(0 < n < 1001).
Then n lines inputed in given format:
  First - ID[int type]
  Second - FromLocation[char*]
  Third - ToLocation[char*]
  Fourth - DepartureTime[char*]

Output:
Sorted list of planes should be in UPPER CASE.

Example of input:(it's just one of an examples, you need to write code generally)

10
40 Shuch Satp 05:47
89 Kyzy Taldy  07:00
95 Taldy Arka 03:20
61 Baiko Tara 06:31
73 Asta Akto 05:42
77 Akta Turkis 09:42
38 Oske Asta 08:35
94 Rid Sem 08:58
94 Taldy Baiko 03:00
55 Shah Temi 05:43

Output:

73 ASTA AKTO 05:42
95 TALDY ARKA 03:20
38 OSKE ASTA 08:35
94 TALDY BAIKO 03:00
40 SHUCH SATP 05:47
84 RID SEM 08:58
89 KYZY TALDY 07:00
61 BAIKO TARA 06:31
55 SHAH TEMI 05:43
77 AKTA TURKIS 09:42

As you see, you need to sort ToLocation by alphabet.

Solutions

Expert Solution

Program Code Screenshot

Program Sample Input/Output Screenshot

Program Code to Copy

#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>

using namespace std;

// create structure for plane
struct plane
{
   int ID;
   string FromLocation;
   string ToLocation;
   string DepartureTime;
};

// custom comparator to do sorting
bool sort_by_to_location(plane a, plane b)
{
   return a.ToLocation < b.ToLocation;
}

string toUpperCase(string word)
{
   // convert to uppercase
   for (int i = 0; i < word.size(); i++)
   {
      if (word[i] >= 'a' && word[i] <= 'z')
      {
         word[i] = word[i] - 'a' + 'A';
      }
   }
   return word;
}

int main()
{
   // create a vector of planes
   vector<plane> arr;

   // read input from command line
   int n;
   cin >> n;

   // read n values
   while (n--)
   {
      plane p;

      // read id
      cin >> p.ID;

      // read from
      cin >> p.FromLocation;

      //read to
      cin >> p.ToLocation;

      // read time
      cin >> p.DepartureTime;

      // convert from and to to uppercase
      p.FromLocation = toUpperCase(p.FromLocation);
      p.ToLocation = toUpperCase(p.ToLocation);

      // add in vector
      arr.push_back(p);
   }

   // sort using custom comparator
   sort(arr.begin(), arr.end(), sort_by_to_location);

   cout << endl
        << endl;
   // show output
   for (int i = 0; i < arr.size(); i++)
   {
      plane x = arr[i];
      cout << x.ID << " " << x.FromLocation << " " << x.ToLocation << " " << x.DepartureTime << endl;
   }
}

Related Solutions

Please, write code in c++. Using iostream and cstring library. Your friend is the person who...
Please, write code in c++. Using iostream and cstring library. Your friend is the person who does not like any limitations in the life. And when you said to him that it is totally impossible to work with integer numbers bigger than 4 294 967 296 in C++ he blamed you in time-wasting during the university study.So to prove that you hadn't waste 2 months of your life studying C++ in university you have to solve this issue. Your task...
please submit the C code( no third party library). the C code will create output to...
please submit the C code( no third party library). the C code will create output to a file, and iterate in a loop 60 times and each iteration is 1 second, and if any key from your keyboard is pressed will write a 1 in the file, for every second no key is pressed, will write a 0 into the output file.
-Write in C++ -Use Char library functions Write a function that accepts a string representing password...
-Write in C++ -Use Char library functions Write a function that accepts a string representing password and determines whether the string is a valid password. A valid password as the following properties: 1. At least 8 characters long 2. Has at least one upper case letter 3. Has at least one lower case letter 4. Has at least one digit 5. Has at least on special character
(Use the String Class to Solve This (and only the iostream, string and cctype libraries)) Write...
(Use the String Class to Solve This (and only the iostream, string and cctype libraries)) Write a program that can be used to train the user to use less sexist language by suggesting alternative versions of sentences given by the user. The program will ask for a sentence, read the sentence into a string variable, and replace all occurrences of masculine pronouns with gender-neutral pronouns. For example, it will replace “he” with “she or he”, and “him” with “her or...
C++ code Why my code is not compiling? :( #include <iostream> #include <iomanip> #include <string> using...
C++ code Why my code is not compiling? :( #include <iostream> #include <iomanip> #include <string> using namespace std; const int CWIDTH = 26; int main() {    int choice;    double convertFoC, converCtoF;    double starting, endvalue, incrementvalue;    const int CWIDTH = 13;    do {       cin >> choice;    switch (choice)    {        cin >> starting;    if (starting == 28){       cout << "Invalid range. Try again.";    }    while (!(cin >> starting)){       string  garbage;       cin.clear();       getline(cin, garbage);       cout << "Invalid data Type, must be a number....
(In C) Note: Can you create an example code of these tasks. use any variables you...
(In C) Note: Can you create an example code of these tasks. use any variables you wish to use. postfix expressions: (each individual text (T), (F), (NOT), etc is a token) F T NOT T F NOT T T T AND F T F NAND (1) Create stack s. (2) For each token, x, in the postfix expression: If x is T or F push it into the stack s. (T = true, F = false) Else if x is...
please write the code in C not c++, and not to use Atoi or parseint to...
please write the code in C not c++, and not to use Atoi or parseint to parse the string, Thank you. #include <stdio.h> #include <stdbool.h> /* * The isinteger() function examines the string given as its first * argument, and returns true if and only if the string represents a * well-formed integer. A well-formed integer consists only of an * optional leading - followed by one or more decimal digits. * Returns true if the given string represents an...
write this program in c++ using iostream library.( cin>>n; cin>> arr[n] and so on) Write a...
write this program in c++ using iostream library.( cin>>n; cin>> arr[n] and so on) Write a function that converts an array so that in the first half settled with elements from odd positions, and in the second half - with elements from the even positions.Positions are counted from the first index.The program have to use pointer. example: input: 7 1 2 3 4 5 6 7 output: 1 3 5 7 2 4 6 8
Please comments this C++ code and show screenshots of the outputs main.cpp #include<iostream> #include<vector> #include<string> #include"BST.h"...
Please comments this C++ code and show screenshots of the outputs main.cpp #include<iostream> #include<vector> #include<string> #include"BST.h" #include"BST.cpp" using namespace std; std::vector<std::string> tokenize(char line[]) {    std::vector<std::string> tok;        std::string word = "";        for (int i = 0; i < strlen(line); i++)        {            if (i == strlen(line) - 1)            {                word += line[i];                tok.push_back(word);                return tok;       ...
Hi, i need flowchart for this code (C++) please, THANX #include <iostream> #include <thread> #include <unistd.h>...
Hi, i need flowchart for this code (C++) please, THANX #include <iostream> #include <thread> #include <unistd.h> #include <semaphore.h> #include <pthread.h> using namespace std; #define NRO 6 // Número de coches //Puente declarado con matriz y valor entero void Puente(string array, int value); // Variable global int Norte = 1; int Sur = 1; sem_t mutex1; //Coche al norte void* NorteC(void* arg){ sem_wait(&mutex1); string array = "En el lado Norte "; // Norte cout<<array<<"del puente, el coche #"<<Norte<<" puede cruzar el...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT