Question

In: Computer Science

Write a C++ PROGRAM: Add the function min as an abstract function to the class arrayListType...

Write a C++ PROGRAM:

Add the function min as an abstract function to the class arrayListType to return the smallest element of the list.

Also, write the definition of the function min in the class unorderedArrayListType and write a program to test this function.

Solutions

Expert Solution

#include <iostream>     // To use cout and cin
using namespace std;


class ArrayListType {
    
    // Abstract class: A class with atleast one pure virtual function or abstract function.
    // arrayListType: An abstract class
    // Member functions: min(): Pure virtual function or abstract function.

    public:
        virtual int min(int list[], int n) = 0;     // Pure virtual or abstract function.

};


class UnorderedArrayListType: public ArrayListType {
    
    //  unorderedArrayListType: Class inheriting arrayListType abstract class. 

    public:
 
        int min(int list[], int n) {
            int min = INT8_MAX;      // Taking min as max value of int data type.

            for ( int i = 0; i < n; i++ ) {
                
                if(list[i] < min)
                    min = list[i];

            }

            return min;

        }

};

int main() {
    
    // Your program start executing from here.
    
    UnorderedArrayListType uoalt;
    int n;
    cin >> n;
    int list[n];

    for (int i = 0; i < n; i++) {
        
        // Taking n elements
        
        cin >> list[i];
    }

    cout << "Minimun List Value: " << uoalt.min(list, n) << endl;

    return 0;
}

OUTPUT:


Related Solutions

WRITE IN C++ Add to the Coord class Edit the provided code in C++ Write a...
WRITE IN C++ Add to the Coord class Edit the provided code in C++ Write a member function named      int distance2origin() that calculates the distance from the (x, y, z) point to the origin (0, 0, 0) the ‘prototype’ in the class definition will be      int distance2origin() outside the class definition             int Coord :: distance2origin() {                         // your code } _______________________________________________________________________________________________________ /************************************************** * * program name: Coord02 * Author: * date due: 10/19/20 * remarks:...
Find MIN. Write a C# console app consisting of class MIN with the method CalculateMin() and...
Find MIN. Write a C# console app consisting of class MIN with the method CalculateMin() and the driver class. Print the MIN and MIN's location. Don't count numbers outside the range [0, 100].
Implement a program as an object using a class (abstract data type) in C++ that does...
Implement a program as an object using a class (abstract data type) in C++ that does the following: 1) reads the firstName, lastName and 3 test scores of at least five students. 2) calculate student test score totals, average, letter grade for each student. 3) Display the results in a table format showing firstName, lastName, test1, test2, test3, total, average, letterGrade, of all the students. 3 files .h, .cpp, main.cpp create an object that can hold records. must get records...
Write in C++ Abstract/Virtual Rock Paper Scissors Create an abstract Player class that consists of private...
Write in C++ Abstract/Virtual Rock Paper Scissors Create an abstract Player class that consists of private data for name, selection, wins, and losses. It must have a non-default constructor that requires name. It may not contain a default constructor. Create overloaded functions for the ++ and - - operator. The overloaded ++operator will add to the number of wins, while the - - operator will add to the losses. You will create two different child classes of player, Human and...
In C++ write a program with a base class thet has a pure virtual function SALARY,...
In C++ write a program with a base class thet has a pure virtual function SALARY, and two derived classes. In the first derived class salary is increased by 20%, in the second derived class salary is increased by 30%
Write a C program/code that prompts the user for a minimum min and a maximum max....
Write a C program/code that prompts the user for a minimum min and a maximum max. Then use these values to print the squares of all even numbers between the min and max variables. For example if the user enters 6 as the minimum and 200 as the maximum, the program/code should print the following. Enter limit on minimum square: 6 Enter limit on maximum square: 200 36 64 100 144 196
1.write a small program using a loop to add a series of numbers 2.write a function...
1.write a small program using a loop to add a series of numbers 2.write a function called "main" that performs several given steps. Be sure to call the main() function so that its code executes In python and doesn't have to be long. just long enough to do what it says. Thank you.
C# Programming (Class Registration class) Add a Schedule property to the Person class. Add a new...
C# Programming (Class Registration class) Add a Schedule property to the Person class. Add a new behavior as well: add(Section s) this behavior will add a section to the Person’s schedule. The Person’s display() function will also need to be modified to display() the Person’s Schedule. Schedule class has Properties: An array of Sections and a Count. Constructors: only a default constructor is needed. Behaviors: add() and display(). This is my schedule class class Schedule     {         private int...
Write a c++ class definition for an abstract data type describing a bookstore inventory. Each book...
Write a c++ class definition for an abstract data type describing a bookstore inventory. Each book has the following attributes: Book Title (character string); Book Author (character string); Book Price (Floating point number having two decimal places); Count of books on hand (int); The member functions are as follows: A constructor that is used to initialize all four elements of the structure to values inputted by the user; A function that displays in a readable tabular form the contents of...
(Problem is from the textbook Data Structures using C++) Add a function to the dateType class....
(Problem is from the textbook Data Structures using C++) Add a function to the dateType class. The function's name is compareDates. Its prototype is int compareDates(const dateType& otherDate; The function returns -1 if otherDate is greater than than this date The function returns 0 if otherDate equals this date The function returns 1 if otherDate is less than this date Examples dateType d1(1, 1, 2019); dateType d2(11,1, 2019) d1.compareDates(d2) returns -1 d2.compareDates(d1) returns 1 d2.compareDates(d2) returns 0 <<<<< dateType.h >>>>>>...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT