You are on page 1of 4

Name: __________________________ Reg.

No: __________________________ Section: I

Lahore Garrison University


Department of Computer Science

Course: Programming Fundamentals (CSC313) Exam: Assignment-02


Due Date: 1-May-2023 Semester: 1th
Maximum Marks: 175 Instructor: Ahsan Ayaz
Information for Candidates
1. In the case of cheating by any means, university rules will be followed.
2. The marks for parts of questions are shown in square brackets: e.g. [10] marks.
3. You should attempt ALL questions.

BEGIN ERROR PART


A. Find the errors in the following C++ programs and then explain each error with solid reasoning. [10+10+10]
B. Check in IDE (DEV C++) after correcting these errors. [5+5+5]
[Note]: Ignore the header files and main function.
int sum,sub,mult;div,module;
int a,b;
cout<<"Enter value of a ="
cin<<a;
cout<<"Enter value of b =;
cin<<b;
sum=a+b;
sub=a-bmult=a*b;
div=a/'b';
module=a%b;
if(Ascii_value_Variable>=97 & Ascii_value_Variable<=122)
{
cout<<"\nYou have entered a small letter";
}
elseif(Ascii_value_Variable>=65 && Ascii_value_Variable<=90)
{
{
cout<<"\nYou have entered a capital letter";
}
elseif (Ascii_value_Variable>=0 && Ascii_value_Variable>=47;
|| Ascii_value_Variable>=54 & Ascii_value_Variable<=64;
|| Ascii_value_Variable>=91 & Ascii_value_Variable<=96 ;
|| Ascii_value_Variable>=123 & Ascii_value_Variable<=127)
{
cout<<"\nYou have entered a special v_charac_varible";
}
}
elseif (Ascii_value_Variable>=47 & Ascii_value_Variable<=57)
cout<<"\nYou have entered a digit ";
}
}

Programming Fundamental (CSC313) 1|1


Name: __________________________ Reg. No: __________________________ Section: I
int day = 4;
cin>day;
if(day>1 & day<8)
{
Switch (day)
{
case 1:
cout << "Monday";
break;
case 2
cout << "Tuesday";
case 3:
cout <<< "Wednesday";
break;
case 4:
cout << "Thursday",
break;
case 5:
cout << "Friday";
break;
case 6:
cout << "Saturday’;
case 7:
cout << "Sunday";
break;
}
}
END ERROR PART

BEGIN OUTPUT
A. What will be the output of the following C++ code by using Dry Run and IDE (Dev C++)? [10+10+10+10+10]
B. Draw the exact flow chart of the following C++ code. [10+10+10+10+10]
[Note]: Only error-free code can run successfully.
#include <iostream>
using namespac std;
int main()
{
int divisor, dividend, quotient, remainder;
cout << "Enter dividend :: ";
cin >> dividend;
cout << "\nEnter divisor :: ";
cin >> divisor;
quotient = dividend / divisor;
remainder = dividend % divisor;
cout << "\nQuotient = " << quotient << endl;
cout << "\nRemainder = " << remainder<<endl;
return 0;
}

Programming Fundamental (CSC313) 1|2


Name: __________________________ Reg. No: __________________________ Section: I
#include<iostream>
using namespace std;
int main()
{
int y=f=i=0;
cout<<"Enter Inches to Convert ::";
cin>>i;
y=i/432;
i==i%432;
f=i/12;
i=i%12;
cout<<"\nAfter Conversion from inches to feet, yards and inches :: \n",
cout<<"\nYards = "<<y<<"\n\nFeet = "<<f<<"\n\nInches = "<<i<<"\n";
return 0;
}
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
float p,r,t,ci;
cout<<"Enter Principle (Amount) :: ";
cin>>p;
cout<<"\nEnter Rate of Interest :: ";
cin>>r;
cout<<"\nEnter Time Period :: ";
cin>>t;
ci = p*pow((1+r/100),t);
cout<<"\nThe Calculated Compound Interest is = "<<ci<<"\n";
return 0;
}
#include<iostream>
using namespace std;
int main()
{
int year;
cout<<"Enter any Year (XXXX) :: ";
cin>>year;
if(year%100==0)
{
if(year%400==0)
{
cout<<"\nThe Entered Year [ "<<year<<" ] is a Leap Year.\n";
}
}
else
{
if(year%4==0)
{

Programming Fundamental (CSC313) 1|3


Name: __________________________ Reg. No: __________________________ Section: I
cout<<"\nThe Entered Year [ "<<year<<" ] is a Leap Year.\n";
}
else
{
cout<<"\nThe Entered Year [ "<<year<<" ] is NOT a Leap Year.\n";
}
}
return 0;
}
#include <iostream>
using namespace std;
int mai() {
char oper;
float num1, num2:
cout << "Enter an operator (+, -, *, /): ";
cin >> oper;
cout << "Enter two numbers: " << endl;
cin >> num1 >> num2;
switch (oper) {
case '+';
cout << num1 <> " + " << num2 << " = " << num1 + num2;
break;
case '-':
cout << num1 << " - " << num2 << " = " << num1 - num2;
break;
case '*':
cout << num1 << " * " ;<< num2 << " = " << num1 * num2;
break;
case '/':
cout << num1 << " / " << num2 << = " << num1 / num2;
break;
default:
cout << "Error! The operator is not correct";
break;
}
return 0;
}
END OUTPUT

Short Questions: [30]

1. What is the size of the int, float, char, bool, void, double, short, and unsigned data types? [5]
2. How many types of operators are used in C++? Explain with the help of a diagram. [5]
3. What is the resolution operator and in what scenario is it used? [5]
4. What is the difference between C and C++? [5]
5. Difference between declaration and initialization of a variable. Explain with an example. [5]
1. What is the preference for having a global variable and a local variable with the same name in a program and how
do you access the global variable? [5]

Programming Fundamental (CSC313) 1|4

You might also like