Question

c++ program 1a) Implement a class named ???????. Start by adding the following ?????? members: -...

c++ program

1a) Implement a class named ???????. Start by adding the following ?????? members:

- distance, a variable member of type double.

- Non-default constructor which receives a value in order to initialize the variable distance.

- Input stream operator to read a value from the command line into the variable distance.

1b) Write a test ???? as follows:

- Create a vector to hold instances of type ???????

- Use the following ??? loop to read values from the command prompt. Test input values are provided below.

??? (??? ? = 0; ? < 25; + + ?)

{ ??????? ?(−1); ??? >> ?; ?????. ???ℎ_????(?);

}

- Use the STL ???? function from the algorithm header file  Print the values of the ??????. Notice that the values are now sorted.

- Use the STL ???? function to search for a ??????? once with ???????? of 11.11 and once with ???????? of 73.9. Note that the ???? function accepts 3 arguments, ? ????? ????????, ?? ??? ????????, and ?? ?????? of type ???????. The ???? function returns an object of type iterator.

- If the value is found, print ?????. If the value is not found, print ??? ?????

Input these test values:

33.95

68.03

10.16

10.45

33.45

18.82

11.96

89.05

21.05

7.16

31.90

75.43

2.70

22.39

73.37

59.44

90.89

43.22

73.90

75.55

20.09

23.47

70.82

93.69

12.61

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

Please find the code below::

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
class DistObj{
public:
   double distance;
   DistObj(double d){
       distance = d;
   }
   friend istream& operator>>(istream& is, DistObj &obj);
   bool operator <(DistObj &obj){
       if(distance<obj.distance){
           return true;
       }else{
           return false;
       }
   }

   bool operator ==(const DistObj &obj){
       if(distance==obj.distance){
           return true;
       }else{
           return false;
       }
   }
};

istream& operator>>(istream& is, DistObj &obj) {
   is>>obj.distance;
   return is;
}

int main(){
   vector<DistObj> myVec;
   cout<<"Please enter distance below"<<endl;
   for(int i=0;i<25;i++){
       DistObj c(-1);
       cin>>c;
       myVec.push_back(c);
   }
   sort(myVec.begin(), myVec.end());

   cout<<"Sorted distance is as below"<<endl;
   for(int i=0;i<25;i++){
       cout<<myVec[i].distance<<endl;
   }

   vector<DistObj>::iterator iter;
   DistObj findMe(11.11);
   iter = find(myVec.begin(), myVec.end(), findMe);
   if(iter != myVec.end()){
       cout<<"FOUND"<<endl;
   }
   else
   {
       cout<<"NOT FOUND"<<endl;
   }

   DistObj findMe2(73.9);
   iter = find(myVec.begin(), myVec.end(), findMe2);
   if(iter != myVec.end()){
       cout<<"FOUND"<<endl;
   }
   else
   {
       cout<<"NOT FOUND"<<endl;
   }
   return 0;
}

output:

Add a comment
Know the answer?
Add Answer to:
c++ program 1a) Implement a class named ???????. Start by adding the following ?????? members: -...
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
  • Problem: Coffee(Java) Design and implement a program that manages coffees. First, implement an abstract class named...

    Problem: Coffee(Java) Design and implement a program that manages coffees. First, implement an abstract class named Coffee. The Coffee class has three member variables: coffee type(does not mention the data type of the variable coffeeType), price, and store name. The Coffee class has an abstract method name ingredient. Make sure to add all necessary setters and getters as well as other methods. The class Coffee implements an interface HowToMakeDrink. The interface has the following method: public interface HowToMakeDrink { public...

  • In C program #include<stdio.h> Task is to implement the Triangle Program in C. The specification for...

    In C program #include<stdio.h> Task is to implement the Triangle Program in C. The specification for the program is: The triangle program accepts three strings, a, b, and c (the sides of a triangle) as command line parameters. The sides of the triangle must be integers. The sides a, b, and c must satisfy the following conditions: c1. 1 ≤ a ≤ 200 c2. 1 ≤ b ≤ 200 c3. 1 ≤ c ≤ 200 c4. a < b +...

  • For this computer assignment, you are to write a C++ program to implement a class for...

    For this computer assignment, you are to write a C++ program to implement a class for binary trees. To deal with variety of data types, implement this class as a template. The definition of the class for a binary tree (as a template) is given as follows: template < class T > class binTree { public: binTree ( ); // default constructor unsigned height ( ) const; // returns height of tree virtual void insert ( const T& ); //...

  • For this c++ assignment, Overview write a program that will process two sets of numeric information....

    For this c++ assignment, Overview write a program that will process two sets of numeric information. The information will be needed for later processing, so it will be stored in two arrays that will be displayed, sorted, and displayed (again). One set of numeric information will be read from a file while the other will be randomly generated. The arrays that will be used in the assignment should be declared to hold a maximum of 50 double or float elements....

  • Python Please. a)Let a program store the result of applying the eval function to the first...

    Python Please. a)Let a program store the result of applying the eval function to the first command-line argument. Print out the resulting object and its type. Run the program with different input: an integer, a real number, a list, and a tuple. (On Unix systems you need to surround the tuple expressions in quotes on the command line to avoid error message from the Unix shell.) Try the string "this is a string" as a commandline argument. Why does this...

  • this is a C++ program! You will write a program that performs the following tasks for...

    this is a C++ program! You will write a program that performs the following tasks for a simple mathematical calculator: (1) Open a user-specified file for input. Prompt for the name of the file, read it into a string variable, echo print it to the terminal and then open it. If the file is not opened, enter into a loop that prints out an error message, resets the input file stream variable (see the hints section), obtains a new file...

  • 6.15 Program 6: Using Arrays to Count Letters in Text 1. Introduction In this program, you...

    6.15 Program 6: Using Arrays to Count Letters in Text 1. Introduction In this program, you will practice working with arrays. Your program will read lines of text from the keyboard and use an array to track the number of times each letter occurs in the input text. You will use the contents of this array to generate a histogram (bar graph) indicating the relative frequencies of each letter entered. Test cases are available in this document. Remember, in addition...

  • Write a C++ program named, gradeProcessor.cpp, that will do the following tasks: -Print welcome message -Generate...

    Write a C++ program named, gradeProcessor.cpp, that will do the following tasks: -Print welcome message -Generate the number of test scores the user enters; have scores fall into a normal distribution for grades -Display all of the generated scores - no more than 10 per line -Calculate and display the average of all scores -Find and display the number of scores above the overall average (previous output) -Find and display the letter grade that corresponds to the average above (overall...

  • Question 1) Consider a class Point that models a 2-D point with x and y coordinates. Define the c...

    C++ Question 1) Consider a class Point that models a 2-D point with x and y coordinates. Define the class point that should have the following Private data members x and y (of type int), with default values of 0 A constant ID of type int A private static integer data member named numOfPoints This data member should be o Incremented whenever a new point object is created. o Decremented whenever a point object is destructed. A default constructor An...

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
Active Questions
ADVERTISEMENT