Latest Activity In Study Groups

Join Your Study Groups

VU Past Papers, MCQs and More

We non-commercial site working hard since 2009 to facilitate learning Read More. We can't keep up without your support. Donate.


CS201 Assignment No 02 Solution & Discussion Due Date: 02 Dec 2016

Assignment

 

 

  • Write a program that takes input of 10 integers into an array.
  • Give two options to the user:

1= copy odd numbers from the array to a new array (odd[] array) and sort “odd[]”  array in ascending order

and

2= copy even numbers from the array to a new array (even[] array) and sort “even[]” array in ascending order

 

 

  • Write a function that accept (odd[] or even[]) array and sort it
  • Use bubble sort technique to sort the given array
  • Display the sorted array.

    Hint:: you can use 3 arrays like arry[], odd[], even[].

 

 

 

 

Sample output:

 

 

  • Taking input for array from user

 

 

 

  • Ask user for an option

 

 

 

  • Pass array to function and display sorted array

 

 

 

 

 

 

 

Deadline:

The deadline to submit your assignment solution is 2nd December, 2016. Your assignment must be submitted within the due date through VULMS. No assignment will be accepted through email after the due date.

 

Views: 4113

Replies to This Discussion

ap jahnan pr return0 likha hoa hy waha pr us ko remove kr k getch(); likhy gy to apka program crash nai ho ga

CS201_2nd-Assignment-Final-Solution

Attachments:

#include 
using namespace std;
void sort (int arry[], int b){
int temp;
for (int i =0; iarry[j+1]){

temp = arry[j];
arry[j]=arry[j+1];
arry[j+1] = temp;
}
}
}
}
int main (){
int array[10];
int odd [10];
int even [10];
int option, a =0;
cout "Enter 10 Element for Array: \n"; for (int i =0; i<10; i++){ cin>> array [i];
}
cout "For odd Number in Accending Order: Press 1 \n"; cout "For Even Number in Accending Order: Press 2 \n"; cin>> option;
if (option==1){
for (int i=0; i<10; i++) { if (array[i]%2==1){ odd[a] = array[i]; a++; } } sort(odd, a); cout " Total Odd Numbers Are: "/p>

#include<iostream.h>
main()
{
//declare variables

int number, digit;

//prompt the user for input

cout "Please enter four number:";

cin >> number;

// get the first digit and display it on screen

digit = number % 10;

cout "The digits are: ";

cout digit ", ";

// get the remaining three digits number

number = number / 10;

// get the next digit and display it

digit = number % 10;

cout digit ", ";

// get the remaining two digits number

number = number / 10;

// get the next digit and display it

digit = number % 10;

cout digit ", ";

// get the remaining one digit number

number = number / 10;

// get the next digit and display it

digit = number % 10;

cout digit;
return 0;
system ("pause");

}

#include <iostream>

using namespace std;
void display(int dis[10] ,int xx);


void bubblesort (int arr[10] ,int x)
{
int temp;
int num[x];
for (int i=0 ; i<=x ; i++)
{num[i]=arr[i];}

for (int i=0 ; i<=x ; i++)
{
for (int j=0 ; j<x ; j++)
{
if (num[j]>num[j+1])
{
temp = num[j];
num[j]=num[j+1];
num[j+1]=temp;
}
}
}
display (num, x);
}
main()
{
int arr[10];
int j=0 , k=0,E=0,O=0;
cout"Enter 10 values in array"endl;
for (int i=0 ; i<10 ; i++)
{ cin>> arr[i];}

/////////////////////////////////////////////
for (int i=0 ; i<10 ; i++)
{
if (arr[i]%2==0) // count even and odd values
{E++;}
else
{O++;}
}
cout E" "Oendl;
///////////////////////////////////////////

int odd[O] , even[E];

for (int i=0 ; i<10 ; i++) // put even number in even array
{
if (arr[i]%2==0)
{even[j]=arr[i];j++;} // put odd numbe in odd array
else
{odd[k]=arr[i];k++;}
}


display (odd, O);
display (even, E);

cout"Press 1 for odd array"endl;
cout"Press 2 for even array"endl;
cout endl;
cout endl;
cout "REQUIRED Sorted array"endl;
int x;
cin>>x;
if (x==2)
{bubblesort (even, E);}
else if (x==1)
{bubblesort (odd , O);}
else
{cout"You enter a wroung number "endl;}
}


////////////////////////////
void display(int dis[10] , int xx)
{
for (int i =0; i<xx ; i++)
{coutdis[i]" ";}
coutendl;
}

//////////////////////////////////////////

CS201_2nd-Assignment-Final-Solution_

Attachments:

I've already written this assignment, check attached file. I have the issue at the end of the sorted array.
Remove // from the very last lines and check my error. And it would be great if you point out the error. Thanks

Attachments:

Final

#include <iostream>
#include <conio.h>

using namespace std;

void sort(int a[], int size);

main()
{

int inputNo[10];
int oddNoCount=0;
int evenNoCount=0;
int choice=0;

cout"10 Elements  array\n";
for(int i=0; i<10; i++)
{
cin>>inputNo[i];
if(inputNo[i]%2==0)
evenNoCount++;
else
oddNoCount++;
}

int oddNo[oddNoCount];
int evenNo[evenNoCount];
int oddIndex=0;
int evenIndex=0;

for(int i=0; i<10; i++)
{
if(inputNo[i]%2==0)
{
evenNo[evenIndex++]=inputNo[i];

}
else
{
oddNo[oddIndex++]=inputNo[i];
}

}

userChoice:
cout"\nFor Odd Numbers Press 1\n";
cout"For Even Numbers Press 2\n";

cin>>choice;
if(choice==1)
{
cout"Total Odd Number in Array is = "oddNoCount"\n\n";
cout"Sorted Odd Elements:-\n";
sort(oddNo,oddNoCount);
for(int i=0; i<oddNoCount; i++)
{
coutevenNo[i]" ";
}
}
else if(choice==2)
{
cout"Total Even Number in Array is = "evenNoCount"\n\n";
sort(evenNo,evenNoCount);
cout"Sorted Even Elements:-\n";
for(int i=0; i<evenNoCount; i++)
{
coutevenNo[i]" ";
}

}
else
{
cout"Invalid Choice\nPress any key\n";
getche();
goto userChoice;

}
getch();
return 0;
}

void sort(int input[], int size)
{
int temp;
for(int i=1;i<size;++i)
{
for(int j=0;j<(size-i);++j)
if(input[j]>input[j+1])
{
temp=input[j];
input[j]=input[j+1];
input[j+1]=temp;
}
}
}

nhi just .cpp file sbmt krwani hai

RSS

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

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