حل شدہ اسائنمنٹس ڈانلوڈ کرنے کے لئے پہلے رجسڑ کریں پوسٹ کا جواب بھی دیا کریں جس اسائمنٹ کا حل نہ ملے اس کی سوالات کی فائل اپلوڈ کی کریں تاکہ اُس کا حل پوسٹ کیا جا سکے

Vu Help CS201 Assignment Solution How To Write Pointers In C++

This Section is For Vu Old Solved Assignments From Instructors which will be help full for you finding your Solution.
Forum rules
Post Only Old Assignments Which are Solved By Instructors Thanks
User avatar
Ali Raza Tawary
★★★★★★★★★★★★★
★★★★★★★★★★★★★
Posts: 190
Joined: Fri Dec 22, 2017 8:10 am
Location: Lahore
Contact:
Status: Offline

Medals

Vu Help CS201 Assignment Solution How To Write Pointers In C++

Post by Ali Raza Tawary »

Unlike other variables that hold values of a certain type, pointer holds the address of a variable.In computer science, a pointer is a programming language object that stores a memory address. This can be that of another value located in computer memory, or in some cases, that of memory mapped computer hardware.
 
Solution of Problem
 
#include <iostream>
#include <stdlib.h>     /*rand and srand function*/
#include <ctime>        /*time function*/
using namespace std;
 
const int arraySize = 5;
int array[arraySize];
int minVal=0;
int minValInd=0;
 
//Random Number Generation Function
void genRandNum(){
     srand(time(NULL));
     for(int i=0; i<arraySize; i++){
          array = (rand()%100)+1;

          cout << array  <<" ";

     }

     cout<< endl;

}

 

//Finding min value in unsorted array

void findMinNum(int unFirstIndex){

     minVal=array[unFirstIndex];

     for(int i=unFirstIndex; i<arraySize; i++){

          if(minVal>array){

              minVal=array;

              minValInd = i;

          }

     }

}

 

//Swaping min value with leftmost num in unsorted array

void swapValue(int unFirstIndex, int minValInd){

     int temp =array[unFirstIndex];

     array[unFirstIndex] = minVal;

     array[minValInd] = temp;

}

 

main(){

    

     //Generating random numbers and store in array

     cout<<"\n   Random Numbers are    : ";

     genRandNum();

    

     //Sorting the array using findmin and swaping values in array

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

          findMinNum(i);                            

          if(array!=minVal)

              swapValue(i,minValInd);

     }

    

     //Printing sorted array

     cout<<"Sorted Random Numbers are: ";

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

          cout<<array<<" ";

 

     cout<<"\n\n";

     system("pause");

}

 

 

Image

Last 10 Members Who Visited This Topic

User avatar Ali Raza Tawary (2), User avatar Muhammad bakar (1), User avatar Jea awan (1), User avatar aliraza (1)

Who is online

Users browsing this forum: No registered users and 2 guests