Question

In: Computer Science

Write a C++ app to read both files, store them into parallel vectors, sort the list...

Write a C++ app to read both files, store them into parallel vectors, sort the list of people in alphabetical order, display the new sorted list of names with their corresponding descriptions. Use the Bubble Sort strategy to rearrange the vector(s).

File 1:

Marilyn Monroe
Abraham Lincoln
Nelson Mandela
John F. Kennedy
Martin Luther King
Queen Elizabeth II
Winston Churchill
Donald Trump
Bill Gates
Muhammad Ali
Mahatma Gandhi
Margaret Thatcher
Mother Teresa
Christopher Columbus
Charles Darwin
Elvis Presley
Albert Einstein
Paul McCartney
Queen Victoria
Pope Francis
Jawaharlal Nehru
Leonardo da Vinci
Vincent Van Gogh
Franklin D. Roosevelt
Pope John Paul II
Thomas Edison
Rosa Parks
Lyndon Johnson
Ludwig Beethoven
Oprah Winfrey
Indira Gandhi
Eva Peron
Benazir Bhutto
George Orwell
Desmond Tutu
Dalai Lama
Walt Disney
Neil Armstrong
Peter Sellers
Barack Obama
Malcolm X
J.K.Rowling
Richard Branson
Pele
Angelina Jolie
Jesse Owens
John Lennon
Henry Ford
Haile Selassie
Joseph Stalin
Lord Baden Powell
Michael Jordon
George Bush Jnr
Vladimir Lenin
Ingrid Bergman
Fidel Castro
Leo Tolstoy
Greta Thunberg
Pablo Picasso
Oscar Wilde
Coco Chanel
Charles de Gaulle
Amelia Earhart
John M Keynes
Louis Pasteur
Mikhail Gorbachev
Plato
Adolf Hitler
Sting
Mary Magdalene
Alfred Hitchcock
Michael Jackson
Madonna
Mata Hari
Cleopatra
Grace Kelly
Steve Jobs
Ronald Reagan
Lionel Messi
Babe Ruth
Bob Geldof
Leon Trotsky
Roger Federer
Sigmund Freud
Woodrow Wilson
Mao Zedong
Katherine Hepburn
Audrey Hepburn
David Beckham
Tiger Woods
Usain Bolt
Carl Lewis
Prince Charles
Jacqueline Kennedy Onassis
C.S. Lewis
Billie Holiday
J.R.R. Tolkien
Billie Jean King
Anne Frank
Simon Bolivar

File 2:

(1926 - 1962) American actress, singer, model
(1809 - 1865) US President during American civil war
(1918 - 2013) South African President anti-apartheid campaigner
(1917 - 1963) US President 1961 - 1963
(1929 - 1968) American civil rights campaigner
(1926 - ) British monarch since 1954
(1874 - 1965) British Prime Minister during WWII
(1946 - ) Businessman, US President.
(1955 - ) American businessman, founder of Microsoft
(1942 - 2016) American Boxer and civil rights campaigner
(1869 - 1948) Leader of Indian independence movement
(1925 - 2013) British Prime Minister 1979 - 1990
(1910 - 1997) Macedonian Catholic missionary nun
(1451 - 1506) Italian explorer
(1809 - 1882) British scientist, theory of evolution
(1935 - 1977) American musician
(1879 - 1955) German scientist, theory of relativity
(1942 - ) British musician, member of Beatles
( 1819 - 1901) British monarch 1837 - 1901
(1936 - ) First pope from the Americas
(1889 - 1964) Indian Prime Minister 1947 - 1964
(1452 - 1519) Italian, painter, scientist, polymath
(1853 - 1890) Dutch artist
(1882 - 1945) US President 1932 - 1945
(1920 - 2005) Polish Pope
( 1847 - 1931) American inventor
(1913 - 2005) American civil rights activist
(1908 - 1973) US President 1963 - 1969
(1770 - 1827) German composer
(1954 - ) American TV presenter, actress, entrepreneur
(1917 - 1984) Prime Minister of India 1966 - 1977
(1919 - 1952) First Lady of Argentina 1946 - 1952
(1953 - 2007) Prime Minister of Pakistan 1993 - 1996
(1903 - 1950) British author
(1931 - ) South African Bishop and opponent of apartheid
(1938 - ) Spiritual and political leader of Tibetans
(1901 - 1966) American film producer
(1930 - 2012) US astronaut
(1925 - 1980) British actor and comedian
(1961 - ) US President 2008 - 2016
(1925 - 1965) American Black nationalist leader
(1965 - ) British author
(1950 - ) British entrepreneur
(1940 - ) Brazilian footballer, considered greatest of 20th century.
(1975 - ) Actress, director, humanitarian
(1913 - 1980) US track athlete, 1936 Olympics
(1940 - 1980) British musician, member of the Beatles
(1863 - 1947) US Industrialist
(1892 - 1975) Emperor of Ethiopia 1930 - 1974
(1879 - 1953) Leader of Soviet Union 1924 - 1953
(1857 - 1941) British Founder of scout movement
(1963 - ) US Basketball star
(1946 - ) US President 2000-2008
(1870 - 1924) Leader of Russian Revolution 1917
(1915 - 1982) Swedish actress
(1926 - ) President of Cuba 1976 - 2008
(1828 - 1910) Russian author and philosopher
(2003 - ) Environmentalist activist)
(1881 - 1973) Spanish modern artist
(1854 - 1900) Irish author, poet, playwright
(1883 - 1971) French fashion designer
(1890 - 1970) French resistance leader and President 1959 - 1969
(1897 - 1937) Aviator
(1883 - 1946) British economist
(1822 - 1895) French chemist and microbiologist
(1931 - ) Leader of Soviet Union 1985 - 1991
(423 BC - 348 BC) Greek philosopher
(1889 - 1945) leader of Nazi Germany 1933 - 1945
(1951 - ) British musician
(4 BCE - 40CE) devotee of Jesus Christ
(1899 - 1980) English / American film producer, director
(1958 - 2009) American musician
(1958 - ) American musician, actress, author
(1876 - 1917) Dutch exotic dancer, executed as spy
(69 - 30 BCE) Queen of Egypt
(1929 - 1982) American actress, Princess of Monaco
(1955 - 2012) co-founder of Apple computers
(1911 - 2004) US President 1981-1989
(1987 - ) Argentinian footballer
(1895 - 1948) American baseball player
(1951 - ) Irish musician, charity worker
(1879 - 1940) Russian Marxist revolutionary
(1981 - ) Swiss Tennis player
(1856 - 1939) Austrian psychoanalyst
(1856 - 1924) US president 1913 - 1921
(1893 - 1976) Leader of Chinese Communist revolution
(1907 - 2003) American actress
(1929 - 1993) British actress and humanitarian
(1975 - ) English footballer
(1975 - ) American golfer
(1986 - ) Jamaican athlete and Olympian
(1961 - ) US athlete and Olympian
(1948 - ) Heir to British throne
(1929 - 1994) American wife of JF Kennedy
(1898 - 1963) British author
(1915 - 1959) American jazz singer
(1892 - 1973) British author
(1943 - ) American tennis player and human rights activist
(1929 - 1945) Dutch Jewish author who died
(1783 - 1830) Venezuelan independence activist in South America

Solutions

Expert Solution

C++ CODE:

#include <iostream>
#include <vector>
#include <fstream>
#include <string>
using namespace std;
// Function to sort names and descriptions in alphabetical order by name
void sort(vector<string> &names, vector<string> &desc){
    for(int i = 0; i < names.size() - 1; i++){
        for(int j = 0; j < names.size() - i - 1; j++){
            if(names[j] > names[j + 1]){
                // Swap
                string temp = names[j];
                names[j] = names[j + 1];
                names[j + 1] = temp;
                temp = desc[j];
                desc[j] = desc[j + 1];
                desc[j + 1] = temp;
            }
        }
    }
}
int main(){
    ifstream infile1("names.txt");
    ifstream infile2("descriptions.txt");
    // Check if file opened or not
    if(!infile1 || !infile2){
        cout << "Error: Cannot open file" << endl;
        return 1;
    }
    vector<string> names, desc;
    string input;
    // Read names from names.txt file
    while(!infile1.eof()){
        getline(infile1, input);
        names.push_back(input);
    }
    // Read descriptions from descriptions.txt file
    while(!infile2.eof()){
        getline(infile2, input);
        desc.push_back(input);
    }
    // Sort names and their description in alphabetical order
    sort(names, desc);
    for(int i = 0; i < names.size(); i++){
        cout << names[i] << " - " << desc[i] << endl;
    }
    return 0;
}

INPUT FILES USED:

names.txt:

descriptions.txt:

OUTPUT:

FOR ANY HELP JUST DROP A COMMENT


Related Solutions

Objectives:  Write classes in C++  Use dynamic arrays  Write and read from files...
Objectives:  Write classes in C++  Use dynamic arrays  Write and read from files 1. WriteaclassGradeBookcontainingthefollowing: Private attributes: - courseName: a string representing the name of the course. - nbOfStudents: an integer representing the number of students enrolled in the course. The number of students is greater than or equal to 5. - grades: a double dimensional array of integers representing the grades of Test1, Test2 and Final of every student. It should be a dynamic array. Public...
Write an app that works in both vertical and horizontal orientations. The app is a variety...
Write an app that works in both vertical and horizontal orientations. The app is a variety of the game of nim. Two players take turns removing identical objects from a set of objects. A player can remove one, two, or three objects at a time. The player who takes the last object loses. You can store the current number of objects in a TextView and get user input via an EditText. Include a Model. Generate randomly the starting number of...
Question6: Write a program to read the file 202010mid.txt, store the content in a list of...
Question6: Write a program to read the file 202010mid.txt, store the content in a list of tuples, then print the list. [6 marks] Question7: Write Python code to do the following operations using request library. [12 marks] Check if the following webpage is available or not: https://edition.cnn.com/news.html [4 marks] Send a get request to the following webpage and show the result: http://api.open-notify.org/iss-pass.json [4 marks] The webpage from part 2 is expecting some parameters as shown from the results. Now create...
C++ Bubble Sort Write a program that ask user to enter 7 numbers and store that...
C++ Bubble Sort Write a program that ask user to enter 7 numbers and store that in array. Display that all numbers before and after performing Bubble sort. You must have to create new function with required parameter to perform Bubble sort. Sample Run :- Enter 1 number :- 1 Enter 2 number :- 5 Enter 3 number :- 7 Enter 4 number :- 45 Enter 5 number :- 90 Enter 6 number :- 6 Enter 7 number :- 55...
I am Writing a C-Program to read and write files. but none of my code is...
I am Writing a C-Program to read and write files. but none of my code is working like it should be. Please fix all code and supply output response. Please try to use existing code and code in comments. But if needed change any code that needs to be changed. Thank you in advance //agelink.c //maintains list of agents //uses linked list #include <stdio.h> #include <stdlib.h> #define TRUE 1 void listall(void); void newname(void); void rfile(void); void wfile(void); struct personnel {...
C++. Write a program that will read in id numbers and place them in an array.The...
C++. Write a program that will read in id numbers and place them in an array.The array is dynamically allocated large enough to hold the number of id numbers given by the user. The program will then input an id and call a function to search for that id in the array. It will print whether the id is in the array or not. Sample Run: Please input the number of id numbers to be read 4 Please enter an...
Write words in parallel read learn understood
Write words in parallel read learn understood
C++ programming language. Write a program that will read in id numbers and place them in...
C++ programming language. Write a program that will read in id numbers and place them in an array.The array is dynamically allocated large enough to hold the number of id numbers given by the user. The program will then input an id and call a function to search for that id in the array. It will print whether the id is in the array or not. Sample Run: Please input the number of id numbers to be read 4 Please...
Write Insertion Sort and Bubble Sort Program for C# also write their algorithm and Explain their...
Write Insertion Sort and Bubble Sort Program for C# also write their algorithm and Explain their working.
Write a C program that will read different data types from the following file and store...
Write a C program that will read different data types from the following file and store it in the array of structures. Given file: (This file have more than 1000 lines of similar data): time latitude longitude depth mag magType nst gap dmin 2020-10-19T23:28:33.400Z 61.342 -147.3997 12.3 1.6 ml 12 84 0.00021 2020-10-19T23:26:49.460Z 38.838501 -122.82684 1.54 0.57 md 11 81 0.006757 2020-10-19T23:17:28.720Z 35.0501667 -117.6545 0.29 1.51 ml 17 77 0.1205 2020-10-19T22:47:44.770Z 38.187 -117.7385 10.8 1.5 ml 15 100.22 0.049 2020-10-19T22:42:26.224Z...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT