Question

MUST BE IN C++ COMPATIBLE WITH VISUAL STUDIO ALL FILES INCLUDED MUST WORK MUST BE DONE...

MUST BE IN C++

COMPATIBLE WITH VISUAL STUDIO

ALL FILES INCLUDED

MUST WORK

MUST BE DONE USING A CHARACTER ARRAY TO MEET THE REQUIREMENT

1.You have the following clients for your consulting firm:

Client Business Type

Acme Construction

Johnsohn Electrical

Brown Heating and Cooling

Smith Switches

Jones Computers

Williams Cleaning Equipment

Machinery design

Switch manufacturing

Boiler design

Switch manufacturing

Computer sales

Machinery sales

To keep track of your clients in an orderly manner, you need a program that can arrange them alphabetically by name or by buisness type. Write such a program using a BUBBLE SORT. The input specifications are to read the client and business FROM A FILE. Read the rquirement of sorting according to name or business from the key board. The output specification is to put the arranged list into an OUTPUT FILE.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
#include <fstream>
#include <string.h>
using namespace std;

void swap(char c1[], char c2[]){
   char temp[100];
   strcpy(temp, c1);
   strcpy(c1, c2);
   strcpy(c2, temp);
}
int main(){
   ifstream inFile("input.txt");
   ofstream outFile("output.txt");
   char client[100][100], type[100][100];
   int count = 0, choice;
   string str;
   while(getline(inFile, str)){
       strcpy(client[count], str.c_str());
       getline(inFile, str);
       strcpy(type[count], str.c_str());
       count++;
   }
   cout << "Enter 1 to sort by Client name, 2 to sort by business type and anything other to exit:";
   cin >> choice;

   if(choice == 1){
       for(int i = 0; i < count - 1; i++){
           for(int j = 0; j < count - i - 1; j++){
               if(strcmp(client[j], client[j + 1]) >= 0){
                   swap(client[j], client[j + 1]);
                   swap(type[j], type[j + 1]);
               }
           }
       }
   }
   else if(choice == 2){
       for(int i = 0; i < count - 1; i++){
           for(int j = 0; j < count - i - 1; j++){
               if(strcmp(type[j], type[j + 1]) > 0){
                   swap(client[j], client[j + 1]);
                   swap(type[j], type[j + 1]);
               }
           }
       }
   }

   for(int i = 0; i < count; i++){
       string str1(client[i]);
       string str2(type[i]);
       outFile << str1 << "\n" << str2 << "\n\n";
   }
   cout << "Please check the output file 'output.txt' for the sorted results\n";
   return 0;
}

// Input file

input.txt Acme Construction Machinery design Johnsohn Electrical Switch manufacturing Brown Heating and Cooling Boiler design

// Sample output 1

output.txt Acme Construction Machinery design hacker@hacker: /Desktop Brown Heating and Cooling Boiler design File Edit View

// Sample output 2

output.txt Brown Heating and Cooling Boiler design hacker@hacker: IDesktop Jones Computers Computer sales File Edit View Sear

Add a comment
Know the answer?
Add Answer to:
MUST BE IN C++ COMPATIBLE WITH VISUAL STUDIO ALL FILES INCLUDED MUST WORK MUST BE DONE...
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
  • THIS MUST BE DONE ON VISUAL STUDIO Write a C# program that computes a the cost...

    THIS MUST BE DONE ON VISUAL STUDIO Write a C# program that computes a the cost of donuts at your local Rich Horton’s store. The cost, of course, depends on the number of donuts you purchase. The following table gives the break down: Donuts Purchased Cost per Donut ($) = 15 0.75 A customer can save on the HST (13%) if they buy 12 or more donuts so only charge HST (use a constant) on the purchase if the customer...

  • // Write the compiler used: Visual studio // READ BEFORE YOU START: // You are given...

    // Write the compiler used: Visual studio // READ BEFORE YOU START: // You are given a partially completed program that creates a list of patients, like patients' record. // Each record has this information: patient's name, doctor's name, critical level of patient, room number. // The struct 'patientRecord' holds information of one patient. Critical level is enum type. // An array of structs called 'list' is made to hold the list of patients. // To begin, you should trace...

  • This C++ Programs should be written in Visual studio 2017 PROGRAM 1: Comparing Using Arrays to...

    This C++ Programs should be written in Visual studio 2017 PROGRAM 1: Comparing Using Arrays to Using Individual Variables One of the main advantages of using arrays instead of individual variables to store values is that the program code becomes much smaller. Write two versions of a program, one using arrays to hold the input values, and one using individual variables to hold the input values. The programs should ask the user to enter 10 integer values, and then it...

  • It is a C++ program by using inheritance and vectors My professor said that all the files should be separate. like File.cpp, File.h, Text.cpp,Text.h,Main.cpp I already have these files File.cpp #inclu...

    It is a C++ program by using inheritance and vectors My professor said that all the files should be separate. like File.cpp, File.h, Text.cpp,Text.h,Main.cpp I already have these files File.cpp #include "File.h" // Constructor of File that takes File name and type as arguments File::File(string type, string name) {    this->type = type;    this->name = name; } //returns the type. string File::getType() {    return type; } //returns the name of file. string File::getName() {    return name; } File.h #ifndef __FILE_H__ #define...

  • If you’re using Visual Studio Community 2015, as requested, the instructions below should be exact but...

    If you’re using Visual Studio Community 2015, as requested, the instructions below should be exact but minor discrepancies may require you to adjust. If you are attempting this assignment using another version of Visual Studio, you can expect differences in the look, feel, and/or step-by-step instructions below and you’ll have to determine the equivalent actions or operations for your version on your own. INTRODUCTION: In this assignment, you will develop some of the logic for, and then work with, the...

  • Using C programming For this project, you have been tasked to read a text file with student grade...

    Using C programming For this project, you have been tasked to read a text file with student grades and perform several operations with them. First, you must read the file, loading the student records. Each record (line) contains the student’s identification number and then four of the student’s numerical test grades. Your application should find the average of the four grades and insert them into the same array as the id number and four grades. I suggest using a 5th...

  • Write a modularized, menu-driven program to read a file with unknown number of records.

    ==============C++ or java================Write a modularized, menu-driven program to read a file with unknown number of records.Create a class Records to store the following data: first and last name, GPA , an Id number, and an emailInput file has unknown number of records; one record per line in the following order: first and last names, GPA , an Id number, and emailAll fields in the input file are separated by a tab (‘\t’) or a blank space (up to you)No error...

  • Write in JAVA Get Familiar with the Problem Carefully read the program description and look at...

    Write in JAVA Get Familiar with the Problem Carefully read the program description and look at the data file to gain an understanding of what is to be done. Make sure you are clear on what is to be calculated and how. That is, study the file and program description and ponder! Think! The Storm Class Type Now concentrate on the Storm class that we define to hold the summary information for one storm. First, look at the definition of...

  • C++ Programming

    PROGRAM DESCRIPTIONIn this project, you have to write a C++ program to keep track of grades of students using structures and files.You are provided a data file named student.dat. Open the file to view it. Keep a backup of this file all the time since you will be editing this file in the program and may lose the content.The file has multiple rows—each row represents a student. The data items are in order: last name, first name including any middle...

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