Question

22:217 learn-ap-southeast-1-prod-fleet02-xythos.s3-ap-southeast-1.am purse Code: CSCI1540 (2019-20, Term 1) Page 2 of 6 2. (2

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

Thanks for the question. Below is the code you will be needing. Let me know if you have any doubts or if you need anything to change.

If you are satisfied with the solution, please rate the answer.

Thank You !


===========================================================================

#include <iostream>
using namespace std;


int distinct(int* p, int n){
  
   int *uniques = new int[n];
  
   int index =0;
  
   for(int i=0; i<n; i++){
      
       int num = *(p+i);
       bool exist=false;
       for(int k=0; k<index; k++){
           if(*(uniques+k)==num){
               exist=true;
               break;
           }
       }
      
       if(!exist){
           *(uniques+index++) = num;
       }
   }
   delete[] uniques;
   return index;
  
  
}


int main(){
  
   int p[] ={1,6,4,6,1,7,8,6,7,6,5,6,7,1,3,5,7,8,9,5,2,4,7,8,3};
   int n = sizeof(p)/sizeof(int);
  
   cout<<"Total unique elements: "<<distinct(p,n);
  
}

========================================================================

Q2.cpp 1 #include <iostream> 2 using namespace std; C:\UsersUser Documents\Q2.exe Total unique elements: 9 ---------- -------

Add a comment
Know the answer?
Add Answer to:
22:217 learn-ap-southeast-1-prod-fleet02-xythos.s3-ap-southeast-1.am purse Code: CSCI1540 (2019-20, Term 1) Page 2 of 6 2. (20%) Write a...
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
  • 1. Write code for a function that receives two parameters (a,and b) by value and two...

    1. Write code for a function that receives two parameters (a,and b) by value and two more parameters (c and d) by reference. All parameters are double. The function works by assigning c to (a/b) and assigning d to (a*b). The function has no return value. From main, use scanf to get two numbers, then call the function, and then display both outcome values to the output in a printf statement. 2. After part 1 is completed, write code to...

  • Need this in C Code is given below e Dots l lah dit Problem 1. (30...

    Need this in C Code is given below e Dots l lah dit Problem 1. (30 points) Fre bendord.cto obtain the free in decimal representation For ATY. this problem we complete the code in i tive long inte ens (W written the following positive long term 123, 40, 56, 7, 8, 9, 90, 900 the frequencies of all the digits are: 0:4, 1:1, 2:1, 3:1, 4:1, 5:1, 6:1, 7: 1. 8: 1.9: 3 In this example, the free ency of...

  • These are my answere to the following questions: are they right? 1. B 2. T 3....

    These are my answere to the following questions: are they right? 1. B 2. T 3. T 4. T 5. F 6. T 7. A 8. D 9. E 10. B 11. B 12. A 13. A 14. D 15. C 16. D 17. T 18. C 19. T 20. T 21. T 22. A 23. T 24. D 25. B 26. A 27. A 28. A 29. T 30. C 31. D 32. A 33. T 34. F 35....

  • Question 8 A = 23n + 36n2        B = 6 + nlog2(n) + n      C =...

    Question 8 A = 23n + 36n2        B = 6 + nlog2(n) + n      C = log2n + 36n2 Which one of the following is correct? A. TA = O(n2)    TB = O(n)   TC = O(log2n) B. TA = O(n2)      TB = O(nlog2(n))  TC = O(n2) C. TA = O(n2)      TB = O(+ nlog2(n))       TC = O(log2n) D. TA = O(n2)      TB = O(n)      TC = O(n2) 0.5 points Question 9 Three criteria are used to determine whether a data structure is...

  • please write the code in C++ 2 Base class File 3 Derived class PDF 3.1 Class...

    please write the code in C++ 2 Base class File 3 Derived class PDF 3.1 Class declaration • The class PDF inherits from File and is a non-abstract class 1. Hence objects of the class PDF can be instantiated. 2. To do so, we must override the pure virtual function clone) in the base class • The class declaration is given below. • The complete class declaration is given below, copy and paste it into your file. . It is...

  • Write a C or C++ program A6pc(pp) that accepts one command line argument which is an integer n between 2 and 6 inclusiv...

    Write a C or C++ program A6pc(pp) that accepts one command line argument which is an integer n between 2 and 6 inclusive. Generate a string of 60 random upper case English characters and store them somewhere (e.g. in a char array). Use pthread to create n threads to convert the string into a complementary string (‘A’<->’Z’, ‘B’<->’Y’, ‘C’<->’X’, etc). You should divide this conversion task among the n threads as evenly as possible. Print out the string both before...

  • Write a C or C++ program A6p2.c[pp] that accepts one command line argument which is an integer n between 2 and 4 inclusive. Generate 60 random integers between 1 and 39 inclusive and store them in a 5 by 12 two dimensional integer array (e.g.,int a[5][12]

    1.      Write a C or C++ program A6p2.c[pp] that accepts one command line argument which is an integer n between 2 and 4 inclusive. Generate 60 random integers between 1 and 39 inclusive and store them in a 5 by 12 two dimensional integer array (e.g.,int a[5][12];). Use pthread to create n threads to convert all 60 array elements modulo 11 (i.e. take the remainder after division by 11) in place. You should divide this update task among the n threads as evenly as possible. Print the array both before and after...

  • In below C++ sort.cpp 1- Implement the insertion_sort function. 2- Implement the compareSensorPtr function and the...

    In below C++ sort.cpp 1- Implement the insertion_sort function. 2- Implement the compareSensorPtr function and the code in main to create and sort the array of pointers. The places to make modifications are indicated by TODO: comments. You should not have to make modifications anywhere else. 3- what's big O and runtime for 100000 items. #include <iostream> #include <algorithm> #include <numeric> #include <vector> #include <string> #include <cstdlib> #include <cassert> using namespace std; // Set this to false to skip 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