www.vustudents.ning.com

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

# CS201 Introduction to Programming Assignment No. 02 Solution and Discussion Spring 2013 Due Date 15-05-2013

Views: 1533

### Replies to This Discussion

Our main purpose here discussion not just Solution

We are here with you hands in hands to facilitate your learning and do not appreciate the idea of copying or replicating solutions.

Attachments:

tariq bhai hum cin ly kr value ni ly skty kya??

The following program declares two arrays.

#include <iostream>
#include <string>

using namespace std;

int main(int argc, char *argv[])
{
// Array of five ints
int numbers[5];

// Array of four strings
string texts[4];
}

#include <string>

using namespace std;

int main(int argc, char *argv[])
{
// Array of five hundred ints
int *numbers = new int[500];

// Array of four hundred strings
string *texts = new string[400];

// Free the memory
delete [] numbers;
delete [] texts;
}

#include <string>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
int numbers[] = {1, 2, 5, 10};

string texts[] = {"Apple", "Banana", "Orange"};

// Access element at index 0
cout numbers[0] endl;

// Access element at index 2
cout texts[2] endl;
}

pleas provide your best idea  to solve this assigment before due date....

Solution hints for the assignment no 2.

sab se pehle main se bhe pehle header files ko include karne ke baad aap function prototypes dein ge like

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

void displayVUID(char array[]);

void displayReverse(char array1[]);

void storediagonal(char array2);

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

uss ke bad faraz karin keh aapka main program yah hai

main(){

// yahan par aik char array declare karein aour uss mein apni id save kar lein like

char ID[] = "MC1302xxxxxxxx";

// uss ke baad aap functions ko call kar lein bari bari  like

displayVUID(ID);

displayReverse(ID);

storediagonal(ID);

}

///////////////////// main ke curly brace band hone ke baad aap ne sab functions ki body define karni hai like

void displayVUID(char array[])

{

// iss mein aap ne do kam karne hain, aik easy, dosra professional jo aap ka je chahy aap kar sakte hain

// easy kam

//  aap ko apni apni id ke characher ki tadad maloom hai, yani 11 characters

// aap aik loop ki madad se unko print karwa lein  like

for (int a=0;a<11;a++)

cout array[a];

cout endl;

// hint for professional method, pehle aap string ki length maloom karein then aap loop ko 11 ki bajaey strength length tak chalaein

// display ka kam khatam

}

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

void displayReverse(char array1[])

{

///// iss mein ussi loop ko 11-1 se 0 tak chala lein ulta like

for (int b = 10; b>=0; b--)

cout array1[b];

cout endl;

}

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

void storediagonal(char array2)

{

yeh wala portion zara tricky hai, main solve nahi karounga sirf hint dounga, tahkeh aap log thora sochein,

hints, 9 by 9 ki aik arrary declare karein

aour jahan row aour column ki value same ho jaey wahan aap id ka character store karwa dein

}

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

I hope it will help

//Another way to reverse Array Char...Not solution..only guideline

#include
#include
using namespace std;

// function prototype
void Reverse(char name[]);

int main()
{
// declare variable
char name[30];

// get user data
cin.getline(name,30);

// function declaration
Reverse(name);
coutendl;

coutendl;
system("PAUSE");
return EXIT_SUCCESS;
}// end of main

void Reverse(char name[])
{
if(*name=='\0') //the base case
{
return;
}
else // the recursive step
{
Reverse(name+1);
cout*(name);
}
}

//Idea for printing an array chars in Reverse.....Its not Solution...a guideline...

#include
#include
using namespace std;

char* strrev( char* s )
{
char c;
char* s0 = s - 1;
char* s1 = s;

/* Find the end of the string */
while (*s1) ++s1;

/* Reverse it */
while (s1-- > ++s0)
{
c = *s0;
*s0 = *s1;
*s1 = c;
}

return s;
}

int main()
{
char message[] = "Hello world!";

cout "message = " message endl;
cout "egassem = " strrev( message ) endl;

coutendl;
system("PAUSE");
return EXIT_SUCCESS;
}

Nice going

Only idea not a full solution............

#include <iostream>
#include <stdlib.h>
using namespace std;
void DisplayVUID();

void DisplayReverse(char[],int);
int main(){
DisplayVUID();
char VuidReverse[12] = {'M','C','1','2','0','4','0','4','1','4','0'};
DisplayReverse(VuidReverse,11);

}
// Display Function
void DisplayVUID(){
char VUID[12] = "MC120404140";
cout "My VUID is: ";
for(int i=0; i<12; i++){
cout VUID[i];
}
}
// Reverse Function
void DisplayReverse(char* VuidReverse, int arraysize){
cout "\nMy VUID in reverse order: ";
for(int i = arraysize - 1; i>=0; i--){
cout VuidReverse[i];
}
}

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

// ****** Function Prototype *******
void displayVUID(char arg []);
void displayRevVUID(char ar []);
void matrixVUID(char str[]);

// ****** Main Function *******
void main () {

clrscr();
char myID[] = "MC120203645";

displayVUID(myID);
displayRevVUID(myID);
matrixVUID(myID);

} // end of main

// ****** Display VU ID ********
void displayVUID(char arg[]){

int len = strlen(arg);
cout"Display VU ID"endl;
cout"============="endl;
for (int i = 0 ; i<len ; i++ )
coutarg[i];
coutendlendl;
}

// ****** Display Reverse VU ID ********
void displayRevVUID(char arg[]){

int len = strlen(arg);
cout"Display Reverse VU ID"endl;
cout"====================="endl;
for (int i = len-1 ; i>=0 ; i-- )
coutarg[i];
coutendlendl;
}

//******** MATRIX *******
void matrixVUID(char str[]){

cout"Display Matrix VU ID"endl;
cout"===================="endl;
int len = strlen(str);
for (int i = 0 ; i<len ; i++){
for (int j = 0 ; j<len ; j++){
if (i == j)
coutstr[i]" ";
else
cout"0 ";
} // end of inner loop
coutendlendl;
} // end of outer loop
} // end of function

1

2

3

4

5

## Latest Activity

AbdulRabecca updated their profile
2 hours ago
Attas updated their profile
9 hours ago
Ahmed Salman, Abdul Wahab, mubashar and 4 more joined Virtual University of Pakistan
9 hours ago
Abdul Wahab joined + M.Tariq Malik's group

### MGT503 Principles of Management

10 hours ago
mubashar, AbdulRabecca and Wasim joined + M.Tariq Malik's group

### PAD603 Governance, Democracy and Society

10 hours ago
Abdul Wahab joined + M.Tariq Malik's group