We are here with you hands in hands to facilitate your learning & don't appreciate the idea of copying or replicating solutions. Read More>>

Looking For Something at vustudents.ning.com? Click Here to Search

www.bit.ly/vucodes

+ Link For Assignments, GDBs & Online Quizzes Solution

www.bit.ly/papersvu

+ Link For Past Papers, Solved MCQs, Short Notes & More

Problem Statement:

 

In this assignment, you have to write a generic code to sort a dynamic array in ascending order which should work for all (short, int, long, float, double and char) data types.

 

Key points:

 

  • You have to write three template functions in your program which are:
  1. input()
  2. sort()
  3. display()
  • Template function input()  will take two argument: first is template type pointer of dynamic array and other is int type variable will used to save number of values in dynamic array. 

 

  • Template function sort()  will take two arguments: first is template type pointer of dynamic array and other is int type variable will used help to identify number of values in dynamic array what function will sort in ascending order. 

 

  • Template function display()  will take two arguments first is template type pointer of dynamic array and other is int type variable will used for number of iteration to display all values in array.

 

  • In main() function, you are required to create three dynamic arrays of int, float and char type and pass it to functions input(), sort() and display().

Discuss plzzzz

+ How to Follow the New Added Discussions at Your Mail Address?

+ How to Join Subject Study Groups & Get Helping Material?

+ How to become Top Reputation, Angels, Intellectual, Featured Members & Moderators?

+ VU Students Reserves The Right to Delete Your Profile, If?


See Your Saved Posts Timeline

Views: 6869

.

+ http://bit.ly/vucodes (Link for Assignments, GDBs & Online Quizzes Solution)

+ http://bit.ly/papersvu (Link for Past Papers, Solved MCQs, Short Notes & More)

+ Click Here to Search (Looking For something at vustudents.ning.com?)

+ Click Here To Join (Our facebook study Group)

Attachments:

Replies to This Discussion

G theek ha but aap variable names khud change kro. Or well-defined variable declare kro is mein meiney just idea k liye naam likhey hein. aap apney hisab se declare kro like integer array ko intarr k bjaaye Iarray F_array. Like this...

#include<iostream>
#include<conio.h>
using namespace std;


template< typename T>
void input(T* arr, int x)
{
  for(int i=0; i<x; i++)
  {       int j;
          cout"Enter:";
          cin>>arr[i];
          coutendl;
  } 
}

    template<typename T>
    void sort(T arr[], int n)
   {
     int min;
      T tem;     
      for (int i=0;i<n-1;i++)
      {
         min = i;
         for (int j=i+1;j<n;j++)
         {
             if (arr[j] < arr[min])
             {
                min = j;         
             }
         }
         if (min != i)
         {
          
            tem = arr[i];
            arr[i] = arr[min];
            arr[min] = tem;         
         } 
      }
    }

                  template< typename T>
                  void display(T* arr, int n)
                  {
                      for (int i=0;i<n;i++)
                        {
                                 cout arr[i] "\t ";   
                        }
                  }
                
    int main()
{
  
    int n;
  
  
    int intarr[5];
    cout"Enter The number of Element:\n";
    cin>>n;
    cout"Enter integer values...\n";
    input(intarr, n);
    sort(intarr, 5);
    cout"After Sorting\n";
    display(intarr, n);
    cout endl;
  
    float floarr[5];
     coutendl"Enter floating values...\n";
    input(floarr, n);
    sort(floarr, n);
    cout"After Sorting\n";
    display(floarr, n);   
    cout endl;
  
    char chararr[5];
     coutendl"Enter character values...\n";
    input(chararr, n);
    sort(chararr, n);
    cout"After Sorting\n";
    display(chararr, n);
    cout endl;
      system("pause");
}

 

CS304 assignment solution 

#include<iostream>
#include<conio.h>
#include<stdio.h>
using namespace std;
template <class t>
class initial
{
t a[25];
public:
void input(int);
void sort(int);
void display(int);
};
template <class t>
void initial <t>::input(int n)
{
int i;
for(i=0; i<n;i++){
cout"Enter:";
cin>>a[i];
cout"\n";
}
}
template <class t>
void initial <t>:: display(int n)
{
cout"\nAfter Sorting\n";
for(int i=0;i<n;i++)
couta[i]"\t";
cout"\n";
}
template <class t>
void initial <t>::sort(int n)
{
int i,j;
t thr;
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(a[i]>a[j])
{
thr=a[i];
a[i]=a[j];
a[j]=thr;
}
}
}
}

int main()
{
int t;
cout"Enter The number of Element:"endl;
cin>>t;
{
cout"Enter integer values..."endl;
initial<int> b1;
b1.input(t);
b1.sort(t);
b1.display(t);
};
{
cout"\nEnter floating Values..."endl;
initial<float> b2;
b2.input(t);
b2.sort(t);
b2.display(t); 
}; 

cout"\nEnter character Values..."endl;
initial<char> b3; 
b3.input(t);
b3.sort(t);
b3.display(t);
};

system("pause");
}

Dear Tariq Malik 

do you have any idea for other three data types how they include in this assignment 

the data types are short, long and double

RSS

Latest Activity

彡JK彡 ❤️ liked + M.Tariq Malik's discussion Everyone Freelancer Must Watch it - Most important video for Every fiver user
9 minutes ago
彡JK彡 ❤️ replied to +¢αяєℓєѕѕ gιяℓ's discussion Mera tu Mohabbat se aitbar.............:-P
10 minutes ago
彡JK彡 ❤️ liked +¢αяєℓєѕѕ gιяℓ's discussion Mera tu Mohabbat se aitbar.............:-P
11 minutes ago
彡JK彡 ❤️ replied to ٹمبکٹو's discussion محبّت اور دل - عشق مجازی
12 minutes ago
彡JK彡 ❤️ liked ٹمبکٹو's discussion محبّت اور دل - عشق مجازی
12 minutes ago
فقیہہ اقدس liked ٹمبکٹو's discussion محبّت اور دل - عشق مجازی
1 hour ago
Choudary Nafees Ejaz commented on + M.Tariq Malik's group STAT404 Regression and Correlation
3 hours ago
Choudary Nafees Ejaz joined + M.Tariq Malik's group
3 hours ago
Choudary Nafees Ejaz liked + M.Tariq Malik's group STAT404 Regression and Correlation
3 hours ago
MUHAMMAD KASHIF replied to + M.Tariq Malik's discussion ENG506 World Englishes Assignment No 01 Fall 2019 Solution & Discussion in the group ENG506 World Englishes
5 hours ago
MUHAMMAD KASHIF joined + M.Tariq Malik's group
5 hours ago
+ M.Tariq Malik replied to ayesha's discussion CS614 Assignment NO.1 Fall 2019 Solution&Discussion Due date: 14 Nov 2019 in the group CS614 Data Warehousing
5 hours ago
+ M.Tariq Malik replied to ayesha's discussion CS614 Assignment NO.1 Fall 2019 Solution&Discussion Due date: 14 Nov 2019 in the group CS614 Data Warehousing
5 hours ago
Profile IconKhadija Naveed, Muhammad Abdullah, maha khan and 6 more joined Virtual University of Pakistan
5 hours ago
MUHAMMAD KASHIF replied to + M.Tariq Malik's discussion ENG505 Language Learning Theories Assignment No 01 Fall 2019 Solution & Discussion in the group ENG505 Language Learning Theories
6 hours ago
MUHAMMAD KASHIF joined + M.Tariq Malik's group
6 hours ago
+ M.Tariq Malik replied to + M.Tariq Malik's discussion CS201 Assignment No 01 Fall 2019 Solution & Discussion Due Date: 14-11-2019 in the group CS201 Introduction to Programming
6 hours ago
+ M.Tariq Malik replied to + M.Tariq Malik's discussion PAK301 Assignment No 01 Fall 2019 Solution & Discussion Due Date: 21-11-2019 in the group PAK301 Pakistan Studies
6 hours ago
+ M.Tariq Malik replied to + M.Tariq Malik's discussion PAK301 Assignment No 01 Fall 2019 Solution & Discussion Due Date: 21-11-2019 in the group PAK301 Pakistan Studies
6 hours ago
+ M.Tariq Malik replied to Rana Ali's discussion EDU201 Learning Theories Assignment No 01 Fall 2019 Solution & Discussion in the group EDU201 Learning Theories
6 hours ago

© 2019   Created by + M.Tariq Malik.   Powered by

Promote Us  |  Report an Issue  |  Privacy Policy  |  Terms of Service