0% found this document useful (0 votes)
87 views39 pages

FOP Practical

This document outlines the objectives, outcomes, and instructions for a fundamentals of programming course. The course aims to teach basic programming concepts and problem solving techniques using languages like C++ and Java. It is divided into 6 units covering topics such as conditional statements, loops, arrays, functions, classes and constructors. Students will complete 18 practical exercises mapped to the learning outcomes and assessed based on criteria like solution completeness, code quality, and documentation. The exercises are allocated sequentially to students based on their enrollment numbers.

Uploaded by

yunus
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
87 views39 pages

FOP Practical

This document outlines the objectives, outcomes, and instructions for a fundamentals of programming course. The course aims to teach basic programming concepts and problem solving techniques using languages like C++ and Java. It is divided into 6 units covering topics such as conditional statements, loops, arrays, functions, classes and constructors. Students will complete 18 practical exercises mapped to the learning outcomes and assessed based on criteria like solution completeness, code quality, and documentation. The exercises are allocated sequentially to students based on their enrollment numbers.

Uploaded by

yunus
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 39

Bhulabhai Vanmalibhai Patel Institute of Computer Science 2021-2022

CS3004: Fundamentals of Programming


1st Semester
Practical Exercise Workbook

Course Objective: To introduce the fundamentals of programming concepts, methodology and


enforce logical thinking to design and develop algorithm along with problem solving techniques.

Course Outcomes: Programme Outcomes:

Upon completion of the course, the student shall


PO1: Ability to understand the concepts of
be able to
key areas in computer science.
CO1: Present the knowledge about basic
PO2: Ability to design and develop system,
concepts of programming.
component or process as well as test and
CO2: Learn and use the program development
maintain it so as to provide promising
life cycle to solve problems.
solutions to industry and society.
CO3: Design and develop programs using
PO3: Effective communication and
conditional and loop control statements.
presentation skill.
CO4: Get knowledge about array and able to
PO4: Ability to understand professional and
apply operations to solve the problems.
ethical responsibility.
CO5: Design and develop programs using
PO5: Recognition of the need for life-long
methods for obtaining reusability.
learning.
CO6: Design and develop derived data type and
use in problem solving.

Programme Educational Objectives:


PEO1: To provide a basic foundation in the domain of computer applications.
PEO2: To develop analytical and problem-solving skills for life-long learning in computer science.
PEO3: To provide practical skill of tools and technologies to solve real-world problems.
PEO4: To impart knowledge and inspiration to prepare and pursue further academic studies.
PEO5: To induce the consciousness of ethics and moral values to serve the industry and society.
Student Instructions:

 Student must prepare handwritten workbook to solve definition. Each page must contain
the Enrollment number.
 Student may use Online GDB editor, Netbeans IDE or SRIMoodle Virtual Lab Programming
to demonstrate solution of the problem definition.
 Student should follow the Coding standard attached at end of document.
 At time of submission student must submit scan copy of the respective question.
 Student must submit the workbook exercise on given deadline.
 Nature of submission is hand written for all the problem definition.
 Practical work book must have index given.
 Programs should be well-documented and must follows the Coding standards.
 Workbook will be evaluated based on following given rubric parameters.
o Completeness of Solution
o Code Correctness
o Reusability
o Documentation
o Coding standard
o Demonstration
o Technical viva

MS. CHETANA TAILOR | DR. KALPESH LAD 1


Bhulabhai Vanmalibhai Patel Institute of Computer Science 2021-2022
 Practical workbook problem allocation to the students as per their enrolment numbers:

Even Enrollment Number Odd Enrollment Number

Programming
C++ Java C++ Java
Language
1 2 2 1
3 4 4 3
5 6 6 5
7 8 8 7
Practical Number 9 10 10 9
11 12 12 11
13 14 14 13
15 16 16 15
17 18 18 17

Practical mapping with Unit, Course Outcomes, Program Outcomes, Program Educational
Objectives and Skill set:

Practical Uni Total Course Program PEO Skill Set


No. t Hour Outco Outcomes mapping
No. s mes
1, 2 1 6 CO1, PO1 , PO2 PEO2 , PEO3 Thinking Skill: Analytical, Problem
CO2 Solving
Writing Skill: Understanding, Reading
Solitary Learning and Technical Skill
3, 4, 5 2 7 CO1, PO1 , PO2, PEO2 , PEO3 Thinking Skill: Analytical, Problem
CO2, PO5 Solving, Writing Skill: Understanding,
CO3 Reading
Solitary Learning and Technical Skill
6,7, 8,9 3 13 CO2, PO1 , PO2, PEO2 , PEO3 Thinking Skill: Analytical, Problem
CO3 PO5 Solving
Solitary Learning and Technical Skill
10, 11, 12 4 10 CO2, PO1 , PO2, PEO2 , PEO3 Thinking Skill: Analytical, Problem
CO4 PO5 Solving
Solitary Learning and Technical Skill
13, 14,15 5 9 CO2, PO1 , PO2, PEO2 , PEO3 Thinking Skill: Analytical, Problem
CO5 PO5 Solving
Solitary Learning and Technical Skill
16,17,18 6 7 CO2, PO1 , PO2, PEO2 , PEO3 Thinking Skill: Analytical, Problem
CO6 PO5 Solving
Solitary Learning and Technical Skill

MS. CHETANA TAILOR | DR. KALPESH LAD 2


Bhulabhai Vanmalibhai Patel Institute of Computer Science 2021-2022

INDEX

Practical Objective Practical Practical Page Subject


No. Performed Checking No. Teacher
Date Date Signature
1 To test basic understanding regarding identifier,
variable, constant, declaration and I/O
statements.

2 To get aquatinted with C++, and Java environment


including arithmetic and relational expression
representation in programming language.

3 To use the conditional statement such as if


statement and multiple if statements for solving
the problem.

4 To implement the conditional statement namely


if...else and nested if statements for solving the
problem.

5 To verify the understanding for the concepts


if…elseif and switch statements.

6 To apply the simple loop statement in developing


the programs using numeric data.

7 To process characters using Loop and Conditional


statements.

8 To introduce the event driven loop usage in data


validation.

9 To implement nested loop in developing


programs.

10 To work on numeric array with required


operations.

11 To process the string for performing basic task of


text processing.

12 To work with two dimensional array and perform


arithmetic operations on it.

13 To acquaint students with user defined function


with one argument.

14 To implement user defined function with the


multi-arguments for solving the problem.

15 To solve the problem by passing array in a user

MS. CHETANA TAILOR | DR. KALPESH LAD 3


Bhulabhai Vanmalibhai Patel Institute of Computer Science 2021-2022
defined function.

16 To implement the class according to the given


class design.

17 To create a method with business logic in class.

18 To make them aware regarding the concept of


Constructors in a class.

Total Marks

MS. CHETANA TAILOR | DR. KALPESH LAD 4


Bhulabhai Vanmalibhai Patel Institute of Computer Science 2021-2022

Practical: 01 Enrollment No. :


Problem 1. Verify each variable name whether they are valid or invalid. If it is invalid variable name, give
Definition reasons in form of variable naming convention rules violated.
1. 1TEST 9. No of students
2. price$ 10. while
3. Test_1 11. FILE_3
4. 564_56 12. Group1&Group2
5. int 13. Good_Luck
6. Float 14. _Temp
7. Raj-patel 15. AnsWER
8. No#1

2. Define the types of following Constants.


1. 99.09 9. “Best Wishes”
2. 9854 10. ‘\t’
3. +67 11. “9:30 AM”
4. -65.56 12. “#”
5. 9.6e2 13. 018ABC
6. 77. 14. “99.9”
7. 0939 15. “95 %”
8. ‘X’

3. Do as directed.
a. In a Sport shop, Akash has bought three items such as Bat, Stump, Badminton Rackets. For that
how many variables are required? List them with data types to solve the problem.
b. Suggest variable names and data type for below mentioned Student information for Uka
Tarsadia University Student Management System.
Student Name Date of Admission
Enrollment Number Semester Fee
HSC Percentage Student City
Passing Year Of HSC Student Gender

c. Write appropriate declarations statements for following group of variables.


1. Floating point variable: Total Bill Amount, Rate of Interest
2. Integer variable: Number of students, No of itmes purchase
3. Character variable: Gender
d. Write a declaration statement that declare a variable “product_price” of float with +5.25 value,
“No_of_days” of integer with 61 value, “Distance” of float with -50.05 value , “Person_Gender” of
character with ‘M’ value.
e. Write a constant declaration statement to initialize following constant with given value.
(Declare constant using keyword and pre-processor directive)
Name Value
PI 3.1415

MS. CHETANA TAILOR | DR. KALPESH LAD 5


Bhulabhai Vanmalibhai Patel Institute of Computer Science 2021-2022
Lower v
Lucky Number 234
Upper H
special_char #

4. State whether the following declaration statements are valid or invalid. If it is invalid, give an
appropriate reason and rewrite in correct way.
1. float a, b; 9. int p=5; q=6.4; r=40;
2. int x=50, b=x, c=b; 10. float x=y=z=70.37;
3. FLOAT T=99.3, y; 11. int A=80 q==9;
4. int X=Y=10=Z; 12. int p=54, int q=65;
5. float T= 99999; 13. int a= -88;
6. int a=5, c, b=a+b; 14. char temp1=’X’, char=’Y’;
7. Float Y; 15. char = temp1;
8. float A B C= A+B;

5. Write a statement to print following lines on output screen using single output statement
including punctuation marks:
1. Greetings of the day!!!
2. You’re a diamond, they can’t break you…
3. DON’T WORRY ABOUT FAILURES,
WORRY ABOUT THE CHANCE YOU MISS,
WHEN YOU DON’T EVEN TRY.
4. “FUTURE
depends on
what you do TODAY.”
5. Good\\to\see\you\\\again.
6. Temp=100, Test=200
7. /* Good Morning, Nice Day */ (Also print /* and */).
8. Score 1: 199
Score 2: 165
Score 3: 50
9. 1234 5678 93212
10. printf(“(Good Morning)”);
6. Write a snippet of code for each given problem.
1. Accept your Birth Year and weight and display it.
2. Accept your gender(M/F) and display it.
3. Accept mobile price and discount percentage using single and display it.
7. Write appropriate statement to take input for the followings using single input statement and
also display the entered value with proper message using single output statement.
1. The values for i, j and k which are all integer type.
2. The values for i and j are integer type and value for k is floating-point type.
3. The values for i, j and k are all character type.
4. The values for i is integer type, for j is floating point type and for k is character type.

MS. CHETANA TAILOR | DR. KALPESH LAD 6


Bhulabhai Vanmalibhai Patel Institute of Computer Science 2021-2022
5. The value for i is floating point type and j is character type.
Pre- Basic concepts of Programming such as identifier’s naming convention, declaration, I/O statement.
requisite
Objective(s): To test basic understanding regarding identifier, variable, constant, declaration and I/O statements.
Duration for 3 Hours
completion
Solution Hand written answers
must
contain
Evaluation
Criteria Rating (1- 4)
Correctness of Solution
Timeliness
Viva
Signature and Date

MS. CHETANA TAILOR | DR. KALPESH LAD 7


Bhulabhai Vanmalibhai Patel Institute of Computer Science 2021-2022

Practical : 02 Enrollment No. :


Problem 1. Convert the following Mathematical expression into programming language expression:
Definition a. ItemCost=3000 No
b. Surface Area of a Sphere = S = 4πr2
c. The volume of Cylinder = V = πr2h
d.

e.

f.

2. Evaluate the above expression by considering the following values:


a. No=10
b. r=7
c. r=7, h=10
d. number= 5658
e. Followings are the values for e. and f.
i. TruePositive=57
ii. FalsePositive=14
iii. FalseNegative=23
iv. TrueNegative=171
3. What is the output of the program below?
#include <iostream>
using namespace std;
int main()
{
int no=4;
cout<<(no = 4)<<endl;
cout<<(no == 4)<<endl;
cout<<(no > 3)<<endl;
cout<<(no < 4)<<endl;
cout<<(no = 0)<<endl;
cout<<(no == 0)<<endl;
cout<<(no > 0)<<endl;
return 0;
}
Convert the above given code segment into Java programming language.

4. Write a program for the below given algorithm to calculate the cost of colouring where
per square feet cost is 40 Rs. Customer wants to know the cost of the room’s to be
painted which is in squar shape. Customer has measured the length and width in meter.
[1 meter= 3.2804 feet]
Step 1: [Start of the algorithm]
START
Step 2: [Display message]
Print “Give the length of your room in meter:”
Step 3: [Accept length of room]
Input L.
Step 4: [Calculate the area of the room.]
Area=L*L
Step 5: [Covert square meters in to square feet.]

MS. CHETANA TAILOR | DR. KALPESH LAD 8


Bhulabhai Vanmalibhai Patel Institute of Computer Science 2021-2022
Area=Area*3.2804*3.2804
Step 6: [Calculate the cost of colouring]
Cost=Area*40
Step 7: [Display the cost of the colouring]
Print: “Total cost of colouring the room is:”, Cost
Step 8: [End of the algorithm]
End
5. Write a program to find the lucky number from the birth year. If the birth year of a
person is 1989, lucky number is 1+9+8+9=27 for which flowchart is given below.

Pre-requisite : Mathematical operators, Algorithms, Flowchart, C++ and Java Program


Objective(s) : To get aquatinted with C++, and Java environment including arithmetic and relational
expression representation in programming language.
Duration for 3 Hours
completion
Solution must Hand written solution of each of the above questions and sample calculation with input and
contain output data for questions 4 and 5.
Evaluation :
Criteria Rating (1- 4)

MS. CHETANA TAILOR | DR. KALPESH LAD 9


Bhulabhai Vanmalibhai Patel Institute of Computer Science 2021-2022
Completeness of Solution
Code Correctness
Documentation
Viva
Timeliness
Signature and Date

MS. CHETANA TAILOR | DR. KALPESH LAD 10


Bhulabhai Vanmalibhai Patel Institute of Computer Science 2021-2022

Practical : 03 Enrollment No. :


Problem 1. Write an algorithm and a program to calculate total salary including commission for
Definition sales person who sales the two wheelers. Sales person get 20,000 Rs. monthly fixed
salaries and got the commission based on no of two wheelers sales in a month. There is
no commission up to 10 two wheelers sale. If sales person sales above 10 two wheelers’
sales during month than get the commission of 500 Rs on each two wheelers.
2. Draw flowchart and write a program of given algorithm which classify the human based
on age. Four categories are as Child (0-12 years), Adolescence (13-18 years), Adult (19-
59 years) and Senior Adult (60 years and above)
Test Data :
Age - 5
Expected Output :
Child

Algorithm:
Step-1 [Starting of algorithm]
Start
Step-2 [To accept age of human]
Input Age
Step-3 [Check whether the age is below 12 or not]
if Age<=12 than go to step - 4
otherwise go to step - 6
Step-4 [Display message “Child”]
Print “Child”
Step-5 [Transfer the control flow]
go to step – 13
Step-6 [Check whether the age is below 18 or not]
if Age<=18 than go to step - 7
otherwise go to step – 9
Step-7 [Display message “Adolescence” ]
Print “Adolescence”
Step-8 [Transfer the control flow]
go to step - 13
Step-9 [Check whether the age is below 59 or not]
if Age<=59 than go to step - 10
otherwise go to step - 12
Step-10 [Display message “Adult” ]
Print “Adult”
Step-11[Transfer the control flow]
go to step – 13
Step-12 [Display message “Senior Adult”]
print “Senior Adult”
step-13 [Ending of the algorithm]
End

Pre-requisite if statement
Objective(s) To use the conditional statement such as if statement and multiple if statements for solving the
problem.
Duration for 2 hours

MS. CHETANA TAILOR | DR. KALPESH LAD 11


Bhulabhai Vanmalibhai Patel Institute of Computer Science 2021-2022
completion
Solution must Hand written solution of each of the above questions and sample calculation with input and
contain output data for questions 1,2.
Evaluation : Criteria Rating (1- 4)
Completeness of Solution
Code Correctness
Documentation
Viva
Timeliness
Signature and Date

MS. CHETANA TAILOR | DR. KALPESH LAD 12


Bhulabhai Vanmalibhai Patel Institute of Computer Science 2021-2022

Practical : 04 Enrollment No. :


Problem Definition 1. Draw a flowchart and write a program to find the eligibility of admission for a
professional course based on the following criteria:
Marks in Mathematics >=75
Marks in Physics >=78
Marks in Chemistry>=65
Total in all three subject >=210
Note: Do not use logical operator.
Test Data:
Input the marks obtained in Physics :85
Input the marks obtained in Chemistry :65
Input the marks obtained in Mathematics :92
Expected Output:
The candidate is eligible for admission.
2. What is the output of this program? Why?
#include <iostream>
using namespace std;
main ()
{
int balance;
balance=25000;
if (balance = 0)
cout << "You have nothing.\n";
else
cout << "You have " << balance << " Rupees.\n";
return (0);
}

3. What is the output of this program? 4. What is the output of this program?
#include <iostream> #include <iostream>
using namespace std; using namespace std;
int main() int main()
{ {
float f1 = 0.5; int p = 10, q = 20, r;
double f2 = 0.5; if (r = p = q || q > 20)
if (f1 == 0.5f) cout<< r;
cout << "equal"; else
else cout<< "No Output\n";
cout << "not equal"; return 0;
return 0; }
}
Pre-requisite if…else, nested if statements
Objective(s) To implement the conditional statement namely if...else and nested if statements for solving the
problem.
Duration for 2 hours
completion
Solution must Hand written solution of each of the above questions and sample calculation with input and
contain output data for questions 4 and 5.
Evaluation: Criteria Rating (1- 4)

MS. CHETANA TAILOR | DR. KALPESH LAD 13


Bhulabhai Vanmalibhai Patel Institute of Computer Science 2021-2022
Completeness of Solution
Code Correctness
Documentation
Viva
Timeliness
Signature and Date

MS. CHETANA TAILOR | DR. KALPESH LAD 14


Bhulabhai Vanmalibhai Patel Institute of Computer Science 2021-2022

Practical : 05 Enrollment No.:

Problem 1. Write an algorithm and a Java program for a UTU Teacher for generating grade
Definition labels using following table.
Percentage range Grade Labels
0-50 Below Average
51-60 Average
61-75 Good
76-90 Very Good
91-100 Excellent
Sample Input/Output:
Input:
Enter percentage: 95.5
Output:
Grade: Excellent
2. Write a program according to given below flowchart using switch and if..elseif
statement.

Pre-requisite if…elseif, switch statements


Objective To verify the understanding for the concept if…elseif and switch statements.
Duration for 3 Hours
completion

MS. CHETANA TAILOR | DR. KALPESH LAD 15


Bhulabhai Vanmalibhai Patel Institute of Computer Science 2021-2022
Solution must Hand written solution of each of the above questions and sample calculation with input and
contain output data for questions 1,2.
Evaluation : Criteria Rating (1- 4)
Completeness of Solution
Code Correctness
Documentation
Viva
Timeliness
Signature and Date

MS. CHETANA TAILOR | DR. KALPESH LAD 16


Bhulabhai Vanmalibhai Patel Institute of Computer Science 2021-2022

Practical : 06 Enrollment No. :


Problem 1. Write an algorithm for any one of the following series. Write a program to display first
Definition N terms of each of the following series:
a. 0, 3, 8, 15, 24, 35, 48 …..
b. 1, 1.5, 2.5, 4, 6, 8.5, 11.5, 14….
c. A, B, D, G, K, P, V, C, K, T…
d. 1, B, 8, D, 32, F, 128, H, 512….
2. Write a program that takes two positive integers, a and b (a <=b), separated by a
newline and generate an output as given format.
Output Format
For each integer n in the inclusive interval [a, b]:
 If 1 <= n <= 9, then print the English representation of it in lowercase. That is
"one" for 1,"two" for 2, and so on.
 Else if n >9 and it is an even number, then print "even".
 Else if n >9 and it is an odd number, then print "odd".
Sample Input
8
11
Sample Output
eight
odd
3. Write the output for the following programs:
#include <iostream> #include <iostream> #include <iostream>
using namespace std; using namespace std; using namespace std;
int main() int main() int main()
{ { {
int a = 100; for (int i = 75; i >= 69; --i) int n = 15;
if (a >= 100) { cout << (char) i; for ( ;n>=10 ;)
for (i = 0; i < 5; i++) return 0; cout << n;
cout << i+1; } return 0;
} }
else {
cout << i-1;
}
return 0;
}
Pre-requisite Loop
Objective(s) To apply the simple loop statement in developing the programs.
Duration for 4 Hours
completion
Solution must Flow chart, Code , Sample Input and output
contain
Evaluation: Criteria Rating (1- 4)
Completeness of Solution
Code Correctness
Reusability
Documentation
Timeliness
Signature and Date

MS. CHETANA TAILOR | DR. KALPESH LAD 17


Bhulabhai Vanmalibhai Patel Institute of Computer Science 2021-2022

Practical : 07 Enrollment No. :


Problem 1. Write a program that reads N vowel characters from user and display the characters’
Definition detail in following format.
Sample Input:
How many vowels characters you want to enter? 11
Enter the characters:
I
o
A
O
E
a
i
R
e
U
i
Output:
No of time “A or a“ vowel occurs : 2
No of time “E or e“ vowel occurs : 2
No of time “I or i“ vowel occurs : 3
No of time “O or o“ vowel occurs : 2
No of time “U or u“ vowel occurs : 1
No of time other characters occurs: 1

2. Complete the following program code which accepts N positive integer numbers from
user and display minimum number in word among two-digit numbers only otherwise
display appropriate message.
#include <iostream>
using namespace std;
int main()
{
int n, min=0;
cout<<"How many positive integer numbers do you want to input?";
cin>>n;
for(i=1; i<=n; i++)
{
....... .......
}
if (min != 0)
{
cout<<"Minimum Number is:"<<min;
/*write a code to print each digit of minimum number in word
e.g. min=23 o/p: two three
*/
}
else
cout<<"2-digit number is not found.";
return 0;
}
Pre-requisite Loop, Conditional Statement

MS. CHETANA TAILOR | DR. KALPESH LAD 18


Bhulabhai Vanmalibhai Patel Institute of Computer Science 2021-2022
Objective(s) To process characters using Loop and Conditional statements.
Duration for 3 Hours
completion
Solution must Hand written solution of each of the above questions and sample calculation with input and
contain output data for question 2.
Evaluation : Criteria Rating (1- 4)
Completeness of Solution
Code Correctness
Viva
Timeliness
Signature and Date

MS. CHETANA TAILOR | DR. KALPESH LAD 19


Bhulabhai Vanmalibhai Patel Institute of Computer Science 2021-2022

Practical : 08 Enrollment No. :


Problem 1. Write a program for below given algorithm which accept N integer numbers from user
Definition and display average of all integers between 50 and 250 which are divisible by 3 and 5.
Input Numbers:
108 55 117 126 135 144 80 153 405 165 171 180 189 198 45
Expected Output:
The Average: 160

Algorithm:
Step-1 [ Starting of algorithm]
Start
Step-2 [ Accept the value of N which indicates that user want to process N different integer
numbers]
Input N
Step-3 [To intialize counter 'i' and 'sum' variable with 0]
Let sum=0
Let count=0
Let i=0
Step-4 [To check N integer numbers inputted or not]
if i<N than go to step - 5
otherwise go to step - 12
Step-5 [To accept integer number]
Input No
Step-6 [ To check inputted integer number is more than equal to 100 or not]
if No >= 50 than go to step - 7
otherwise go to step - 10
Step-7 [ To check inputted integer number is less than equal to 200 or not]
if No <= 250 than go to step - 8
otherwise go to step - 10
Step-8 [ To check inputted integer number is divisible by 9 or not]
if No mod 3 == 0 and No mod 5 == 0 than go to step - 9
otherwise go to step - 10
Step-9 [ To add integer number into 'sum' variable]
sum=sum + No
Step-10 [ To increase the ‘count’ variable value by 1]
count=count + 1
Step-11 [ To increase the value of counter variable 'i' by 1]
i=i+1
Step-11 [ To transfer flow control]
go to step - 4
Step-12 [To display average of all integer numbers which are between 100 and 200,
also divisible by 3 and 5 ]
print sum/count
step-13 [Ending of algorithm]
Stop
2. If other than positive number is entered by user, then don’t accept that number and ask
user to enter the valid positive number till the positive number is entered by user in
above practical 1. Also add code for the same in above program. Draw the flowchart for
the same.
Which loop is preferable to add data validation among three different looping
statements? Why? List three differences between event driven loop and counter control

MS. CHETANA TAILOR | DR. KALPESH LAD 20


Bhulabhai Vanmalibhai Patel Institute of Computer Science 2021-2022
loop. Also draw the flowchart for event driven and counter control loop. What are the
three common mistakes found in looping statements?

3. Write the output for the following code segment:


#include <iostream> #include <iostream> #include <iostream>
using namespace std; using namespace std; using namespace std;
void main() int main() int main()
{ { {
int i = 0; int a = 0, i = 0; int a = 0, i = 0;
while (i--) for (i = 0;i < 5; i++) for (i = 0;i < 9999; i++)
{ { {
cout<<"B"; a++; a++;
} continue; if (i == 5)
return 0; } break;
} cout<<a; }
} cout<<a;
}
Pre-requisite Loop, break and continue
Objective To introduce the event driven loop usage in data validation.
Duration for 3 Hours
completion
Solution must Hand written solution of each of the above questions and sample calculation with input and
contain output data for questions 2.
Evaluation : Criteria Rating (1- 4)
Completeness of Solution
Code Correctness
Viva
Timeliness
Signature and Date

MS. CHETANA TAILOR | DR. KALPESH LAD 21


Bhulabhai Vanmalibhai Patel Institute of Computer Science 2021-2022

Practical : 09 Enrollment No. :


Problem 1. Write an algorithm and a program to print the following triangle for number of rows to
Definition be printed ‘n’ is 5.
25
20 19
15 14 13
10 9 8 7
5 4 3 2 1
2. Draw a flow chart and write a program to print the following triangle for number of
rows to be printed ‘n’ is 5.
1
BC
345
DEFG
56789
3. Print a pattern of numbers from 1 to n (n<=9) as shown below. Each of the numbers is
separated by a single space.
Sample Input
4
Sample Output
4444444
4333334
4322234
4321234
4322234
4333334
4444444

Pre-requisite Nested Loop


Objective To implement nested loop in developing programs.
Duration for 3 Hours
completion
Solution must Hand written solution of each of the above questions and sample calculation with input and
contain output data for questions 1,2.
Evaluation : Criteria Rating (1- 4)
Completeness of Solution
Code Correctness
Viva
Timeliness
Signature and Date

MS. CHETANA TAILOR | DR. KALPESH LAD 22


Bhulabhai Vanmalibhai Patel Institute of Computer Science 2021-2022

Practical : 10 Enrollment No. :


Problem 1. Write a program to find statistics of M. S. Dhoni in his last “N” innings score. Provide a
Definition provision to store maximum 50 innings scores.
Input:
How many inning score do you want to enter: 5
Enter 5 inning scores: 145 0 51 35 99
Output:
Highest score is 145.
Lowest score is 0.
Average score is 66.
Innings with Average score are 1, 5.
2. Arrange the code given below which calculate the sum of positive two digits numbers
which are divisible by 5 among user given 10 numbers:
class MyClass
{
public static void main(String argv[])
{
System.out.println("Sum of number is:"+sum);
if(mark[i]%5==0)
sum=sum+mark[i];
for(i=0;i<10;i++)
if (mark[i]>=0)
mark[i]=sc.nextInt();
int mark[]=new int[10];
if (mark[i]>=10 && mark[i]<100)
Scanner sc=new Scanner(System.in);
{{
int sum=0, i;
}}
for(i=0;i<10;i++)
System.out.println("Enter Ten Numbers:");
}
}
After arranging the code, draw the flowchart for the same.
3. Answer the following questions with appropriate explanation:
1. Which of the following array initialization statement is valid? State reason for
invalid statement.
a. int ary[]={100, 2, 30, 4};
b. int ary[-5]={0, 5, 10, 20, 30};
c. int ary[4.5]={1, 2, 3, 4, 5};
d. int ary[4]={1 ,2 ,3 ,4 ,5 ,6};
2. Which of the following statements assigns the value stored in x into the fifth
element of an array, ary?
a. ary(4) = x;
b. ary[5] = x;
c. ary[4]=x;
d. ary=x[4];
3. What will be the output of following program? Write output with proper
justification.
int main()

MS. CHETANA TAILOR | DR. KALPESH LAD 23


Bhulabhai Vanmalibhai Patel Institute of Computer Science 2021-2022
{
float a[5];
cout<<sizeof(a);
return 0;
}
4. Consider the following array:
int a[]={1,2,3,4,5,6};
What will be the value of total after the following loop complete?
int total=0,i;
for(i=0; i<6; i+=2)
{
total = total + a[i];
}
Pre-requisite Numeric array
Objective To work on numeric array with required operations.
Duration for 3 Hours
completion
Solution must Program code with appropriate sample input and output of problem 1 and 2 and answers of all
contain the questions defined under problem 3.
Evaluation : Criteria Rating (1- 4)
Completeness of Solution
Code Correctness
Viva
Timeliness
Signature and Date

MS. CHETANA TAILOR | DR. KALPESH LAD 24


Bhulabhai Vanmalibhai Patel Institute of Computer Science 2021-2022

Practical : 11 Enrollment No. :


Problem 1. Write a program to count total number of declaration statements written by user which
Definition are given in form of paragraph. Statements are delimited by semicolon mark.
e.g.
Input Paragraph:
int x=0; float d=10.5, k; char x=’a’;
Output:
No of declaration statements: 3
2. Write a program to count the palindrome words in sentence which is given by user.
3. Write a program to authenticate user for whom user name and password are already stored
in the program for the below given cases to be verified:
User Name Password Message
Valid username Valid password Welcome to BVPICS.
Invalid username Valid password Please try again.
Valid username Invalid password Please try again.
Invalid username Invalid password Please try again.
If user tries to authentic himself or herself more Please contact to admin.
than three time:
Pre-requisite String
Objective To process the string for performing basic task of text processing.
Duration for 4 Hours
completion
Solution must Program codes followed by sample input and output.
contain
Evaluation : Criteria Rating (1- 4)
Completeness of Solution
Code Correctness
Viva
Timeliness
Signature and Date

MS. CHETANA TAILOR | DR. KALPESH LAD 25


Bhulabhai Vanmalibhai Patel Institute of Computer Science 2021-2022

Practical : 12 Enrollment No. :


Problem Definition 1. Write a program to find the value of a matrix C having order 3 X 3 where C is made
up of 2AB-(B/5) i.e., C=2AB-(B/5). Take value of the matrix A, B from user.
2. Also add code which finds the maximum element in the matrix C.
3. State whether the following initialization of an array is valid or invalid with proper
reason.
A)float item[3][2]={0,1,2,3,4,5};
B)int m[3,5]={1,2,3,4,5};
C)int m2[2][1]={0,9,8,7,6,5,4,3,2,1};
4. Find out syntax error if any otherwise write the output of following code segment.
int main() {
int test[2][3] ={{12, -15},{14, 10},{19,41}};
for(int i = 0; i < 3; ++i) {
for(int j = 0; j < 2; ++j){
cout<< "test["<<i<<"]["<<j<<"]="<<test[i][j]<<endl;
}
}
return 0;
}

Pre-requisite Two dimensional array


Objective To work with two dimensional array and perform arithmetic operations on it.
Duration for 3 Hours
completion
Solution must contain Programme code for problem 1, 2 and answers of the questions 3, 4, and 5.
Evaluation : Criteria Rating (1- 4)
Completeness of Solution
Code Correctness
Viva
Timeliness
Signature and Date

MS. CHETANA TAILOR | DR. KALPESH LAD 26


Bhulabhai Vanmalibhai Patel Institute of Computer Science 2021-2022

Practical : 13 Enrollment No. :


Problem 1. Write a user defined function named "lessThan100" that takes two integer argument and
Definition return true if the sum of both numbers is less than 100. Otherwise return false.
E.g.
lessThan100(22, 15) ➞ true
// 22 + 15 = 37
lessThan100(83, 34) ➞ false
// 83 + 34 = 117
lessThan100(3, 77) ➞ true
//3+77=100
2. Write a function that takes two numbers and a mathematical operator and returns the
result. e.g.
calculate(4, 9, '+') ➞ 13
calculate(12, 5, '-') ➞ 7
calculate(6, 3, '*') ➞ 18
calculate(25, 5, '/') ➞ 5
calculate(14, 3, '%') ➞ 2
3. Write a user defined function named as “ispalindrome” which takes one integer
argument and display message whether given number is palindrome or not. Write a
program which accept N integer numbers and display all palindrome numbers using
ispalindrome().
4. What is the output of this code segments A and B?
//Code segment A. //Code segment B.
class Test { #include <iostream>
public static void main(String args[]) { using namespace std;
System.out.println(fun()); int i;
} void increment( int i ){
static int fun() { i++;
static int x= 0; }
return ++x; int main(){
} for (i = 0; i < 10; increment( i )){
} cout << i;
}
return 0;
}

Pre-requisite User defined function


Objective To acquaint students with user defined function with one argument.
Duration for 3 Hours
completion
Solution must Program code with proper sample input and output. Answer of the code segment A, B and C.
contain
Evaluation : Criteria Rating (1- 4)
Completeness of Solution
Code Correctness
Viva
Timeliness
Signature and Date

MS. CHETANA TAILOR | DR. KALPESH LAD 27


Bhulabhai Vanmalibhai Patel Institute of Computer Science 2021-2022

Practical : 14 Enrollment No. :


Problem 1. Write a user defined function named "multiply_from_to" that takes two integer
Definition arguments, call them "first" and "last", and returns as its value the multiply of all the
integers between first and last inclusive. Thus, for example,
cout << multiply_from_to(4,7) << endl; // will print 840 because 4*5*6*7 = 840
cout << multiply_from_to(-2,1) << endl; // will print 0 because (-2)*(-1)*0*1 = 0
cout << multiply_from_to(7,4) << endl; // will print 840 because 7*6*5*4 = 840
cout << multiply_from_to(9,9) << endl; // will print 9

2. Write a user defined function which accept the Programme name and convert it into
TOGGL CASE. Prototype of the function is : void tOGGLcASE(char title[])

Sample Input/Output:
Enter the Programme Name: Bachelor OF Computer APPLICATION
Programme Name is: bACHELOR OF cOMPUTER aPPLICATION

Pre-requisite Multiple parameter, Array passing in User defined function


Objective To implement user defined function with the multi-arguments for solving the problem.
Duration for 3 Hours
completion
Solution must Program code for the problem definition 1, and 2
contain
Evaluation : Criteria Rating (1- 4)
Completeness of Solution
Code Correctness
Viva
Timeliness
Signature and Date

MS. CHETANA TAILOR | DR. KALPESH LAD 28


Bhulabhai Vanmalibhai Patel Institute of Computer Science 2021-2022

Practical : 15 Enrollment No. :


Problem 1. Write a function namely "CharFrequency" that takes two arguments, one as a string and
Definition second one as character. CharFrequency() counts the frequency of character in given
string and return it.
Example:
CharFrequency(“INDIA”, ‘I’) -- 2
CharFrequency(“This is an sample test”, ‘s’) --4
2. Arrange the below given code to count the Consonants in the inputted string.
int vowelCount(char str[])
{
return 0;
while(str[i] != ‘\0’)
{
i++;
cnt++
}
if(str[i]!=’a’||str[i]!=’A’||str[i]!=’e’||str[i]!=’E’||str[i]!=’i'||str[i]!=’I’||str[i]!=’o'
||str[i]!=’O’||str[i]!=’u’||str[i]!=’U’)
{}
int i=0, cnt=0;
}
int main()
{
int cnt;
cout<<”Number of Consonants are:”<<cnt;
char textStr[20];
cin>>textStr;
return 0;
}
3. Write two alternative solution for the function vowelCount().

Pre-requisite User defined function, Array


Objective To solve the problem by passing array in a user defined function.
Duration for 3 Hours
completion
Solution must Program code for problem 1,2 and 3.
contain
Evaluation : Criteria Rating (1- 4)
Completeness of Solution
Code Correctness
Viva
Timeliness
Signature and Date

MS. CHETANA TAILOR | DR. KALPESH LAD 29


Bhulabhai Vanmalibhai Patel Institute of Computer Science 2021-2022

Practical : 16 Enrollment No. :


Problem Observe the below given class:
Definition Person
-AdharNo: String
-FirstName: String
-MiddleName: String
-LastName: String
-Address: String
-BirthYear: Integer
-Gender:Char
-ContactNo: String
+SetAdharNo(String):void
+SetFirstName(String):void
+SetMiddleName(String):void
+SetLastName(String):void
+SetAddress(String):void
+SetBirthYear(Integer):void
+SetGender(Char):void
+SetContactNo(String):void
+GetAdharNo():String
+GetFirstName():String
+GetMiddleName():String
+GetLastName():String
+GetAddress():String
+GetBirthYear():Integer
+GetGender():String
+GetContactNo():String
+Display():void
1. State atleast three advantages of class.
2. Write the name of the class and list all the properties in the above class including
methods of the class.
3. Write the need of set and get methods defined for the class in brief.
4. Define a class according to the class diagram given above.
5. Implement the above class by creating its instance of the class.
Pre-requisite Class
Objective To implement the class according to the given class design.
Duration for 3 Hours
completion
Solution must Program code, sample input output.
contain
Evaluation : Criteria Rating (1- 4)
Completeness of Solution
Code Correctness
Viva
Timeliness
Signature and Date

MS. CHETANA TAILOR | DR. KALPESH LAD 30


Bhulabhai Vanmalibhai Patel Institute of Computer Science 2021-2022

Practical : 17 Enrollment No. :


Problem 1. Create class Number with one data member namely number. To include the following
Definition methods
setNumber() - initialize property of Number class
getNumber() - return the property's value namely number
IsPositive( ) - returns true if number is positive otherwise false
IsThreeDigits( ) - returns true if number’s having 3 otherwise false
GetSquare() - returns the square of number
isPrime() - returns true if number is prime otherwise false
Write a main() function to create an object of Number class and display appropriate
output using class method.
2. Why this code prints 100 rather than 90.
public class Test {
public int x=100;
public void Test() {
x=90;
}
public static void main(String[] args)
Test t = new Test();
System.out.println(t.x);
}
}

3. Write the output of the following Java program:


class Test {
int i;
float f;
}
class Main {
public static void main(String args[]) {
Test t = new Test();
System.out.println(t.i);
System.out.println(t.f);
}
}
4. Write the output of the following program:
class Test
{
int a = 10;
int b = 20;

Test func(Test obj)


{
Test obj3 = new Test();
obj3 = obj;
obj3.a = obj.a++ + ++obj.b;
obj.b = obj.b;
return obj3;
}

MS. CHETANA TAILOR | DR. KALPESH LAD 31


Bhulabhai Vanmalibhai Patel Institute of Computer Science 2021-2022
public static void main(String[] args)
{
Test obj1 = new Test();
Test obj2 = obj1.func(obj1);

System.out.println("obj1.a = " + obj1.a + " obj1.b = " + obj1.b);


System.out.println("obj2.a = " + obj2.a + " obj1.b = " + obj2.b);
}
}
Pre-requisite Class
Objective To create a method with business logic in class.
Duration for 2 Hours
completion
Solution must Class diagram, Code of the program with sample input output data.
contain
Evaluation : Criteria Rating (1- 4)
Completeness of Solution
Code Correctness
Viva
Timeliness
Signature and Date

MS. CHETANA TAILOR | DR. KALPESH LAD 32


Bhulabhai Vanmalibhai Patel Institute of Computer Science 2021-2022

Practical : 18 Enrollment No. :


Problem  Implement following functionalities in practical 16.
Definition  A default constructor.
 A constructor which initializes the AdharNo, FirstName, MiddleName, LastName
and Address attributes of class.
 A constructor which initializes all attributes of class.
 GetAge() - It’s return the current age on the basis of Birth Year.
 GetFullName() - It’s return the Full Name in the order of LastName, FirstName,
MiddleName.
 GetPersonCategory() – it’s returns human category based on person age. Categories
are as Child (0-12 years), Adolescence (13-18 years), Adult (19-59 years) and
Senior Adult (60 years and above)
Write a main() function to create and initialize an object of Person class and display
Person details including age and category.
 What is the output of the following Java program?
class A {
public void S() { n = 0; }
public void S(int a) { n = a; }
public void f() { n++; }
public void g() { f(); n = 2 * n; f(); }
public int h() { return n; }
public void k() { System.out.println(n); }
private int n;
}
public class P1 {
public static void main(String[] args) {
A a = new A();
A b = new A();
A c = new A();
a.S(3);
b.S(2);
c.S(1);
c.f();
A e = new A();
e.S(a.h() + b.h() + c.h()) ;
e.k();
}}
 Consider the following class and give the answer of Q-1 to 3:
public class Temp {
public static int No = 100;
public int y = 45;
}
1. What are the class variables?
2. What are the instance variables?
3. What is the output from the following code:
IdentifyMyParts a = new IdentifyMyParts();
IdentifyMyParts b = new IdentifyMyParts();
a.y = 21;
b.y = 45;
a.x = 56;
b.x = 34;

MS. CHETANA TAILOR | DR. KALPESH LAD 33


Bhulabhai Vanmalibhai Patel Institute of Computer Science 2021-2022
System.out.println("a.y = " + a.y);
System.out.println("b.y = " + b.y);
System.out.println("a.x = " + a.x);
System.out.println("b.x = " + b.x);
System.out.println("IdentifyMyParts.x = " + IdentifyMyParts.x);

Pre-requisite Class, Constructors


Objective To make them aware regarding the concept of Constructors in a class.
Duration for 2 Hours
completion
Solution must Class diagram, Program code with sample input and output
contain
Evaluation : Criteria Rating (1- 4)
Completeness of Solution
Code Correctness
Viva
Timeliness
Signature and Date

MS. CHETANA TAILOR | DR. KALPESH LAD 34


Bhulabhai Vanmalibhai Patel Institute of Computer Science 2021-2022

Basic Coding Rules to Follow


1. Use descriptive and appropriate names for all identifiers (variables, method names, class
names, constants, etc.).
2. Comment confusing sections of code.
3. Proper indentation should be maintained.
4. Be neat.

Identifier Naming and Capitalization


Guidelines
 Use descriptive names for all variables, function names, constants, and other identifiers. Use
single letter identifiers only for the counter in loops.
 Variable names start with lower case.
 Multi-word identifiers are internally capitalized.
 Do not use hyphens or underscores to separate multi-word identifiers (exception only for
those who use speech recognition software).

Example

float sumOfSquares = 0;

Counter Example

float Sum = 0;
float sumofsquares = 0;
float sum_of_squares = 0;
float qw = 0;

Comments: Classes
Guidelines
 Every class should be preceded with a descriptive comment using the “JavaDoc” notational
convention. The comment should name the class, describe its purpose, and name the author.

Example

/**
* Haiku, prints a haiku.
* @author Suzuki, Susan
*/
public class Haiku {
// ...

MS. CHETANA TAILOR | DR. KALPESH LAD 35


Bhulabhai Vanmalibhai Patel Institute of Computer Science 2021-2022
}

Comments: Methods
Guidelines
 Every method should be preceded with a descriptive comment using the “JavaDoc”
notational convention. The comment should name the method, describe its purpose,
comment all arguments, the return value, and any exceptions using JavaDoc keywords.
(Omit @return and @exception, if the return value is void or there are no exceptions
thrown.)

Example

/**
* Attempts to print a word. Indicates whether printing was possible.
* @param word to print, must not contain spaces
* @return true if printer is available, false otherwise
* @exception SpacesFoundException if there are any spaces in the word
*/
public boolean printWord(String word) throws SpacesFoundException {
// ...
}

Comments: Public variables


Guidelines
 Every public variable should be preceded with a descriptive comment using the “JavaDoc”
notational convention. The comment should describe the purpose for the public variable.

Example

/** Toggles between Frame and NoFrame mode. */


public boolean frameMode = true;

Comments: In-line
Guidelines
 In-line comments should be used to explain complicated sections of code, such as loops. Use
the // comment delimiter for in-line comments. Do not comment generally known features
of the java language.

Example

// Do a 3D transmogrification on the matrix.

MS. CHETANA TAILOR | DR. KALPESH LAD 36


Bhulabhai Vanmalibhai Patel Institute of Computer Science 2021-2022
for (int i = 0; i < matrix.length; i++) {
for (int j = 0; j < matrix.length; j++) {
for (int k = 0; k < matrix.length; k++) {
values.transmogrify(matrix[i],matrix[j],matrix[k]);
}
}
}

Counter Example

i++; // increments i
// the variable "i" loops from 0 to the length of matrix
for (int i = 0; i < matrix.length; i++) {
// ...
}

Spacing: Between lines


Guidelines
 Use two blank lines to separate each method within a class definition. Use one blank line to
separate logical sections of code within a method.

Example

public static void main(String[] arg) {


System.out.println("Hello" + " " + "World");
}

public void foo() {


// ...
}

Spacing: Within lines


Guidelines
 Put a single space before every “{“.
 Separate all operators such as “+” with a single space.

Example

public static void main(String[] arg) {

MS. CHETANA TAILOR | DR. KALPESH LAD 37


Bhulabhai Vanmalibhai Patel Institute of Computer Science 2021-2022
System.out.println("Hello" + " " + "World");
}

Counter Example

public static void main(String[] arg){


System.out.println("Hello"+" "+"World");
}

Indentation
Guidelines
 Indent two spaces when beginning a new block.
 Open braces (i.e. “{“) do not start a new line.
 Close braces (i.e. “}”) do start a new line, and are indented with the code they close.
 Comments line up with the block they comment.

Example

for (int i=0; i < args.length; i = i + 1) {


vals.insertElementAt(new Float (args[i]), i);
// Transmogrify is incremental and more efficient inside the loop.
vals.transmogrify();
}

Counter Example

for (int i=0; i < args.length; i = i + 1)


{
vals.insertElementAt(new Float (args[i]), i);
// Transmogrify is incremental and more efficient inside the loop.
vals.transmogrify();
}

Class and Method Naming and Capitalization


Guidelines
 Classes begin with a capital letter.
 Methods begin with a lower case letter.
 Multi-word identifiers are internally capitalized in methods (CamelCase).

MS. CHETANA TAILOR | DR. KALPESH LAD 38


Bhulabhai Vanmalibhai Patel Institute of Computer Science 2021-2022
Example

class MeanStandardDeviation
private Vector getNewVector(Vector oldVector) {

Counter Example

public class Meanstandarddeviation


private Vector GetNewVector(Vector oldVector) {

MS. CHETANA TAILOR | DR. KALPESH LAD 39

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy