Cs201 Midterm Subjective by Adil Alvi

Download as pdf or txt
Download as pdf or txt
You are on page 1of 17

PREPARED BY ADIL ALVI

UNSOLVED CS201 MIDTERM SUBJECTIVE QUESTIONS 2010 TO 2019


1) Loops iterations.
2) Functions calling techniques.
3) Diagonal of matrix [N] [N].
4) Arithmetic solutions to check order.
5) Diagonal and quotient questions
Dec 17, 2019
1) Why program is evaluated? Two techniques of evaluation?
2) Write three type of system software
3) How system software control all the.....
4) 2 programs were given ... Weight in kg convert it in pound and one more
5) One question was from Array
6) Errors Puchay Thy Aur kuch ki Output Show Karna thi
7) Write the functionality of following function: strcpy & strncpy (3 marks)
8) Using not operator write the output: true? False? (3 marks)
9) Write a program of 4 digits which gives the first and last digit :( 5 marks)
10) Code given tha error find krny thy :( 5 marks)
11) Program likhna tha :( 5 marks)
12) Program for class
13) Write program to copy one array into another array and array of 5 elements
14) Find errors in the given code
15) Calloc and Malloc function
16) Write program for constructor
17) Difference between default and parameterized constructors.
18) Use three variable to expose the dec, hex, and Oct.
19) Write c++ programs with three variable salary, no. Of days and rate and salary account by
the formula Salary= no. days*rate. Take out of no of days with the daily rate of 1000 per day.
20) write c++ program with 2 variable (i) Calculate rows and columns (ii) Calculate transpose of
matrix
21) Function of default function
22) If you agree prototype of ordinary function and special function of a class are same. Justify
with comment.
23) define output for given code (loop).
24) Write salary program to calculate tax using switch statement.
25) Use pointer to reverse the order of array.
26) Show output for following code (strcpy, strcat) ke functions thay code main
27) Output of the following code for loop
28) Main () function ka procedure aya tha
29) System software ki types or work
30) Program 15 array change uppercase latter to lowercase latter and lowercase latter to
uppercase latter aya tha
31) 2 part thy wrong code ki identification krni the
Cin<< count:
If x<y
Int x;

For any query feel free to ask [email protected]


PREPARED BY ADIL ALVI
Else
Int y;
32) What happens if the file 'myfile.txt' does not exist and we still try to open it using the
function file.Open (“myfile.txt”, ios: out)?
33) Would the open () function create a new file and open it OR it will generate an error?
34) Determine the output of the given code segment.
Int x = 2;
Switch(x){
Case 1:
X += 1;
Break;
Case 2:
X += 2;
Case 3:
X +=3;
Break;
Case 4:
X += 4;
Break;
}
Cout x;
35) Transform the following If-else statement into switch statement.
If (x == 5)
Else if (x == 10 || x == 11)
Else if (x == 8)
Else if (x == 9)
Else
36) Write a C++ program which calculates the Net price of a book and displays it on the screen.
The Net price of book can be calculated by the following formula:
Net price = Retail Price + Sales Tax + Income Tax
Retail Price, Sale Tax and Income Tax are taken as input from the user.
37) write a program which opens a file named "writefile.txt" and moves the file pointer 100
characters forward starting from the beginning of the file and then writes the message "Reached
at position 101" at the new position in the file.
Dec 26, 2019
All statements like for loop, arrays, pointers, functions and file handling starting from lec no 17
onward, these are very imp topics for paper
Jun 23, 2019
1) Write the code of the following arrays; (i) Float array length 8 (ii) Float array length 8 to
pointer
2) Find the error in the following. Marks (3)
{
Int number;
If(number/2==0)
Cout"The number is even:";

For any query feel free to ask [email protected]


PREPARED BY ADIL ALVI
Else()
Cout"The number is odd:";
Getch();
3) Write a program in C++ to calculate the Average Price of the book. Calculations given
the. Inputs ly kr display krwana tha.
4) Give the output of the following
{
Int It=1 nt=o s;
Int number=8;
If(nt<number/2)
{
Coutit"\t";
S=nt+It
Nt=It
S=It
}
5) Write a code to find the product. Product= number *2^5. Input ly kr output show krwani the.
Jun 23, 2018

1) Comments ka long sawal tha


2) Programming Questions
3) Software ka function pa kia asar hota
4) Long Array Wala topic acha sy KR lena (Array main sy Program aye thy)
5) F stream function ka program write krna tha
6) Questions error find krny thy
7) Voding m sy flie stream wala question tha [Marks 5]
8) Lines hight light ki hui thin un ka batana tha k ye line ka is coding m kia kaam hy
9) Array ka aik question tha add () name sy aik function bnana tha jis m 2 integer leny thy or un
ka sum lena tha or result show krwana tha [Marks= 3]
10) General syntax of switch statement
11) Applications software’s with examples
12) Output of program having arrays
13) To write a program arrays of 10 elements. Sorting. Find minimum and maximum number
Jun 23, 2018

1) Write down the output of the code given below :


Hint:
Size of char is 1 byte
Size of int is 2 byte
Size of float is 4 byte
#include <iostream.h>
union mytypes_t {
char c;
int i;
float f;
} mytypes;

For any query feel free to ask [email protected]


PREPARED BY ADIL ALVI
int main(){
mytypes.c = 'H';
mytypes.i = 15;
cout sizeof(mytypes)endl;
mytypes.i = 15;
mytypes.c = 'H';
cout sizeof(mytypes)endl;
system("PAUSE");
return 0;
}
2) Identify the errors in the following code segment and give the reason of errors.
Main(){
int x = 10
const int *ptr = &x ;
*ptr = 5 ;
}
3) 1 programme likhna tha convert weight wala
Dec 10, 2017
Q No. 19: (2 Marks) write the output of the following program:
Int x = 5;
Int y = 10;
X = x + 10 * 5 + 5;
Y = x / 10 + 6;
Cout x endl;
Cout y endl;
Q No. 20: (3 Marks) write the output of the following program:
Int num[3][2] = { 51, 53, 47, 64, 39, 48 };
For ( j = 0; j < 3; j++ ) {
Cout *(*( num + j ) + 1 ) endl;
}
Q No. 21: (5 Marks) Write a Function Definition which takes 3 Arguments (saletax, income tax,
books price) and calculates the net price. (Net Price = sale tax + income tax + books price).
Q No. 22: (5 Marks) Write a Program that swaps two integers without using the temporary third
variable. (Hint: Bitwise Operator can be used).
Q No. 23: (5 Marks) Write a Program that calculates and print the product of all odd integers
from 1 to 10.
Jun 8, 2017

1) Write a program using do while loop (5 marks)


2) Explain & | operators (3 marks)
3) Explain the highlighted lines in a program (5 marks)
4) Write a c++ program (5marks)
5) Write the output of a program (3 marks)
6) Write a program and display 15% tax of an item. First take an input from user and then show
his 15% tax as output.

For any query feel free to ask [email protected]


PREPARED BY ADIL ALVI
7) Write a program in which ask user to input radius and then using switch statement write 2
cases. (i) Enter A or a to find area of circle. (ii) Enter C or c to find Circumference of circle
Formula were given
8) Write a program to make a 2D array which has 4 rows and 2 columns and display it. I used
rand () and then displayed 1st row elements in it for example there is an array:
 23 43. 5. 84.54. 42. 1. 75
 The Display/output should be like this :
 23 43 5 84

Q19: marks 3
Int num[3][2]={12,51,34,54,14,55};
For(int j =0; j<3; j++)
Cout(*(*num+j)+1)endl;
Q20: marks 3
A=3;
B=a++;
Cout"a="a;
Cout"b="b;
Q21: (marks 5) Write a code to read a string not greater than 20 character from keyboard, store it
in on array and display it on screen.
Q22: (marks 5) calculate the area of circle. You have to declare two variables for this, one is area
and other is radius. Take the value of radius from user. Hint: Area of circle= 3.14 *radius *
radius
Q23: (marks 5) Write a program that prompts the user to enter a string & reverse the string using
pointer & display the string in reverse order on the output screen. Program must include the
complete line include spaces.
Jun 11, 2017

1) Float array[8] declare krni the and then pointer pas krna tha.
2) Utilty software kounsy hoty hn example.
3) Net salary caluculate krni the c++ program likh kr dailywages= 1000 aur no of days. Khud
write krny thy salary= dailywages*no of days.
4) String declare krni the "this is my country"
5) Program. M, n values batani the after execution of program.
Jun 11, 2017
1) Write 2d array with five rows and six column and also write pointer to above array.?
2) Why we comment liberally in programs does they affect on performance...?
3) A do while loop executive how many times at least and a while loop?
4) Then 2 program likhi thy inline output likhi thy
5) One question was from Array
6) Write down the general syntax of switch statement.
7) Write a code segment that displays the diagonal element of a matrix of nxn.
8) Where N can be any number and represents dimension of matrix
9) Mention any two affects in a program who can occur as a result of an overflow condition.

For any query feel free to ask [email protected]


PREPARED BY ADIL ALVI
10) Write a program sum of 10 positive integers
11) Two different syntax of character strings
12) Which is best for storing a string Array or pointer explain
Dec 18, 2016

1) Write a code to read lower and upper case.


2) Int name [2] [2] is 2x2 write the code
3) two dimensional array of matrix
May 28, 2016
1) Write the syntax for calling function string manipulation function which compare the first 5
character array "name" with string "asdf"?
2) When a pointer is incremented then how many bytes will it move to change its address?
3) Declare an integer array long routes and pointer routrptr and assign the address of array long
routes to the pointer variable routeptr to the pointer?
4) Find which is legal and illegal?
5) Show the output of the following code:
Main()
{char st[]="~This is -a sample string!";
Char*pch;
Pch=strtoklstr,",-s`";
While(pch!=Null)
Coutpch;
Pch=strtok(NULL,",-s~")
}
Return 0;
}
6) When a pointer is incremented, what happens in the following cases?
(i) single-dimensional array. (ii) Two –dimensional array 3
May 31, 2016

1) Write down the output of the following code segment (2 marks)


Int x [10]={0,1,2,3,4,5,6,7,8,9};
Int*xptr;
Xptr=&x[5];
Cout*(ptr ++)+ 1;
2) In ac language program, how does closing a file explicitly by using close() function provide
advantages in terms of memory utilization? (2 marks)
3) When a pointer is incremented what happens in the following case? (3 marks)
(i) Single-Dimensional array. (ii) Two-dimensional array
4) Which one of the given two methods a file and why? (3 marks)
5) What will be output of the following segment? (5 marks)
Int x=6;
Int y;
X=x1;
Y=x>>1;
May 31, 2016

For any query feel free to ask [email protected]


PREPARED BY ADIL ALVI
Q.21.A two-dimensional array has 3 rows and 4 columns. Write down the syntax to initialize
first element of all three rows of two-dimensional array with value 2.
Q.22: Write the code for calling get line () member function of cin for reading 30 characters from
the keyboard and storing it in the array 'Arr' of characters.
Q.23: Write the code for the declaration of a function named getmax which takes a 2D array of
integers (3x3 dimension) as its parameter and returns a double pointer to an integer.
Q.25 Write the code for a structure called Inventory having the following elements:
 A character array named part name
 An integer named part number
 An integer named stock.
Jun 21, 2015

1) Write down the output of following code segment.


Int num[10] = {2, 3, 5, 8, 9, 10, 12, 15, 19, 20};
int *ptr = num ;
for (int i=0; i<10; i+=2){
cout *(ptr+i) “, ”;
} (05
2) What will be the output of given program code?
Main()
{
char province[] = "Sindh";
char s[80];
strcpy(s, "Hyderabad");
strcat(s, " and ");
3) What will be the correct syntax for initialization of pointer ptr of type int with variable x?
Int ptr = &x ;
int ptr = x ;
int *ptr = &x ;
int ptr* = &x ;
4) Write down the output of the following code segment?
Int x[10] = {0,1, 2, 3, 4, 5, 6, 7, 8, 9};
int *xptr;
xptr = &x[5];
cout *(xptr++) + 1;
Dec 21, 2015
1) Explane the meaning of given c++ statement. (cons int *ptr=&x ;)
2) Identify any logical of syntax error in statement below and explain the reason of the error
seekg(-10L,ios::beg);
3) Explain the logic of given program code and also determine its output
#include <iostream.h>
#include <string.h>
main()
{
Char name[10]=”Khagan”;

For any query feel free to ask [email protected]


PREPARED BY ADIL ALVI
Char msg[20]=”Welcome!”;
Cout ‹‹ strcat(msg,name,3);
Return 0;
}
4) Consider the following program write the output:
main()
{
char string1 []=”introduction”;
char string[]=”programming”;
cout ‹‹ “string 1 is”‹‹ string1‹‹endl;
cout ‹‹ “size of string 1 is”‹‹sizeof(string1)‹‹”bytes”‹‹endl;
cout ‹‹ “string 2 is”‹‹ string2‹‹endl;
cout ‹‹ “size of string 2 is”‹‹sizeof(string2)‹‹”bytes”‹‹endl;
}
6) Write the output of the following program
int x=6;
int y;
x=x‹‹1;
y=y>>1;
cout ‹‹ “x=”‹‹x ‹‹ “/n”;
cout‹‹”y=”‹‹y;
7) The statement int Name[2][2] defines a 2x2 array write the code which read data from
keyboard for each element of array
Dec 21, 2015

Q1: can we create an array of object for a class having default constructor?
Q2: overloaded member function using ostream and istream show any example?
Q3: write c++ code to overload subscript [] operator for string class?
Q4: what does you meant by static data member in c++:
Q5: explain the terms predecrenent and post decrement?
Jan 13, 2015

Q1. Data Reading From Files, Write Code to read data from myfile.txt, and write 1 line on 100
location of file by using fstream functions (Lecture 18) (5 Marks)
Q2. Swapping & Call by Reference, Pointers, Given Code to Write Output (5 Marks)
Q3. Functions and structures, how to handle members with two different technique (Lecture 18)
(3 Marks)
Q4. String concatenation, Given Code to Write Output (Lecture 17) (Marks 2)
Q5. Size of () & Array, Given Char Array to Find out Output by using Size of (Lecture 20)
(Marks 2)
Jun 11, 2014

1) Write a program with counts which tells at the end how many numbers are in the string
"90some7text". The output should be like. The total nos are: 3
2) Write a program declare a string of 10 characters and then show the value of the 4th and 8th
element using pointers?

For any query feel free to ask [email protected]


PREPARED BY ADIL ALVI
3) What will be the Output of
int x=10;
int y=30;
int *xptr;
xptr=&x;
cout "x = " *xptr+x; (Output signs are present but can’t write here)
4) Rest 2 questions were from Files Topic. Files Topic is very Important 6 mcqs be wahan sai ai
thai ..
Dec 21, 2013

Q 1: Identify each of the given functions as string conversion function or string manipulation
function.
(i) double at of (const char* nptr)
(ii) char* strcpy (char*s1 const char*)
(iii) int at of (const char*nptr)
Q 2 : If p and q are pointers and n is integer then the following are legal or illegal.
A p + q. B p - q. C p + n. D p – n. E n + q
Q 3: If (char array [7], is a character array then write a char at fifth location of this array.
Q 4: Which function is used in read & write while handling file.
Dec 22, 2013

1) Functions of strcpy and strncpy? 3marks


2) Output file? 5 marks
3) Detect and correct the coding (coding was about for loop) 5marks
4) Had to make a statement for input file trans.txt I dun remember the exact question. 3marks
5) 3 marks question about pointer
Dec 22, 2013

1. Write a structure named inventory which has char array, int name and int Num 3 Marks.
2. Syntax to close a file which has handle my file. 2 Marks
3. Code consisting of calling an array by a function and how function call change array contents.
5 Marks.
4. Const pointer related question. 2 Marks
Jun 4, 2013

1) How the two dimensional array is related to the matrix .2 MARKS


2) Assuming that “num” is a 2D array of character than what does statement *num contains?
2MARKS
3) Write a program in which you prompt the user to take 10 values in array and then display
them, sort the array and then find the maximum and minimum number in them. 3 MARKS
4) Write the output of the following: 5 MARKS
#include <iostream. H>
Union mytypes_t
{
Char c;
Int i;

For any query feel free to ask [email protected]


PREPARED BY ADIL ALVI
Float f;
}
Mytypes;
Int main();
{
Mytypes.c=’H’;
Mytypes.i=’15’;
Coutsize of (mytypes)endl;
Mytypes.i=’15’;
Mytypes.c=’H’;
Coutsize of (mytypes)endl;
Return0
}
5) Explain the logic of each statement: 5 MARKS
Streampos orig=afile,tellp();
Afile.seekp(0.ios::end);
Jun 1, 2013

Q1: Write down the general syntax of switch statement. 2 Marks


Q2: Why we close a file after use? 2 Marks
Q3: When a pointer is incremented then how many bytes will it move to change its address?
2 Marks
Q4: If there are 2n element in an array then what would be the number of iterations required
to search a number using binary and linear search? 3 Marks
Q5: write down the functions definition if we want to pass the argument to a function by
reference without changing the values stored at address. 5 Marks
Q6: What will be the output of the following code segment 5 Marks?
int x= 6;
int y;
x = x y =” x”>> 1;
cout “x = ” y =” ””>

1. What is the difference between pre-increment and post-increment operator


2. One major use of pointer
3. If an array has elements 2^n, then what would be the maximum number of iterations required
to search by binary and linear search? (I don’t remember the exact statement of the question)
(Answer is on page # 118)
4. Write the procedure of data insertion in middle of the files by Merge Method practiced
in older systems? (Answer is given in page # 218, in handouts)
5. Functions used to read/write more than a single character or a single line while using Files?
(Read chapter # 19, on page 221 I think this concept has been discussed)
6. In the long question, a program was given and we were required to point out the compilation
errors and correct them.
May 30, 2013

1) Technology with An Interesting name ka puch tha.

For any query feel free to ask [email protected]


PREPARED BY ADIL ALVI
2) If an array has 100 elements, what is allowable range of subscripts?
(a) 0 - 99 (b) 1 - 99 (c) 0 - 100 (d) 1 – 100. 2 number ka Quiz tha
3) Write a code to open a file, file name is "myfile.txt"
Dec 11, 2012

1) In programming we use structure and Arrays for what purpose? Marks=3


2) Which is better approach in term of memory space occupation and why? Marks=3
i) Char *arr[]={“programming”,”fundamental”,”cs201”};
ii) Char arr[3][50]= {“programming”,”fundamental”,”cs201”};
3) Determine the value of m and n after execution the code
Int m=44;
Int*p=&m;
Int &r=m;
Int n=(*P)++;
Int *q=p-1;
++*q;
Assume that integers occupy 4 bytes and that m is stored in memory.
4) Briefly explain the logic of given code. Also determine the value of ‘counter’ variable if the
code below is executed.
Main ()
{
Int num=5;
Int counter=0;
While (num !=0)
{
If (num &01)
Counter++;
Num >>=1;
}
Return 0;
}
Dec 14, 2012

1) What is bit sign number?


2) What is sequential and random access and which is best?
3) For loop ka aik question tha us main error batana tha?
4) Output batani thi program ki?
Dec 16, 2012

For getting good marks is cs201 prepare multidimensional array ,array and pointer and string and
file handling or structure union and bit wise manipulation k topic achy se ready karlo
May 16, 2012

1) Identify each of these functions as character conversion functions or manipulation functions.


(i) Int isprint( int c ). (ii) int tolower( int c )

For any query feel free to ask [email protected]


PREPARED BY ADIL ALVI
2) How can we declare a character array, is it different from integer array declaration? Give one
example of character array declaration.
3) Write the output of following program.
#include<iostream.h>
Int main()
{
int a[5] = {5, 1, 15, 20, 25};
int i, j, k, l, m;
I = ++a[1];
j = a[1]++;
k = a[i++];
l = a[i--]*i;
m = a[++i] - 1;
Couti" "j" "k " "l" "m;
}
4) Write the code for a structure called Inventory having the following elements:
• A character array named part name
• An integer named part number
• An integer named stock.
5) Write the code of a main() function which takes command-line arguments and returns an
integer type value.
6) Write a program which defines two strings "Hello" and "Pakistan", merges both the strings
using string manipulation function and displays on the screen.
1) Which bit of number is used as a sign bit?
2) Open () & close () function advantage of memory utilization...
3) int array[7] is an int array type.what will b the statement for the fourth element of this array?
4) Write the output of the given code. 5 marks
Subject Questions...
Q1. Write a program which will input ten integers into an array then sort it and find maximum
and minimum integer in array.
Hint: Finding maximum and minimum is quite easier in sorted array. (10 Marks)
Q2. Open () & close () function memory utilization advantages. (3 marks)
Q3. Write down a syntax in which we can find the size of structure in bytes. (3 Marks)
Q4. Difference between and (& in pointers. (Mark 5)
Q5. Int num is an array then assign its address to point myptr. (Mark 5)
May 16, 2012
Q: tell the size of () value of a structure variable.
Q: use of the keyword “const”
Q: which of these functions are string manipulation and conversion function?
Q: a program which input a telephone number with city code and recognize if it is from lhr or
not.
Q: A program is given and we have to tell the output. Program consists array and loop.
Q: how many memory locations will a pointer jump if it is incremented?
1) Write the code for a structure called Inventory having the following elements:
(i) A character array named part name

For any query feel free to ask [email protected]


PREPARED BY ADIL ALVI
(ii) An integer named part number
(iii) An integer named stock.
2) Declare a 2D array of integers having two rows and three columns.
3) We know that random method for accessing the files increases the performance but there are
certain constraints on it. Mention those constraints
4) Write the code to access the element at third row and second column of a 2D array uses
pointer named arrayptr.
Paper 4:
1) Long questions were on, to write down the output of the given program. (In these loop
structures were given)
2) Question on output of array elements. (Very basic one) marks ranging from 2 to 3.
3) Write down a program on the function involving the swap of integer values without using any
other variable (last one of 6 marks)
Paper 5:
Q1. Write a program which will input ten integers into an array then sort it and find maximum
and minimum integer in array. Hint: Finding maximum and minimum is quite easier in sorted
array.
Q2. Open () & close () function memory utilization advantages. (3 marks)
Q3. Write down a syntax in which we can find the size of structure in bytes. (3 Marks)
Q4. Difference between (*) and (&) in pointers. (Mark 5)
Q5. Int num is an array then assign its address to point myptr. (Mark 5)
Note: pointers mein se zyada questions aaye hain.

1) Write a declaration statement for an array of 10 elements of type float. Also initialize first four
elements of array to 1.0, 2.0, 3.0 and 4.0.(2)
2) Which bitwise operator returns true if both bits are different and returns false if both bits are
same?(2)
3) Suppose if we want to store values like 10, 45.3, 4, A, D, 6.4, and 50 by using array. Can we
store all these vu solutions dot com elements by declaring a single array? Yes or no? Give reason
to support your answer(3)
4) Write the code for a structure called Inventory having the following elements:
(i) A character array named part name
(ii) An integer named part number
(iii) An integer named stock. (3)
5) Write a program which opens a file named “this.txt” and then using write() function, writes
the string “Introduction to Programming” at the end of the file.(5)
6) Write a program which declares and initializes an integer array of 10 elements and then using
a pointer, displays the array elements in reverse order.
May 13, 2012
1) *num and num& difference.
2) Which one will you prefer: random or sequential access .Reason?
3) A code snippet was there of strings to calculate bytes
4) Cin function to compare two strings

For any query feel free to ask [email protected]


PREPARED BY ADIL ALVI
5) Write a program which gets input string from user and matches it with another “This is my
Pakistan”. For example if user enter “my” then the output will be “string found” or in case it
does not matches “Not Found”.
6) Write a program which get input from user as an integer array and uses pointer to print it in
reverse order.
7) One question from matrix programming
8) multidomintiona arrays
9) file handling
10) pointers
11) output of program etc.
Dec 7, 2011

Q1- Write down the output of the following code?


Int array[7], sum = 0;
for(int i=0;i<7;i++)
{
array = i;
sum+= array;
}
cout “ Sum = “ sum;
Q2- Explain C-String with an example?
Q3- anonymous structure and anonymous union k baray likhain?
Q4- 2 question practical related thay jis may code dya gya tha us ko theek kerna tha geek ki
option say.[/b]

1) Write a short note on files and also explain how they are handled in C++?
2) Is comparison possible in pointers? If yes what operators are used, if no justify your answers?
3) Briefly explain structure padding?
4) What is the difference between single and multi-dimensional arrays?
5) Explain the meaning of given C++ statement: const int *ptr = &x;
6) Write about char str?
May 14, 2011

Q: - Give one major use of Pointer? (2 marks


Q: - What does the file mode parameter ios::binary mean? (2 Marks)
Q: - What are the basic steps of file handling? (3 Marks)
Q: - Differentiate between array & list? (3 Marks)
Q: - Differentiate between random access & sequential access file? (5Marks)
May 17, 2011

1-difference in pointer and variable?


2-differenc in tellg() and tellp()
3-why we close a file after use?
4-Call by value and call by reference?
5-Give one use of pointer

For any query feel free to ask [email protected]


PREPARED BY ADIL ALVI
6-Bubble sort
7-What happened when we increment pointer
8-Basic steps for file handling
9-Which function is used in read/write while handling files?
Dec 5, 2010

Some questions from past papers

1) If there are 2n elements in an array then what would be the number of iterations required to
search a number using binary search and linear search?
2) Which header file must be included while handling files?
3) What is meant by C++ statement: const int *ptr = &x;
(i) An array day is declared as: int day[] = {1, 2, 3, 4, 5, 6, 7}; How many elements does array
'day' has?
(ii) If the declaration is changed as: int day[7] = {1, 2, 3, 4, 5, 6, 7}; How many elements does
array 'day' has?
4) Write a void function( ); that takes integer numbers from the user and then displays the sum of
odd and even numbers entered by the user. Your program should terminate if user enters a
negative number
5) Write down the function definition if we want to pass the arguments to a function by reference
without changing the values stored at that addresses.
6) What is meant by scope of identifiers? Differentiate between different scope of identifiers and
explain them with examples?
7) Can you use an assignment operator to assign the value of one C-string to another?
8) Which bitwise operator returns true if both bits are different and returns false if both bits are
same?
9) What will be the value of x after the execution of the following code segment?
Int x =10;
int y =30;
int *xptr = &x;
x = *xptr + 10;
10) Write a program which reads a text file “playersinfo.txt” residing in the current directory.
Open the file playersinfo.txt in read mode and assign these values to the struct Player; assume
order of the data in the file to be exactly the same as the order of struct attributes. The struct
Player has following attributes
i) Name
ii) Height
iii) Age
iv) Score
v) Game
After reading the file and assigning values to the struct, in the end close the file playersinfo.txt
11) Write a recursive function that takes character array and starting subscript as arguments. In
each recursive call, the function should display the string from subscript to the end of string. The
starting subscript in first call should be 0. In each successive call, the subscript should increase
by one and function should print the array from subscript to the end of string. The function
should stop processing and return when null character encounters. Suppose the char string passed

For any query feel free to ask [email protected]


PREPARED BY ADIL ALVI
to the function is, "samplestring", then the function will print output as follows,
samplestring
amplestring
mplestring
plestring
so on....
12) Customer with structure variable cust1 What line of code should he write
13) Write a void function( ); that takes integer numbers from the user and then displays the sum
of odd and even numbers entered by the user. Your program should terminate if user enters a
negative number
14) Suppose ‘z’ is a variable of type int. What will be the result of x = 27/4:
15) Give the general syntax of definition of structure.
16) Consider the structure
struct Customer
{
int custnum;
int salary;
float commission;
};
17) A programmer wants to assign 2000 for the structure member salary in the above example
ofstructure Customer with structure variable cust1 What line of code should he write
18) Write a C++ program that will determine if a departmental store customer has exceeded the
credit limit on a charge account.
Program should input the following facts in five variables
1. Account number
2. Balance at the beginning of month (Beginning balance)
3. Total of all items charged by customer this month (charges)
4. Total of all credits (credits)
5. Allowed credit limit
Calculate the new balance
New balance = Beginning balance + charges – credits
Determine if new balance exceeds the allowed credit limit. For those customers whose credit
limit is exceeded. The program should display the message “Credit Limit exceeded.”
19) What happens when we increment a pointer? (3 marks)
20) Can you use an assignment operator to assign the value of one C-string to another?(3 marks)
21) Write down the functions definition if we want to pass the argument to a function by
reference without changing the values stored at address.
22) write a programme which open the file named “this.txt”and using write ( ) function writes
the string “introduction to programming” at the end of the file.At the end close the programme
properly . 5
23) write down the output of the following code segment .
Intnum[10]=[2,3,5,8,9,10,12,15,19,20]
Int*ptr=num;
For int i=o; i<10, i+=2
{
Cout(ptr+i)<,”;

For any query feel free to ask [email protected]


PREPARED BY ADIL ALVI
}5
24) when a pointer is incremented,what happens in the following cases?
A)single-dimensional array b)two –dimensional array 3
25) write down syntax in two different ways to intilize charcter array with strings”programming”
26) what happen if the file “myfile.*does not exists and we still try to open it using the function
file open (“myfile.txt”ios:out)?

For any query feel free to ask [email protected]

You might also like