Question

Can you fix this program and run an output for me. I'm using C++ #include using...

Can you fix this program and run an output for me. I'm using C++

#include

using namespace std;

//function to calculate number of unique digit in a number and retun it

int countUniqueDigit(int input) {

   int uniqueDigitCount = 0;

   int storeDigit = 0;

   int digit = 0;

   while (input > 0) {

       digit = 1 << (input % 10);

       if (!(storeDigit & digit)) {

           storeDigit |= digit;

           uniqueDigitCount++;

       }

       input /= 10;

   }

   return uniqueDigitCount;

}

//function to get the largest number with largest unique digit

int getLIWLUDDigitCount() {

   //varibale declare

   int size, i, maxUniqueDigit, pos;

   //ask user size of array

   cout << "What is the size of array? " << endl;

   cin >> size;

   //initialize array withe size

   int a[size], uniqueDigit[size];

   //ask user the value in array and store in array

   for (i = 0; i < size; i++) {

       cout << "\n Value # " << (i + 1) << " ";

       cin >> a[i];

   }

   //sort the array

   sort(a, a + size);

   //store the unique digit count in uniqueDigit array for every digits

   for (i = 0; i < size; i++) {

       uniqueDigit[i] = countUniqueDigit(a[i]);

   }

   //check the maximum unique digit presnt

   maxUniqueDigit = uniqueDigit[0];

   for (int i = 0; i < size; i++) {

       if (maxUniqueDigit < uniqueDigit[i]) {

           maxUniqueDigit = uniqueDigit[i];

           pos = i;

       }

   }

   //return the number

   return a[pos];

}

int main()

{

   int choice;

   //dipplaying the template

   cout << "CIS 25 - C++ Programming " << endl;

   cout << "Laney College" << endl;

   cout << "Your Name" << endl;

   cout << "Assignment Information --" << endl;

   cout << " Assignment Number: Homework 02," << endl;

   cout << " Exersice #1" << endl;

   //pls give your name here

   cout << "Written by: Your Name" << endl;

   //pls give due date

   cout << "Due Date: Due Date" << endl;

   //while loop for menu creating

   do {

       //menu display

       cout << "*******************************" << endl;

       cout << "* Menu - Hw #2 *" << endl;

       cout << "* 1. getLIWLUDDigitCount() *" << endl;

       cout << "* 2. Quit *" << endl;

       cout << "*******************************" << endl;

       //ask user choice

       cout << "Select an option(use integer value only): " << endl;

       cin >> choice;

       //if user enter 1 then call the function

       if (choice == 1) {

           int n = getLIWLUDDigitCount();

           cout << "Largest number with largert unique digit is " << n << endl;

       }

       //display funny message

       else if (choice != 2) {

           cout << "You are very funny here" << endl;

       }

   } while (choice != 2);

   cout << "\n Having Fun...";

   return 0;

}

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

If you have any doubts, please give me comment...

#include<iostream>

#include<algorithm>

using namespace std;

//function to calculate number of unique digit in a number and retun it

int countUniqueDigit(int input)

{

    int uniqueDigitCount = 0;

    int storeDigit = 0;

    int digit = 0;

    while (input > 0)

    {

        digit = 1 << (input % 10);

        if (!(storeDigit & digit))

        {

            storeDigit |= digit;

            uniqueDigitCount++;

        }

        input /= 10;

    }

    return uniqueDigitCount;

}

//function to get the largest number with largest unique digit

int getLIWLUDDigitCount()

{

    //varibale declare

    int size, i, maxUniqueDigit, pos;

    //ask user size of array

    cout << "What is the size of array? " << endl;

    cin >> size;

    //initialize array withe size

    int *a = new int[size];

    int *uniqueDigit = new int[size];

    //ask user the value in array and store in array

    for (i = 0; i < size; i++)

    {

        cout << "\n Value # " << (i + 1) << " ";

        cin >> a[i];

    }

    //sort the array

    sort(a, a + size);

    //store the unique digit count in uniqueDigit array for every digits

    for (i = 0; i < size; i++)

    {

        uniqueDigit[i] = countUniqueDigit(a[i]);

    }

    //check the maximum unique digit presnt

    maxUniqueDigit = uniqueDigit[0];

    for (int i = 0; i < size; i++)

    {

        if (maxUniqueDigit < uniqueDigit[i])

        {

            maxUniqueDigit = uniqueDigit[i];

            pos = i;

        }

    }

int result = a[pos];

    delete a;

    delete uniqueDigit;

    //return the number

    return result;

}

int main()

{

    int choice;

    //dipplaying the template

    cout << "CIS 25 - C++ Programming " << endl;

    cout << "Laney College" << endl;

    cout << "Your Name" << endl;

    cout << "Assignment Information --" << endl;

    cout << " Assignment Number: Homework 02," << endl;

    cout << " Exersice #1" << endl;

    //pls give your name here

    cout << "Written by: Your Name" << endl;

    //pls give due date

    cout << "Due Date: Due Date" << endl;

    //while loop for menu creating

    do

    {

        //menu display

        cout << "*******************************" << endl;

        cout << "* Menu - Hw #2 *" << endl;

        cout << "* 1. getLIWLUDDigitCount() *" << endl;

        cout << "* 2. Quit *" << endl;

        cout << "*******************************" << endl;

        //ask user choice

        cout << "Select an option(use integer value only): " << endl;

        cin >> choice;

        //if user enter 1 then call the function

        if (choice == 1)

        {

            int n = getLIWLUDDigitCount();

            cout << "Largest number with largert unique digit is " << n << endl;

        }

        //display funny message

        else if (choice != 2)

        {

            cout << "You are very funny here" << endl;

        }

    } while (choice != 2);

    cout << "\n Having Fun...";

    return 0;

}

Let me know if you facing any issues like errors, etc... Thank you...

CIS 25 - C++ Programming Laney College Your Name Assignment Information -- Assignment Number: Homework 02, Exersice #1 Written by: Your Name Due Date: Due Date ******************************* * Menu - Hw #2 * * 1. getLIWLUDDigitCount() * * 2. Quit * ******************************* Select an option(use integer value only): What is the size of array? 10 Value # 1 3774 Value # 2 387 Value # 3 4387 Value # 4 348 Value # 5 9754 Value # 6 4764 Value # 7 873 Value # 8 648 Value # 9 4876 Value # 10 347 Largest number with largert unique digit is 4387

Add a comment
Know the answer?
Add Answer to:
Can you fix this program and run an output for me. I'm using C++ #include using...
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
  • I'm just a beginner in programming,how to make this program more simple without using #include<iostream> and #include<redex> here is the question Terms to know: If-else statement,for.....

    I'm just a beginner in programming,how to make this program more simple without using #include<iostream> and #include<redex> here is the question Terms to know: If-else statement,for..while..do while,loops,pointer,address,continue,return,break. Create a C++ program which contain a function to ask user to enter user ID and password. The passwordmust contain at least 6 alphanumeric characters, 1 of the symbols !.@,#,$,%,^,&,* and 1 capital letter.The maximum allowable password is 20. Save the information. Test the program by entering the User ID and password. The...

  • c++, I am having trouble getting my program to compile, any help would be appreciated. #include...

    c++, I am having trouble getting my program to compile, any help would be appreciated. #include <iostream> #include <string> #include <string.h> #include <fstream> #include <stdlib.h> using namespace std; struct record { char artist[50]; char title[50]; char year[50]; }; class CD { //private members declared private: string artist; //asks for string string title; // asks for string int yearReleased; //asks for integer //public members declared public: CD(); CD(string,string,int); void setArtist(string); void setTitle(string); void setYearReleased(int); string getArtist() const; string getTitle() const; int...

  • This is for a C++ program: I'm almost done with this program, I just need to...

    This is for a C++ program: I'm almost done with this program, I just need to implement a bool function that will ask the user if they want to repeat the read_course function. I can't seem to get it right, the instructions suggest a do.. while loop in the main function. here is my code #include <iostream> #include <cstring> #include <cctype> using namespace std; const int SIZE = 100; void read_name(char first[], char last[]); void read_course(int & crn, char des[],...

  • Can you tell me what is wrong and fix this code. Thanks #include <iostream> #include <string>...

    Can you tell me what is wrong and fix this code. Thanks #include <iostream> #include <string> #include <fstream> #include <sstream> using namespace std; //function void displaymenu1(); int main ( int argc, char** argv ) { string filename; string character; string enter; int menu1=4; char repeat; // = 'Y' / 'N'; string fname; string fName; string lname; string Lname; string number; string Number; string ch; string Displayall; string line; string search; string found;    string document[1000][6];    ifstream infile; char s[1000];...

  • I need help with this code. I'm using C++ and Myprogramming lab to execute it. 11.7:...

    I need help with this code. I'm using C++ and Myprogramming lab to execute it. 11.7: Customer Accounts Write a program that uses a structure to store the following data about a customer account:      Customer name      Customer address      City      State      ZIP code      Telephone      Account balance      Date of last payment The program should use an array of at least 20 structures. It should let the user enter data into the array, change the contents of any element, and display all the...

  • C++ getline errors I am getting getline is undefined error messages. I would like the variables...

    C++ getline errors I am getting getline is undefined error messages. I would like the variables to remain as strings. Below is my code. #include <iostream> #include<string.h> using namespace std; int index = 0; // variable to hold how many customers are entered struct Address //Structure for the address. { int street; int city; int state; int zipcode; }; // Customer structure struct Customer { string firstNm, lastNm; Address busAddr, homeAddr; }; // Functions int displayMenu(); Customer getCustomer(); void showCustomer(Customer);...

  • fully comments for my program, thank you will thumb up #include <iostream> #include <fstream> #include <string>...

    fully comments for my program, thank you will thumb up #include <iostream> #include <fstream> #include <string> #include <iomanip> using namespace std; struct book { int ISBN; string Author; string Title; string publisher; int Quantity; double price; }; void choice1(book books[], int& size, int MAX_SIZE) { ifstream inFile; inFile.open("inventory.txt"); if (inFile.fail()) cout <<"file could not open"<<endl; string str;    while(inFile && size < MAX_SIZE) { getline(inFile, str); books[size].ISBN = atoi(str.c_str()); getline(inFile, books[size].Title);    getline(inFile, books[size].Author); getline(inFile, books[size].publisher);          getline(inFile,...

  • C++ Object Oriented assignment Can you please check the program written below if it has appropriately...

    C++ Object Oriented assignment Can you please check the program written below if it has appropriately fulfilled the instructions provided below. Please do the necessary change that this program may need. I am expecting to get a full credit for this assignment so put your effort to correct and help the program have the most efficient algorithm within the scope of the instruction given. INSTRUCTIONS Create a fraction class and add your Name to the name fraction and use this...

  • So. I'm sick and I need help figuring out whatever is going on with this. #include...

    So. I'm sick and I need help figuring out whatever is going on with this. #include using namespace std; //prototypes int getExchangesInBubbleSort(int[], int); int getExchangesInSelectionSort(int[], int); int main() {    char choice;       cout << "1. Search Benchmarks\n";    cout << "2. Sorting Benchmarks\n";    do    {        int input;        cout << "Please enter the program you would like to run. \n";        cin >> input;               if (input == 1)...

  • The following is a sample inventory in C++, i want to ask the user to input a item number for removing from inventory. //CPP #include <iostream> #include <fstream> #include <cstdlib>...

    The following is a sample inventory in C++, i want to ask the user to input a item number for removing from inventory. //CPP #include <iostream> #include <fstream> #include <cstdlib> #include <iomanip> #define MAX 1000 using namespace std; //Function to Add a new inventory item to the data into the array in memory void addItem(string desc[],string idNum[], float prices[], int qty[],int &num) { cout<<"Enter the names:"; cin>>desc[num]; cout<<"Enter the item number:"; cin>>idNum[num]; cout<<"Enter the price of item:"; cin>>prices[num]; cout<<"Enter the...

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