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].
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...
The goal of this project is to practice (Write a C Program) with a function that...
The goal of this project is to practice (Write a C Program) with a function that one of its parameter is a function.The prototype of this function is: void func ( float (*f)(float*, int), float* a, int length); This means the function: func has three parameters: float (*f)(float*, int): This parameter itself is a function: f that has two parameters and returns a floating-point number. In the body of the function: func we call the function: f with its arguments...
1. Create a console program in C#, * Create a class: "Student.cs" * Add 3 variables:...
1. Create a console program in C#, * Create a class: "Student.cs" * Add 3 variables: StudentName (string), SchoolYear (int), YearsUntilGraduation(int) * Method YTK() = 12 - SchoolYear; 2. Main *Enter name *Enter age *You will attend school:____ years before graduating.
(C++ program) ***User Interface Write a program that offers an easy way to add items, remove...
(C++ program) ***User Interface Write a program that offers an easy way to add items, remove the last item, look at the last item put in the list. You will write all of the code for processing the stack - do not use any predefined objects in C++.  You decide how the interface will look. A menu driven program is always a good choice. ***Rules for program*** NEVER use break, exit, return, pass, continue or anything to leave a loop (or...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT