You are on page 1of 3

Date: 20 - Jan - 2021

Final Examination Fall 2020


Reg. No:
Name:SafiurRehman________________________________ 2012184_______________
_______________
Department & Program: BS Computer Science Class & Section:
BSCS 1(B)
Course Code & Name: CSC 1103 Fundamentals of Programming Duration: 2 hrs
Instructor’s
Important Name:
Instructions: Ms. Farah Younas Total Marks: 30
Read all questions carefully first and then ask for the questions. Copied solutions will be marked zero.
-----------------------------------------------------------------------------------------------------------------------------------
Attempt all questions:

Q1: (05 Marks)


Arrays can be multidimensional. Explain with the help of code how to initialize a 2D array and how would you add
two 2-dimensional arrays.
Answer: A multidimensional array is an array with more than two dimensions. 2D Array is called two
dimensional arrays. Which is also called matrix. Multidimensional arrays are an extension of 2-D matrices
and use additional subscripts for indexing.
Syntax of Two-Dimensional Array:-
(Data type) (Name of array) [Number of rows] [Number of columns]
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int matrix [2][3];
for (int c1=0 ; c1<2 ; c1++)
{
for (int c2=0 ; c2<3 ; c2++)
{
cout<<"Enter Integer :";
cin>>matrix [c1][c2];
}
}
cout<<endl;

for (int c1=0 ; c1<2 ; c1++)


{
for (int c2=0 ; c2<3 ; c2++)
{
cout<<"The integer you entered is :";
cout<<matrix [c1][c2];
cout<<endl;
}
}
getch();
}

Page 1 of 3
Q2: (05 Marks)
Default argument is a type of function arguments. Elaborate its functionality and use with the help of an
example.
Answer: A default argument is a worth given in a capacity presentation that is consequently appointed by the
compiler if the guest of the capacity doesn't offer a benefit for the contention with a default esteem. ... We don't need
to compose 3 entirety capacities, just one capacity works by utilizing default values for third and fourth contentions.
For example: Calling of function sum (10, 15, 25, 30) overwrites the value of c and d to 25 and 30
respectively. During calling of function, arguments from calling function to called function are copied from
left to right

#include<iostream>
using namespace std;
  
// A function with default arguments, it can be called with 
// 2 arguments or 3 arguments or 4 arguments.
int sum(int x, int y, int z=0, int w=0)
{
    return (x + y + z + w);
}
  
/* Driver program to test above function*/
int main()
{
    cout << sum(10, 15) << endl;
    cout << sum(10, 15, 25) << endl;
    cout << sum(10, 15, 25, 30) << endl;
    return 0;
}

Q3: (05 Marks)


Find the output of the following program. Assuming all the desired header files are already included, which are
required to run the code, Elaborate your work.
Page 2 of 3
struct Dimensions
{
            int x_cord, y_cord;
};

void show(Dimensions);

int main()
{
            Dimensions X = {40,50}, Y, Z;
            Z = X;
            X.C += 10;
            Y = Z;
            Y.C += 10;
            Y.R += 20;
            Z.C -= 15;
            show(X);
            show(Y);
            show (Z);
            return 0;
}
void show(Dimensions D)
{
            cout << "X coordinate "<< D. x_cord << " Y coordinate " << D. y_cord << endl;
}

Q4: (15 Marks)

Suppose you own a Car Showroom and you have 10 different cars at the showroom. You need to maintain the record
of all the registered cars and display their data when required.
Create a structure Cars, containing registration number (int), name (char []), model number(int), date of
arrival(nested) as structure members. (03 Marks)

Write a program that accomplish the following tasks:

1. Main function should ask the user to enter username and password to proceed further. (02 Marks)
2. Main function should display a menu either to enter the record or display the record. Program should call the
function according to user’s choice. (02 Mark)
3. If user chooses to enter the record, program should store the data in a structure array of 10 members. Program
should ask the user if he wants to enter the next record. (02 Mark)
4. If user chooses to display the record and there is record present, program should display the list of record (in
ascending order of date of arrival, as mentioned in point 5), if there is no record present then it should display a
message of “no record found”. (03 Marks)
5. Record displayed by point number 4 should be sorted in descending order of date of arrival of cars by using a sort
function. (03 Marks)

***END***

Page 3 of 3

You might also like