loading...

CS201 Introduction to Programming Assignment 2 Solution Spring 2013

Problem Statement:     

 

Write a C++ program that prints your VUID by using character array, then prints your VUID in reverse order by using character array and finally stores and displays the digits of your VUID at the diagonal of 9 x 9 Matrix by using two dimensional integer array.

You are required to perform these tasks with the help of following three functions:

  • DisplayVUID()
  • DisplayReverse(char [])
  • StoreDiagonal()

 

Detailed Description:

 

Description of above functions are as follows:

 

DisplayVUID()

This function stores your VUID in character array (for example bc020455055) and simply prints it.

 

DisplayReverse(char [])

This function takes the character array as parameter having your VUID and displays it in reverse order.

 

StoreDiagonal()

This function stores the digits of your VUID at the diagonal of 9 x 9 matrix, for example VUID i.e. bc020455055   contains the digits 020455055, so you have to store these digits in the diagonal of the 9 x 9 matrix as follows:


Solution:


#include <iostream>
#include <cstdlib>
using namespace std;

void DisplayVUID();
void DisplayReverse(char[],int);
void StoreDiagonal();

int main(){
DisplayVUID();
char VUID[12] = {‘B’,’C’,’1′,’2′,’0′,’4′,’0′,’3′,’4′,’5′,’6′};
DisplayReverse(VUID,11);
StoreDiagonal();

system(“pause”);
cout << “nnn”;
cout << “*****************************************” << endl;
cout << “* Name: sdfd Marchal tt*” << endl;
cout << “* Date: Saturday, May 11, 2013 tt*” << endl;
cout << “* facebook.com/vupaktutorial tt*” << endl;
cout << “* Virtual University Paktutorialt*” << endl;
cout << “*****************************************” << endl;
return 0;
}

void DisplayVUID(){
char VUID[12] = “BC12xxx”;
cout << “My VUID is: “;
for(int i=0; i<12; i++){
cout << VUID[i];
}
}
void DisplayReverse(char* VUID, int arraysize){
cout << “nMy VUID in reverse order: “;
for(int i = arraysize – 1; i>=0; i–){
cout << VUID[i];
}
cout << endl;
}
void StoreDiagonal(){
cout << “Digits of my VUID are stored in the diagonal of the digionalMat”
<< endl;
int digionalMat[9][9];
for(int row = 0; row < 9; row++){
for(int col = 0; col < 9; col++){
digionalMat[row][col] = 0;
}
}
digionalMat[0][0]= 1;
digionalMat[1][1]= 2;
digionalMat[2][2]= 0;
digionalMat[3][3]= 4;
digionalMat[4][4]= 0;
digionalMat[5][5]= 3;
digionalMat[6][6]= 4;
digionalMat[7][7]= 5;
digionalMat[8][8]= 6;
for(int row = 0; row < 9; row++){
for(int col = 0; col < 9; col++){
cout << digionalMat[row][col];
cout << ” “;
}
cout << endl;
}
}

 


DOWNLOAD SOLUTION HERE
loading...
  • fahad

    solution upload krain iska