0% found this document useful (0 votes)
14 views5 pages

CT2 Set 3

This document outlines the details for the Cycle Test II for the B.Tech program at SRM Institute of Science and Technology, including course code, learning outcomes, and test structure. It consists of multiple parts with questions related to programming concepts in C and Python, including algorithm construction, data types, and string functions. The test is scheduled for May 10, 2023, with a total of 50 marks available.

Uploaded by

nimishparmar06
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)
14 views5 pages

CT2 Set 3

This document outlines the details for the Cycle Test II for the B.Tech program at SRM Institute of Science and Technology, including course code, learning outcomes, and test structure. It consists of multiple parts with questions related to programming concepts in C and Python, including algorithm construction, data types, and string functions. The test is scheduled for May 10, 2023, with a total of 50 marks available.

Uploaded by

nimishparmar06
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/ 5

SRM Institute of Science and Technology Slot F,Batch 2

SET 3
College of Engineering and Technology OFF LINE
CYCLE TEST – II
Academic Year: 2022-2023 (EVEN Semester)

Program offered: B.Tech Year / Sem: I/ II


Max. Marks: 50 Time :2.15PM -04.00PM
Date :10-05-2023

Course Code and Title: 21CSS101J: Programming for Problem Solving


Course Learning Rationale (CLR):
CLR-1: Think and evolve with a logic to construct an algorithm and pseudo code that can be converted into a program.
CLR-2 : Utilize the appropriate operators and control statements to solve engineering problems
CLR-3 : Store and retrieve data in a single and multidimensional array
CLR-4 :Create custom designed functions to perform repetitive tasks in any application
CLR-5 :Create basic Abstract Data Types with python
Course Learning Outcomes (CLO):
CO-1: To solve problems through computer programming. Express the basic data types and variables in C
CO-2 : To use appropriate data types in simple data processing applications. To create programs using the concept ofarrays.
CO-3:Create string processing applications with single and multi-dimensional arrays
CO-4: Create user defined functions with required operations. To implement pointers in applications with dynamic memory
requirements
CO-5: Create programs using the python data types, loops, control statements for problem solving

Answer all questions


Part A (8x1=8 Marks)
Part A-Don’t Mark in question paper. Write in the answer sheet
Sl.N P Mar
Question CO BL
o O ks
1. Select the correct output for the below C code?
#include <stdio.h>
Voidexample(int *);
Voidmain() {
Inti = 10, *p = &i;
example(p);
3 2 4 1
1 }
Voidexample(int *k) {
Printf("%d", *k);
}
(a) Garbage value (c) Compilation error
(b) 10 (d) Segmentation fault
2. Which of the following statements is used to create an empty set in Python?
2 (a) () (c) [ ] 3 1 2 1
(b) {} (d) set ()
3. Suppose list1 is [2, 33, 222, 14, 25],then what is list1[-1]?
3
(a) Error (c) 25 3 1 2 1
(b) None (d) 2
4. If the strings are same, a string function strcmp() returns___________
4 (a) 1 (c) 0 3 1 2 1
(b) -1 (d) 2
5. In the Python programming language, how do we define a block of code? 4 1 2 1
5 (a) Key (c) Indentation
(b) Brackets (d) Brackets
66. Which of the following is the truncation division operator in Python? 4 21 2 1

(a) | (c) /
(b) // (d) %
7. What will be the output of given Python code? 5 2 4 1
7
n=7
c=0
while(n):
if(n>5):
c=c+n-1
n=n-1
else:
break
print(n)
print(c)
(a) 5 11 (c) 7 11
(b) 59 (d) 5 2
What is the order of precedence in python? 5 2 4 1
8 a) Exponential, Parentheses, Multiplication, Division, Addition, Subtraction
b) Exponential, Parentheses, Division, Multiplication, Addition, Subtraction
c) Parentheses, Exponential, Multiplication, Division, Subtraction, Addition
d) Parentheses, Exponential, Multiplication, Division, Addition, Subtraction
Part B (3x4Marks=12 Marks)
Answer all questions
Sl.N Question C PO BL Mar
o O ks
9 In C, explain strtok function with an example. 3 2 4 4
The strtok in c is a library function which breaks the given string into a series of tokens using the
delimiter passed as a parameter. Like if there is a string with multiple words separated by comma
then we can use this function strtok in c with comma(,) as a delimiter to split this string based on
comma.
char *strtok(char *string, const char *delimiter)
10 Write a Python program to find the average of 10 numbers using while loop 4 2 4 4
a=[19, 25, 74, 38, 99, 39, 18, 83, 10, 50]
count=0
sum=0
while (count<len(a)):
sum=sum+a[count]
count=count+1
print('average of list',a,'is',(sum/len(a)))
11 How will you create an empty Data Frame in pandas? 5 2 2 4
To create an empty dataframe by importing pandas from the python library. Later, using the
pd.DataFrame(), create an empty dataframe without rows and columns as shown in the below
example. Note that the DataFrame() class available in the pandas library is similar to the
constructor which is used to construct the class.
df = pd.DataFrame()
Part C( 3x10=30 Marks)
Answer all questions
Sl.N Question C PO BL Mar
o O ks
12 Write a C program to sort a string array in ascending order 10 marks 3 2 4 10
a.
#include <stdio.h>
void main()
{
char str[100],ch;
int i,j,l;
printf("\n\nSort a string array in ascending order :\n");
printf(" \n");
printf("Input the string : ");
fgets(str, sizeof str, stdin);
l=strlen(str);
/* sorting process */
for(i=1;i<l;i++)
for(j=0;j<l-i;j++)
if(str[j]>str[j+1])
{
ch=str[j];
str[j] = str[j+1];
str[j+1]=ch;
}
printf("After sorting the string appears like : \n");
printf("%s\n\n",str);
}
OR
12 Explain the string functions with its syntax :Strlen( ), Strcat ( ), Strcmp( ), Strrev( ), Strcpy( ) 3 1 2 10
b. Strlen( ) (Explanation and any one syntax 2 marks)
The strlen() function takes a string as an argument and returns its length. The returned value is of
type size_t (an unsigned integer type).
Syntax :
n=strlen(str);
length = strlen(str);
length = strlen("pritesh");
char *str = "pritesh";
Strcat ( ) (Explanation and any one syntax 2 marks)
Function takes 2 Strings / Character Array as Parameter
Appends second string at the end of First String. Parameter Taken - 2 Character Arrays /
Strings Return Type - Character Array / String
Syntax :
char* strcat ( char * s1, char * s2);
Strcmp( ) (Explanation and any one syntax 2 marks)
Function takes two Strings as parameter.
It returns integer .
Syntax :
int strcmp ( char *s1, char *s2 ) ;
Strrev( ) (Explanation and any one syntax 2 marks)
reverses a given string in C language. Syntax for strrev( ) function is
given below.
char *strrev(char *string);
strrev() function is nonstandard function which may not available in
standard library in C.
Strcpy( ) (Explanation and any one syntax 2 marks)
Function takes two Strings as parameter.
Header File : String.h
It returns string.
Purpose : Copies String2 into String1.
Original contents of String1 will be lost.
Original contents of String2 will remains as it is.
Syntax :
char * strcpy ( char *string1, char *string2 ) ;
13 Write a Python to get the age of a person as input and report whether the 4 1 2 10
a. person is eligible to vote or not 10 marks
age = int(input("Enter age : "))

if age >= 18:


print("Eligible for Voting!")
else:
print("Not Eligible for Voting!")
OR

13 Explain the basic Tuple operations with examples. (Explanation 5 marks, 4 1 2 10


b. Examples 5 marks)
Tuple is an immutable (unchangeable) collection of elements of different data types. It is an
ordered collection, so it preserves the order of elements in which they were defined.

Tuples are defined by enclosing elements in parentheses (), separated by a comma. The
following declares a tuple type variable.
tpl=() # empty tuple
print(tpl) #output: ()

names = ('Jeff', 'Bill', 'Steve', 'Yash') # string tuple


print(names) #output:('Jeff', 'Bill', 'Steve', 'Yash')

nums = (1, 2, 3, 4, 5) # int tuple


print(nums) #output:(1, 2, 3, 4, 5)

employee=(1, 'Steve', True, 25, 12000) # heterogeneous data tuple


print(employee) #output:(1, 'Steve', True, 25, 12000)
14 Write a program using Numpy for creating an array, identifying data type, shape, 5 2 4 10
a. dimension and to perform arithmetic operations.
Numpy for creating an array
import numpy as np #To import numpy
data1 = [6, 7.5, 8, 0, 1] #To define the data
arr1 = np.array(data1) #To store the data in array
print(arr1) #To print the data stored
[6. 7.5 8. 0. 1. ]
print(arr1.dtype) #To print the data type of the data
float64
print(arr1.shape) #To print the number of elements in the rows and columns (row, Column)
(5,)
print(arr1.ndim) #To print the dimension of the array
1
print (arr*arr) #To multiply the two arrays
[1. 4. 9.]
print (arr-arr) #To divide the two arrays
[0. 0. 0.]
print (1/arr) #To inverse the array
[1. 0.5 0.33333333]
print (arr**0.5) #To the exponential of the array
[1. 1.41421356 1.73205081]

OR
14 Describe the following basic operation which can be performed on Pandas 5 1 2 10
b. DataFrame with example
i) Creating a DataFrame 5 marks
A Pandas DataFrame is a 2 dimensional data structure, like a 2
dimensional array, or a table with rows and columns.
Example
Create a simple Pandas DataFrame:
import pandas as pd
data = {
"calories": [420, 380, 390],
"duration": [50, 40, 45]
}
#load data into a DataFrame object:
df = pd.DataFrame(data)
print(df)
ii) Iterating over rows and columns 5 marks
Iteration is a general term for taking each item of something, one
after another. Pandas DataFrame consists of rows and columns so, in
order to iterate over dataframe, we have to iterate a dataframe like a
dictionary. In a dictionary, we iterate over the keys of the object in
the same way we have to iterate in dataframe.
In this article, we are using “nba.csv” file to download the CSV,
In Pandas Dataframe we can iterate an element in two ways:

Iterating over rows


Iterating over columns

You might also like