You are on page 1of 4

WCTB Group Assignment 2

Group 1

Roll Name of the Candidates


Number
MBA23249 NITHIN BABU K
MBA23240 GAURAV SINGH
MBA23228 BHASHYAM SREERAM CHARAN GOUD
MBA23235 DEPANGSHA
MBA23300 SAKSHI JAISWAL

1. Write a function Eval_Quadratic_Equa(a, b, c, x) which returns the value of any


quadratic equation of form ax2+bx+c

Eval_Quadratic_Equa<-function(a, b, c, x){
equation<-a*x*x+b*x+c
return(equation)
}
l<-as.numeric(readline("Enter coefficient of x square: "))
m<-as.numeric(readline("Enter coefficient of x: "))
n<-as.numeric(readline("Enter the constant of equation: "))
o<-as.numeric(readline("Enter the value of x: "))
value<-Eval_Quadratic_Equa(l,m,n,o)
print(paste("The value of equation will be",value))

2. Write a function calc_exp(base, exp) which computes the exponent of any number,
i.e., baseexp. The function should take two values as base, which can be float or
integer. Exp will be an integer greater than 0

calc_exp<-function(base, exp){
number<-base^exp
return(number)
}
b<-as.numeric(readline("Enter the base number: "))
e<-as.integer(readline("Enter the exponent: "))
baseexp<-calc_exp(b,e)
print(paste("The value of base raised to the given exponent will be",baseexp))

3. Write a function Calc_GCD_Recurr(a, b) which calculates the greater common


divisor(GCD) of two number. The function should take two positive integers and
should return one integer as GCD.

Calc_GCD_Recurr<-function(a, b){
if(a>b) {
for (i in b:1) {
if(a%%i==0 & b%%i==0) return(i) else if(a%%b==0) return(i)
i=i-1
WCTB Group Assignment 2
Group 1

}
}
if(b>a) {
for (i in a:1) {
if(a%%i==0 & b%%i==0) return(i) else if(b%%a==0) return(i)
i=i-1
}
}
}
x<-as.integer(readline("Enter the first positive integer: "))
y<-as.integer(readline("Enter the second positive integer distinct from first: "))
gcd<-Calc_GCD_Recurr(x,y)
print(paste("GCD of given two distinct positive intergers is",gcd))

4. Write a function reverse_number() to return the reverse of the number entered

reverse_number<-function(x){
temp<-0
while (x>0) {
dig<-x%%10
temp<-temp*10+dig
x<-x%/%10
}
return(temp)
}
n <- as.numeric(readline("Enter the number you want to be reversed: "))
rev<-reverse_number(n)
print(paste("The reversed number will be",rev))

5. A four-digit integer is entered through the keyword. Write a function to calculate the
sum of the four-digit number

num4<-as.numeric(readline("Enter a 4 digit number: "))

temp<-0
for (i in 1:4) {
temp=temp+(num4%%10)
num4=as.integer(num4/10)
i=i+1
}

print(paste("Sum of the given 4 digit number is: ",temp))

6. Write a program to define below functions. Perform the following operations on it


WCTB Group Assignment 2
Group 1

a) Define the function named get_radius() which returns the radius of the circle
b) Define the function named calc_area() which returns the area of circle

get_radius<-function(){
x<-as.numeric(readline("Enter the radius of the circle in cms: "))
return(x)
}
calc_area<-function(y){
a<-3.14*y^2
return(a)
}
radius<-get_radius()
area<-calc_area(radius)
print(paste("The area of the circle will be",area,"cm square"))

7. Create the given data frame

FName<-c("Tom","Krish","Nick","Juli")
LName<-c("Reacher","Pete","Wilson","Williams")
Age<-c(25,30,26,22)
people<-data.frame(FName,LName,Age)
row.names(people)<-c("0","1","2","3")
people

8. Create the given student data frame and do the required exercise
a) Calculate mean, median, maximum, minimum, and standard deviation of salary
b) Calculate mean, median, maximum, minimum, and standard deviation of age
c) Is there any correlation between age and salary?

ID<-
c("MBA21001","MBA21002","MBA21003","MBA21004","MBA21005","MBA21006")
Name<-c("Rohit","Meenal","Sneha","Mrigank","Naresh","Deepika")
Gender<-c("Male","Female","Female","Male","Male","Female")
Age<-c(24,25,22,23,25,23)
Family_Income<-c(120000,98000,112000,85000,92000,106000)
students<-data.frame(ID,Name,Gender,Age,Family_Income)
students

summary(students[5])
sd(students[,5])

summary(students[4])
sd(students[,4])
WCTB Group Assignment 2
Group 1

cor(students[4],students[5])

9. Draw line and bar diagram for the given data

Month<-c("January","February","March","April","May","June","July",
"August","September","October","November","December")
Sales<-c(50,30,20,15,17,55,40,25,20,60,35,40)

plot(1:12,y=Sales,type='b',main="Monthly Sales Data",


xlab="Months",ylab="Sales in Millions $",
col=c("red","blue","black","cyan"))
axis(side = 1,at=1:12,labels = Month)

barplot(names=Month,height = Sales,main="Monthly Sales Data",


xlab="Months",ylab="Sales in Millions $",
col=c("red","blue","black","cyan"))

10. Draw a pie chart to visualize the placement statistics on given placement data

Industry<-c("IT","Sales and Marketing","Finance and Banking",


"Manufacturing","others")
Placement<-c(55,88,39,24,63)
piepercent<-round(100*Placement/sum(Placement),1)
pie(x=Placement,labels = piepercent,main = "Domains",
col =c("red","green","cyan","yellow","blue"),radius = 1)
legend("topright",Industry,cex = 0.5,
fill = c("red","green","cyan","yellow","blue"))

You might also like