Sir Syed University of Engineering & Technology: Qno:1 Answers
Sir Syed University of Engineering & Technology: Qno:1 Answers
ANSWER SCRIPT
Date: 16/11/2020
Roll Number: EL20-043
Section: B
Name: Ejaz-ullah
Course Name: CE122T Programming Fundamentals
Degree Program: Electrical Engineering
Total number of pages
2
being submitted:
Qno:1 ANSWERS
a) The “~” should not be added in the context it will return error and second the variable
is not declared as well correct form will be : void Date(int a)
b) An interger object cannot take string as inputs so we have to make it String
student(string, string)
c) Error: The class definition for Example has two errors.
1) Error:In function getIncrementedData. The function is declared const, but it
modifies the object t.
Correction: remove the const keyword from the definition ofgetIncrementedData.
2) Error: occurs in function getCount. This function is declared static, so it is not
allowed to access any non-static member of the class.
Correction: remove the output line from the getCount definition.
Qno 2: Answers
a) The function can be called inside a function but it has been coded inside othe function
Which will lead to error
b) Int yourname and int yourfathername has not been allocated with value first we will have
to allocate values (int yourname=1, int yourfathername=4)
c) The context in “if condition ” is writtend wrong it should be written as “ if(yourname=
=0)” instead of if ( 0 == yourname ), The second error is “{}” are missing after if
statement we will have to place them
d) A double name integer which is initialized is again initialized with float which will give
compilation error , A variable can be of a single type in C++ so whether we take it as
double or float
Page 1 of 2
Qno 3: Answers
a) Error: The file name payables.dat has not been opened before and the attempt is
made to output data to the stream which is an appropriate approch.
a. Correction:We shouldd Use ostream function open to open payables.dat for
output
b) Error: incorrect istream object is used to read a record from the file named
payables.dat.
a. Correction: Use istream object in Payable to refer to payables.dat
c) Error: The file’s contents are discarded because the file is opened for output (ios::out).
Correction: To add data to the file, open the file either for updating (ios::ate) or for
appending (ios::app)
Qno:4 Answers
a) X= block scope
Y= block scope.
Function square= global namespace scope
Main function= global namespace scope.
function prototype for square= function-prototype scope
Qno:5 Answers
a) Comaprision operators are used in cout statemet which will lead to error
a. Correction: whether compare values first and store in a new variable and than
call it in cout statement
b) The variable c is written in ‘’ which will not print the value of c
a. Correction: we will have to remove ‘’ and write : cout << c;
c) Extra ”” have been used which will cause error
a. Correction: removing additional “ colons will fix the problem : cout << "A
string in yourrollno";
Page 2 of 2