Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

SYBBA (CA) Sem-IV Practical Slip-1

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 79

Soham Phansalkar

SLIP 1
Q.1

a)

#include<iostream.h>

inline int max(int a,int b)

return ((a>b) ? a:b);

inline int min(int a,int b)

return ((a<b) ? a:b);

int main()

int a,b;

cout<<”Enter 2 numbers”<<endl;

cout<<”Number 1:”;

cin>>a;

cout<<”Number 2:”;

cin>>b;

cout<<”The maximum number is:”<<max(a,b)<<endl;

cout<<”The minimum number is:”<<min(a,b)<<endl;

return 0;

b)

Q.2

a)

const readline=require(‘readline’);

const rl=readline.createInterface({
input:process.stdin,

output:process.stdout

});

rl.question(‘Enter a string:’,(inputString) =>

const upperCaseString=inputString.toUpperCase();

console.log(‘Uppercase Output:’,upperCaseString);

rl.close();

});

b)

slip1db.js

let mysql=require("mysql");

let con=mysql.createConnection({

host: "localhost",

user: "root",

password: "12345",

port: "3306",

});

con.connect(function(err){

if (err) {

console.log(err);

} else {

console.log("connected");

});

con.query("CREATE DATABASE studentdb",function(err,result){

if(err) throw err;

console.log("Database Created");

});

slip1table.js

let mysql=require("mysql");
let con=mysql.createConnection({

host: "localhost",

user: "root",

password: "12345",

port: "3306",

database: “studentdb”

});

con.connect(function(err){

if (err) {

console.log(err);

} else {

console.log("connected");

});

var sql=”CREATE TABLE student(rollno int, name varchar(30), percentage double)”;

con.query(sql,function(err,result){

if(err) throw err;

console.log(“Table Created”);

});

SLIP 2
Q.1

a)

#include<iostream.h>

float volume(float r, float h){

return (3.14*r*2*h);

float coneVol(float r, float h){

return (3.14*2*h/3);

float volume(float r){

return (4/3*3.14*r*r*r);

}
int main()

float cy_h,cy_r,co_h,co_r,sp_r;

cout<<”Enter dimensions”<<endl;

cout<<”1.Cyclinder”<<endl;

cout<<”Height:”;

cin>>cy_h;

cout<<”Radius:”;

cin>>cy_r;

cout<<endl;

cout<<”2.Cone”<<endl;

cout<<”Height:”;

cin>>co_h;

cout<<”Radius:”;

cin>>co_r;

cout<<endl;

cout<<”3.Sphere”<<endl;

cout<<”Radius:”;

cin>>sp_r;

cout<<endl;

cout<<”The volume of Cyclinder is:”<<volume(cy_h, cy_r)<<endl;

cout<<”The volume of Cone is:”<<coneVol(co_h, co_r)<<endl;

cout<<”The volume of Sphere is:”<<volume(sp_r)<<endl;

return 0;

b)

Q.2

a)

fact.js

var fact={

factorial:function(n){
var f=1,i;

for(i=0;i<=n;i++){

f=f*i;

console.log(‘factorial of’ +n+ ‘is:’ +f);

module.exports=fact;

app.js

var mymod=require(‘fact.js’);

mymod.factorial(5);

b)

validate.js

function Dob(dob){

const dobDate=new Date(dob);

return dobDate.getTime()?dobDate:null;

function Jdate(jdate){

const joinDate=new Date(jdate);

return joinDate.getTime()?joinDate:null;

function Salary(salary){

return salary>0;

module.exports={Dob,Jdate,Salary};

slip2.js

const http=require('http');

const qs=require('querystring');

const {Dob,Jdate,Salary}=require('./validate');
const server=http.createServer((req,res)=>

if(req.method=='GET'&&req.url=='/register')

res.writeHead(200,{'Content-Type':'text/html'});

res.end(`

<form method="post" action="/register">

Name:

<input type="text" id="name" name="name"><br>

Email:

<input type="email" id="email" name="email"><br>

Department:

<input type="text" id="department" name="department"><br>

Date Of Birth:

<input type="date" id="bdate" name="bdate"><br>

Joining Date:

<input type="date" id="jdate" name="jdate"><br>

Salary:

<input type="number" id="salary" name="salary"><br>

<button type="submit">Register</button>

</form>

`);

else if(req.method=='POST'&&req.url=='/register')

let body='';

req.on('data',(data)=>

body=body+data;

});

req.on('end',()=>

const formData=qs.parse(body);
const name=formData.name;

const email=formData.email;

const department=formData.department;

const dob=formData.bdate;

const jdate=formData.jdate;

const salary=formData.salary;

if(!Dob(dob))

res.end('Invalid Date of Birth');

return;

if(!Jdate(jdate))

res.end('Invalid Joining Date');

return;

if(!Salary(salary))

res.end('Invalid Salary');

return;

console.log(`Employee Registered:

Name: ${name}

Email: ${email}

Department: ${department}

Date of Birth: ${dob}

Joining Date: ${jdate}

Salary: ${salary}`);

res.end('Employee registered successfully');

});

else

{
res.writeHead(404,{ 'Content-Type':'text/plain'});

res.end('Not Found');

}).listen(3030);

console.log("Successfully Run.");

SLIP 3
Q.1

a)

#include<iostream.h>

void swap(int &a, int &b){

int temp;

temp=a;

a=b;

b=temp;

int main(){

int a,b;

cout<<”Enter two numbers”<<endl;

cout<<”Enter first number:”;

cin>>a;

cout<<”Enter second number:”;

cin>>b;

cout<<endl<<”Original Numbers”<<endl<<”a=”<<a<<”&b=”<<b<<endl;

swap(a,b);

cout<<endl<<”After swap numbers”<<endl<<”a=”<<a<<”&b=”<<b<<endl;

return 0;

b)
Q.2

a)

circle.js

const PIE=3.14;

function area(r){

return PIE*r*r;

};

function circum(r){

return 2*PIE*r;

};

module.exports={area,circum};

app.js

let app=require("./circle");

const readline=require('readline');

const rl=readline.createInterface({

input:process.stdin,

output:process.stdout

});

rl.question('Enter a radius:',(r)=>{

console.log("Area of circle is:",app.area(r));

console.log("Circumference of circle is:",app.circum(r));

});

b)

validate1.js

function Name(name)

return name.match(/^[A-Za-z]+$/)!=null;

function Email(email)

return email.includes('@')&&email.includes('.');
}

function Dob(dob)

const dobDate=new Date(dob);

return dobDate.getTime()?dobDate:null;

module.exports={Name,Email,Dob};

slip3.js

const http=require('http');

const qs=require('querystring');

const {Name,Email,Dob}=require('./validate1');

http.createServer((req,res)=>

if(req.method=='GET'&&req.url=='/register')

res.writeHead(200,{'Content-Type':'text/html'});

res.end(`

<form method="post" action="/register">

Name:

<input type="text" id="name" name="name"><br>

Email:

<input type="text" id="email" name="email"><br>

Date Of Birth:

<input type="date" id="bdate" name="bdate"><br>

Age:

<input type="number" id="age" name="age"><br>

Address:

<input type="text" id="add" name="add"><br>

<button type="submit">Register</button>

</form>

`);

else if(req.method=='POST'&&req.url=='/register')
{

let body='';

req.on('data',(data)=>

body=body+data;

});

req.on('end',()=>

const Data=qs.parse(body);

const name=Data.name;

const email=Data.email;

const dob=Data.bdate;

const age=Data.age;

const add=Data.add;

if(!Name(name))

res.end('Enter Name Field Proper!');

return;

if(!Dob(dob))

res.end('Invalid Date of Birth');

return;

if(!Email(email))

res.end('Invalid Email Id!');

return;

console.log(`Student Registered:

Name:${name}

Email:${email}

Date of Birth:${dob}
Age:${age}

Address:${add}

`);

res.end('Student registered successfully');

});

else

res.writeHead(404,{'Content-Type':'text/plain'});

res.end('Not Found');

}).listen(3032);

console.log("Successfully Run.");

SLIP 4
Q.1

a)

#include<iostream.h>

class workerInfo{

char wname[50];

int no_of_hours_worked,salary;

public:

void accept(){

cout<<”Enter name of the worker:”;

cin>>wname;

cout<<”Enter number of hours worked:”;

cin>>no_of_hours_worked;

void display(){

cout<<”Worker details”<<endl;

cout<<”Name:”<<wname<<endl;

cout<<”Salary:”<<calSal(no_of_hours_worked)<<endl;

}
int calSal(int work_hrs, int pay_rate=100){

return (work_hrs*pay_rate);

};

int main(){

workerInfo w;

w.accept();

w.display();

return 0;

b)

Q.2

a)

name.js

function flname(first,last){

return first+" "+last;

function age(dob){

const bdate=new Date(dob);

const current=new Date();

let age=current.getFullYear()-bdate.getFullYear();

if(current<bdate){

age--;

return age;

module.exports={flname,age};

slip4.js

let app=require("./name");
const readline=require('readline');

const rl=readline.createInterface({

input:process.stdin,

output:process.stdout

});

rl.question('Enter First Name:',(fname)=>{

rl.question('Enter Last Name:',(lname)=>{

rl.question('Enter Date of Birth:',(bdate)=>{

console.log("Your Name is",app.flname(fname,lname));

console.log("Age of person is",app.age(bdate));

});

});

});

b)

SLIP 5
Q.1

a)

#include<iostream.h>

class point{

int x,y;

public:

void setpoint(int a, int b){

x=a;

y=b;

void showpoint(){

cout<<”(”<<x<<”,”<<y<<”)”;

};

int main(){

int a,b;
point p;

cout<<”Enter coordinates”<<endl;

cout<<”Enter x:”;

cin>>a;

cout<<”Enter y:”;

cin>>b;

p.setpoint(a,b);

p.showpoint();

return 0;

b)

#include<iostream.h>

const double PI=3.14;

class Shape

public:

virtual double area() const=0;

};

class Circle:public Shape

private:

double radius;

public:

Circle(double r):radius(r){}

double area() const

return PI*radius*radius;

};

class Sphere:public Shape

private:
double radius;

public:

Sphere(double r):radius(r){}

double area() const

return 4*PI*radius*radius;

};

class Cylinder:public Shape

private:

double radius;

double height;

public:

Cylinder(double r,double h):radius(r),height(h){}

double area() const

return 2*PI*radius*(radius+height);

};

int main()

Circle c1(5);

Sphere s1(3);

Cylinder cy1(4,6);

cout<<”Area of Circle:”<<c1.area()<<endl;

cout<<”Area of Sphere:”<<s1.area()<<endl;

cout<<”Area of Cylinder:”<<cy1.area()<<endl;

return 0;

Q.2
a)
const buf1=Buffer.from('Hello ');

const buf2=Buffer.from('Nashik');

const concat=Buffer.concat([buf1, buf2]);

console.log('Concatenated Buffer:',concat.toString());

const compare=buf1.compare(buf2);

console.log('Comparison Buffer:',compare);

const copy=Buffer.from(buf2);

console.log('Copied Buffer:',copy.toString());

b)

let mysql=require(‘mysql’);

let con=mysql.createConnection({

host: “localhost”,

user: “root”,

password: “12345”,

port: “3306”,

database: “college”

});

con.connection((err) => {

if(err){

console.log(err);

}else{

console.log(“Connected Successfully”);

});

con.query(“SELECT * FROM CUSTOMER”, (err,rs) => {

if(err){

console.log(err);

}else{

console.log(“CID NAME”);

console.log(“--------------------”);

Object.keys(rs).forEach((ft) => {
console.log(rs[ft].cid, “|”, rs[ft].cname);

});

});

con.query (“DELETE FROM customer WHERE cid=1”, (err,result) =>{

if(err){

console.log(err);

}else{

console.log(result.affectedRows,” rows deleted”);

});

con.end();

SLIP 6
Q.1

a)

#include<iostream.h>

class square{

public:

int s;

void getdata(){

cout<<”Enter the side of the square:”;

cin>>s;

int calArea(){

return (s*s);

friend void compare(int s, int r);

};

class rectangle{

public:

int l,w;

void getdata(){
cout<<”Enter the length of the rectangle:”;

cin>>l;

cout<<”Enter the width of the rectangle:”;

cin>>w;

int calArea(){

return (l*w);

friend void compare(int s, int r);

};

void compare(int s, int r){


if(s > r){

cout<<”The area of square is bigger than area of rectangle.”<<endl;

}else{

cout<<”The area of rectangle is bigger than area of square.”<<endl;

int main(){

int s_area,r_area;

square s1;

rectangle r1;

s1.getdata();

s_area=s1.calArea();

r1.getdata();

r_area=r1.calArea();

cout<<”Square:”<<s_area<<endl;

cout<<”Rectangle:”<<r_area<<endl;

compare(s_area, r_area);

return 0;

b)

#include<iostream.h>
class Matrix

private:

int **p;

int r,c;

public:

Matrix(int rows,int cols):r(rows),c(cols)

p=new int*[r];

for(int i=0;i<r;i++)

p[i]=new int[c];

~Matrix()

for(int i=0;i<r;i++)

delete[] p[i];

delete[] p;

void acceptElements()

cout<<”Enter matrix elements:”<<endl;

for(int i=0;i<r;i++)

for(j=0;j<c;j++)

cout<<”Enter element at position (“<<i+1<<”,”<<j+1<<”):”;

cin>>p[i][j];

}
}

void displayElements() const

cout<<”Matrix elements:”<<endl;

for(int i=0;i<r;i++)

for(int j=0;j<c;j++)

cout<<p[i][j]<<””;

cout<<endl;

Matrix transpose() const

Matrix transposed(c,r);

for(int i=0;i<r;i++)

for(int j=0;j<c;j++)

transposed.p[j][i]=p[i][j];

return transposed;

};

int main()

int rows, cols;

cout<<”Enter number of rows of the matrix:”;

cin>>rows;

cout<<”Enter number of columns of the matrix:”;

cin>>cols;
Matrix mat(rows,cols);

mat.acceptElements();

cout<<”Original matrix:”<<endl;

mat.displayElements();

Matrix transposed=mat.transpose();

cout<<”Transpose of the matrix:”<<endl;

transposed.displayElements();

return 0;

Q.2

a)

demo_server.js

var http=require(‘http’);

var url=require(‘url’);

var fs=require(‘fs’);

http.createServer(function(req,res) {

var q=url.parse(req.url,true);

var filename=”sample.txt”+q.pathname;

fs.readFile(filename,function(err,data){

if(err){
res.writeHead(404,{‘Content-Type’:’text/html’});

return res.end(“404 not found”);

res.writeHead(200,{‘Content-Type’:’text/html’});

res.write(data);

return res.end();

});

}).listen(8080);

b)

let mysql=require(‘mysql’);
let con=mysql.createConnection({

host: “localhost”,

user: “root”,

password: “12345”,

database: “college”,

port: “3306”

});

con.connect((err) => {

if(err){

console.log(err);

}else{

console.log(“Connected”);

}):

let sql=”(14,’Soham’,’SYBBA(CA)’),(15,’Sujal’,’SYBBA(CA)’),(16,’Aditya’,’SYBBA(CA)’)”;

con.query(“INSERT INTO student(id,name,class) VALUES” + sql, (err,result) => {

if(err){

console.log(err);

}else{

console.log(result.affectedRows, “rows inserted”);

console.log(“Warning count”,result.serverStatus);

console.log(“Messages:”,result.message);

});

con.end();

SLIP 7
Q.1

a)

#include<iostream.h>

#include<string.h>

class String

{
private:

char str[50];

public:

String(const char* input)

strncpy(str,input,49);

str[49]=’\0’;

int replace(char ch1,char ch2=’*’)

int count=0;

for(size_t i=0;i<strlen(str);i++)

if(str[i]==ch1)

str[i]==ch2;

count++;

return count;

const char* getString()

return str;

};

int main()

String s1(“Hello,World!”);

cout<<”Original string:”<<s1.getString()<<endl;

int replacements=s1.replace(‘o’);

cout<<”Modified string:”<<s1.getString()<<endl;

cout<<”Number of replacements:”<<replacements<<endl;
return 0;

b)

#include<iostream.h>

class Vector

private:

int size;

int* ptr;

public:

Vector(int s): size(s), ptr(new int[s]) {}

Vector(const Vector& other): size(other.size), ptr(new int[other.size])

for(int i=0;i<size;i++)

ptr[i]=other.ptr[i];

~Vector()

delete[] ptr;

void acceptVector()

cout<<”Enter”<<size<<”elements for the vector:”;

for(int i=0;i<size;i++)

cin>>ptr[i];

void displayVector()

{
cout<<”(“;

for(int i=0;i<size;i++)

cout<<ptr[i];

if(i<size-1)

cout<<”,”;

cout<<”)\n”;

Vector calculateUnion(const Vector& other)

int newSize=size+other.size;

Vector result(newSize);

int index=0;

for(int i=0;i<size;i++)

result.ptr[index++]=ptr[i];

for(i=0;i<other.size;i++)

result.ptr[index++]=other.ptr[i];

return result;

};

int main()

Vector vec1(3);

Vector vec2(2);

cout<<”Enter elements for vector 1:\n”;

vec1.acceptVector();
cout<<”Enter elements for vector 2:\n”;

vec2.acceptVector();

cout<<”Vector 1:”;

vec1.displayVector();

cout<<”Vector 2:”;

vec2.displayVector();

Vector unionVector=vec1.calculateUnion(vec2);

cout<<”Union of Vector 1 and Vector 2:”;

unionVector.displayVector();

return 0;

Q.2

a)

var fs=require(‘fs’);

fs.appendFile(‘f1.txt’,’f2.txt’,function(err){

if(err) throw err;

console.log(‘Updated’);

});

f1.txt

“Welcome to SY

f2.txt

BBA(CA) Department”

b)

let mysql=require(‘mysql’);

let con=mysql.createConnection({

host: “localhost”,

user: “root”,

password: “12345”,

database: “college”

});

con.connect((err) => {
if(err) throw err;

console.log(“Connected”);

});

con.query(“SELECT * FROM customer”,(err,result) => {

if(err){

console.log(err);

}else{

console.log(result);

});

con.end();

SLIP 9
Q.1

a)

#include<iostream.h>

#include<conio.h>

class person{

char name[20];

char addr[20];

float sal,tax;

public:

void get(){

cout<<”\nEnter the name, address, salary:\n”;

cin>>name>>addr>>sal;

void put(){

cout<<”Person Information:\n”;

cout<<”Name\tAddress\tSalary\tTax:\n”;

cout<<”=================================\n”;

cout<<name<<”\t”<<addr<<”\t”<<sal<<”\t”<<tax<<endl;

}
void cal_tax(){

if(sal<=20000){

tax=0;

}else if(sal>=20000||sal<=40000){

tax=(sal*5)/100;

}else{

tax=(sal*10)/100;

};

void main(){

person p;

clrscr();

p.get();

p.cal_tax();

p.put();

getch();

b)

#include<iostream.h>

#include<iomanip.h>

class Time

private:

int hours;

int minutes;

int seconds;

public:

Time(int h=0, int m=0, int s=0): hours(h), minutes(m), seconds(s) {}

void acceptTime()

cout<<”Enter hours:”;
cin>>hours;

cout<<”Enter minutes:”;

cin>>minutes;

cout<<”Enter seconds:”;

cin>>seconds;

void displayTime()

cout<<setw(2)<<setfill(‘0’)<<hours<<”:”<<setw(2)<<setfill(‘0’)<<minutes<<”:”<<setw(2)<<setfill(‘0’)<<seconds<
<endl;

void difference(const Time& t1, const Time& t2)

int totalseconds1=t1.hours*3600+t1.minutes*60+t1.seconds;

int totalseconds2=t2.hours*3600+t2.minutes*60+t2.seconds;

int diffSeconds=totalSeconds2-totalSeconds1;

int diffHours=diffSeconds/3600;

diffSeconds %=3600;

int diffMinutes=diffSeconds/60;

diffSeconds %=60;

cout<<”Difference:”<<setw(2)<<setfill(‘0’)<<diffHours<<”:”<<setw(2)<<setfill(‘0’)<<diffMinutes<<”:”<<setw(2)<
<setfill(‘0’)<<diffSeconds<<endl;

};

int main()

Time time1, time2;

cout<<”Enter time 1:\n”;

time1.acceptTime();

cout<<”Enter time 2:\n”;

time2.acceptTime();
cout<<”Time 1:”;

time1.displayTime();

cout<<”Time 2:”;

time2.displayTime();

time1.difference(time1, time2);

return 0;

Q.2

a)

var http=require(‘http’);

http.createServer(function(req,res){

res.writeHead(200,{‘Content-Type’:’text/html’});

res.write(‘<form action=”fileupload” method=”post” enctype=”multipart/form-data”>’);

res.write(‘<input type=”file” name=”filetoupload”><br>’);

res.write(‘<input type=”submit”>’);

res.write(‘</form>’);

return res.end();

}).listen(3000);

b)

SLIP 10
Q.1

a)

#include<iostream.h>

class Account

private:

int Acc_number;

char Acc_type;

double Balance;

public:
void acceptDetails()

cout<<”Enter Account Number:”;

cin>>Acc_number;

cout<<”Enter Account Type (Savings ‘S’ or Checking ‘C’):”;

cin>>Acc_type;

cout<<”Enter Balance:”;

cin>>Balance;

void displayDetails()

cout<<”Account Number:”<<Acc_number<<endl;

cout<<”Account Type:”<<Acc_type<<endl;

cout<<”Balance:”<<Balance<<endl;

};

int main()

int n;

cout<<”Enter the number of accounts:”;

cin>>n;

Account* accounts=new Account[n];

for(int i=o;i<n;i++)

cout<<”Enter details for Account”<<i+1<<”:”<<endl;

accounts[i].acceptDetails();

cout<<”\nDisplaying Account Details:\n”;

for(i=0;i<n;i++)

cout<<”Details for Account”<<i+1<<”:”<<endl;

accounts[i].displayDetails();

cout<<endl;
}

delete[] accounts;

return 0;

b)

Q.2

a)

const http=require(‘http’);

const fs=require(‘fs’);

const path=require(‘path’);

const server=http.createServer((req,res) => {

if(req.url===’/download’){

const filePath=path.join(__dirname,’image.jpg’);

const stat=fs.statSync(filePath);

res.writeHead(200,{‘Content-Type’:’image/jpeg’,’Content-Length’:stat.size,’Content-
Disposition’:’attachment;filename=image.jpg’});

const readStream=fs.createReadStream(filePath);

readStream.pipe(res);

}else{

res.writeHead(404,{‘Content-Type’:’text/html’});

res.end(‘404 not found’);

});

const PORT=process.env.PORT||3000;

server.listen(PORT, () => {

console.log(`Server is running on port ${PORT}`);

});

b)
SLIP 11
Q.1

a)

#include<iostream.h>

class MyArray{

private:

int* arr;

int size;

public:

MyArray(int s){

size=s;

arr=new int[size];

~MyArray(){

delete[] arr;

void acceptElements(){

cout<<”Enter”<<size<<”array elements:”<<endl;

for(int i=0;i<size;i++){

cin>>arr[i];

void displayElements(){

cout<<”Array elements:”;

for(int i=0;i<size;i++){

cout<<arr[i]<<” “;

cout<<endl;

void displaySum(){

int sum=0;

for(int i=0;i<size;i++){

sum+=arr[i];
}

cout<<”Sum of array elements:”<<sum<<endl;

};

int main(){

int size;

cout<<”Enter the size of the array:”;

cin>>size;

MyArray myArray(size);

myArray.acceptElements();

myArray.displayElements();

myArray.displaySum();

return 0;

b)

#include<iostream.h>

class Student

protected:

int Roll_No;

char Name[50];

public:

void acceptInfo()

cout<<”Enter Roll No:”;

cin>>Roll_No;

cout<<”Enter Name:”;

cin>>Name;

void displayInfo()

cout<<”Roll No:”<<Roll_No<<endl;
cout<<”Name:”<<Name<<endl;

};

class Theory: virtual public Student

protected:

int M1,M2,M3,M4;

public:

void acceptTheoryMarks()

cout<<”Enter theory marks (M1,M2,M3,M4):”;

cin>>M1>>M2>>M3>>M4;

class Practical: virtual public Student

protected:

int P1,P2,;

public:

void acceptPracticalMarks()

cout<<”Enter practical marks (P1,P2):”;

cin>>P1>>P2;

class Result: public Theory, public Practical

private:

int Total_Marks;

float Percentage;

char Grade;

public:

void calculateResult()
{

Total_Marks=M1+M2+M3+M4+P1+P2;

Percentage=(Total_Marks)/6;

if(Percentage >= 90){

Grade=’A’;

}else if(Percentage >=80){

Grade=’B’;

}else if(Percentage >=70){

Grade=’C’;

}else if(Percentage >=60){

Grade=’D’;

}else{

Grade=’F’;

void displayResult()

cout<<”Total Marks:”<<Total_Marks<<endl;

cout<<”Percentage:”<<Percentage<<”%”<<endl;

cout<<”Grade:”<<Grade<<endl;

};

int main()

Result r1;

int choice;

do{

cout<<”\nMenu:\n”;

cout<<”1.Accept Student Information:\n”;

cout<<”2.Display Student Information:\n”;

cout<<”3.Calculate Result:\n”;

cout<<”4.Exit:\n”;

cout<<”Enter your choice:”;


cin>>choice;

switch(choice){

case 1:r1.acceptInfo();

r1.acceptTheoryMarks();

r1.acceptPracticalMarks();

break;

case 2:r1.displayInfo();

break;

case 3:r1.calculateResult();

r1.displayResult();

break;

case 4:cout<<”Exiting program…\n”;

break;

default:cout<<”Invalid choice! Please enter a valid option.\n”;

}while(choice!=4);

return 0;

Q.2

a)

const http=require(‘http’);

const collegeInfo={

name: “RNC Arts, JDB Commerce & NSC Science College”,

address: “Nashik Road,Nashik”,

phone: “0253-5454666”,

website: http://www.example.com

};

const server=http.createServer((req,res) {

res.writeHead(200,{‘Content-Type’:’text/html’});

res.write(‘<h1>College Information</h1>’);

res.write(‘<p><strong>Name:</strong>’+collegeInfo.name+’</p>’);

res.write(‘<p><strong>Address:</strong>’+collegeInfo.address+’</p>’);
res.write(‘<p><strong>Phone:</strong>’+collegeInfo.phone+’</p>’);

res.write(‘<p><strong>Website:</strong> <a
href=”’+collegeInfo.website+’”>’+collegeInfo.website+’</a></p>’);

res.end();

});

const port=3100;

server.listen(port, () => {

console.log(`Server is running on port ${port}`);

});

b)

const express=require('express');

const app=express();

app.get('/',(req,res)=>

res.send(`

<h1>Welcome to the Computer Science Department Portal</h1>

<ul>

<li><a href="/Courses">Courses</a></li>

<li><a href="/Faculty">Faculty</a></li>

<li><a href="/Contact">Contact</a></li>

</ul>

`);

});

app.get('/Courses',(req,res)=>

res.send(`<h2>Computer Science Courses</h2>

<ul>

<li>Advanced ML Techniques</li>

<li>Data Mining</li>

<li>AI Basics</li>

</ul>`

);
});

app.get('/Faculty',(req, res)=>

res.send(`<h2>Computer Science Faculty Members</h2>

<h1>Member 1</h1>

<ul>

<li>Name:Sujal Vora</li>

<li>Designation:Professor</li>

<li>Specialization:Machine Learning</li>

</ul>

<h1>Member 2</h1>

<ul>

<li>Name:Soham Phansalkar</li>

<li>Designation:Associate Professor</li>

<li>Specialization:Data Science</li>

</ul>

<h1>Member 3</h1>

<ul>

<li>Name:Aadityakumar Singh</li>

<li>Designation:Assistant Professor</li>

<li>Specialization:Artificial Intelligence</li>

</ul>`

);

});

app.get('/Contact',(req,res)=>

res.send(`

<h2>Contact Us</h2>

<ul>

<li>Phone:997812xxxx</li>

<li>Email:sujalvora17@gmail.com</li>

<li>Address:Nashik</li>

</ul>
<ul>

<li>Phone:908923xxxx</li>

<li>Email:sohamphansalkar11@gmail.com</li>

<li>Address:Nashik</li>

</ul>

<ul>

<li>Phone:897182xxxx</li>

<li>Email:adityakumarsingh9@gmail.com</li>

<li>Address:Nashik</li>

</ul>

`);

});

app.listen(3000);

console.log("Successfully Run!");

SLIP 12
Q.1

a)

#include<iostream.h>

class Date

private:

int day;

int month;

int year;

public:

Date()

day=1;

month=1;

year=2000;

Date(int d,int m,int y)


{

day=d;

month=m;

year=y;

void displayDate()

const char*
months[]={“Jan”,”Feb”,”Mar”,”Apr”,”May”,”Jun”,”Jul”,”Sep”,”Oct”,”Nov”,”Dec”};

cout<<day<<”-“<<months[month-1]<<”-“<<year<<endl;

};

int main()

Date defaultDate;

cout<<”Default Date:”;

defaultDate.displayDate();

Date customDate(4,1,2021);

cout<<”Custom Date:”;

customDate.displayDate();

return 0;

b)

Q.2

a)

const EventEmitter=require(‘events’);

const myEmitter=new EventEmitter();

const listener1= () => {

console.log(‘Listener 1 executed’);

};

const listener2= () => {


console.log(‘Listener 2 executed’);

};

myEmitter.on(‘myEvent’, listener1);

myEmitter.on(‘myEvent’, listener2);

myEmitter.emit(‘myEvent’);

b)

validate5.js

function Username(name) {

return name.match(/^[A-Za-z]+$/)!=null;

function Dob(dob) {

const dobDate=new Date(dob);

return dobDate.getTime()?dobDate:null;

function Email(email) {

return email.includes(‘@’)&&email.includes(‘.’);

function Mobile(mno) {

return mno.match(/^d{10}$/);

module.exports={Username,Dob,Email,Mobile};

slip12.js

const http=require('http');

const qs=require('querystring');

const {Username,Dob,Email,Mobile}=require('./validate5');

http.createServer((req,res)=>

if(req.method=='GET'&&req.url=='/register')

res.writeHead(200,{'Content-Type':'text/html'});

res.end(`
<form method="post" action="/register">

<h2>User Login System</h2>

Username:

<input type="text" id="name" name="name"><br>

Password:

<input type="text" id="pass" name="pass"><br>

Email:

<input type="text" id="email" name="email"><br>

Mobile Number:

<input type="number" id="mno" name="mno"><br>

Date Of Birth:

<input type="date" id="bdate" name="bdate"><br>

Age:

<input type="number" id="age" name="age"><br>

Address:

<input type="text" id="add" name="add"><br>

<button type="submit">Log In</button>

</form>

`);

else if(req.method=='POST'&&req.url=='/register')

let body='';

req.on('data',(data)=>

body=body+data;

});

req.on('end',()=>

const Data=qs.parse(body);

const name=Data.name;

const pass=Data.pass;

const email=Data.email;
const mno=Data.mno;

const dob=Data.bdate;

const age=Data.age;

const add=Data.add;

if(!Username(name))

res.end('Enter Name Field Proper!');

return;

if(!Dob(dob))

res.end('Invalid Date of Birth');

return;

if(!Email(email))

res.end('Invalid Email Id!');

return;

if(!Mobile(mno))

res.end('Mobile Number Contains 10 Digits Only!');

console.log(`User Registered:

Username:${name}

Password:${pass}

Email:${email}

Mobile Number:${mno}

Date of Birth:${dob}

Age:${age}

Address:${add}

`);

res.end('User registered successfully');


});

else

res.writeHead(404,{'Content-Type':'text/plain'});

res.end('Not Found');

}).listen(3080);

console.log("Successfully Run.");

SLIP 13
Q.1

a)

#include<iostream.h>

#include<string.h>

class Product

private:

static int numObjects;

int Product_id;

char Product_Name[50];

int Qty;

double Price;

public:

Product()

Product_id=0;

Qty=0;

Price=0.0;

numObjects++;

Product(int id,const char* name,int qty,double price)

{
Product_id=id;

Qty=qty;

Price=price;

strcpy(Product_Name,name);

numObjects++;

~Product()

numObjects--;

static void displayNumObjects()

cout<<”Number of objects created:”<<numObjects<<endl;

void acceptProductInfo()

cout<<”Enter Product ID:”;

cin>>Product_id;

cout<<”Enter Product Name:”;

cin>>Product_Name;

cout<<”Enter Quantity:”;

cin>>Qty;

cout<<”Enter Price:”;

cin>>Price;

void displayProductInfo()

cout<<”Product ID:”<<Product_id<<endl;

cout<<”Product Name:”<<Product_Name<<endl;

cout<<”Quantity:”<<Qty<<endl;

cout<<”Price:”<<Price<<endl;

};
int Product::numObjects=0;

int main()

Product::displayNumObjects();

Product p1(1,”Laptop”,5,800.0);

cout<<”\nProduct 1 Info:”<<endl;

p1.displayProductInfo();

Product:: displayNumObjects();

Product p2;

cout<<”\nProduct 2 Info:”<<endl;

p2.acceptProductInfo();

p2.displayProductInfo();

Product:: displayNumObjects();

return 0;

b)

#include<iostream.h>

class Cuboid

private:

float length;

float breadth;

float height;

public:

void setvalues(float l,float b,float h)

length=l;

breadth=b;

height=h;

void getvalues()

{
cout<<”Length:”<<length<<endl;

cout<<”Breadth:”<<breadth<<endl;

cout<<”Height:”<<height<<endl;

float volume()

return length*breadth*height;

float surfaceArea()

return 2*(length*breadth+breadth*height+height*length);

};

int main()

Cuboid c;

c.setvalues(5.0,3.0,2.0);

cout<<”Cuboid dimensions:”<<endl;

c.getvalues();

cout<<”Volume:”<<c.volume()<<endl;

cout<<”Surface Area:”<<c.surfaceArea<<endl;

return 0;

Q.2

a)

rectangle.js

class Rectangle{

constructor(length, width){

this.length=length;

this.width=width;

calculateArea(){
return this.length * this.width;

};

module exports=rectangle;

app.js

const Rectangle=require(‘./rectangle’);

const rectangle=new Rectangle(5,2);

const area=rectangle.calculateArea();

console.log(‘Rectangle Details:’);

console.log(‘Length:’,rectangle.length);

console.log(‘Width:’,rectangle.width);

console.log(‘Area:’,area);

b)

let mysql=require(‘mysql’);

let con=mysql.createConnection({

host: “localhost”,

user: “root”,

password: “12345”,

database: “college”,

port: “3306”,

});

con.connect((err) => {

if(err) throw err;

console.log(“Connected”);

});

con.query(“UPDATE student SET marks=99 WHERE id=13”, (err,result) => {

if(err){

console.log(err);

}else{

console.log(“No of rows change/affected:”,result.changeRows);

console.log(“Messages:”,result.message);

}
});

con.end();

SLIP 14
Q.1

a)

#include<iostream.h>

using namespace std;

class Circle{

private:

float radius;

public:

void setRadius(float r){

radius=r;

inline float diameter(){

return 2 * radius;

inline float circumference(){

return 2 * 3.14 * radius;

inline float area(){

return 3.14 * radius * radius;

};

int main();

Circle c2;

float radius;

cout<<”Enter the radius of the circle:”;

cin>>radius;

c2.setRadius(radius);

cout<<”Diameter of the circle:”<<c2.diameter()<<endl;

cout<<”Circumference of the circle:”<<c2.circumference()<<endl;


cout<<”Area of the circle:”<<c2.area()<<endl;

return 0;

b)

Q.2

a)

var fs=require('fs');

function searchWordInFile(filePath,word){

fs.readFile(filePath,'utf8',(err,data)=>{

if(err){

console.error('Error reading file:',err);

return;

const regex=new RegExp('\\b'+word+'\\b','gi');

const matches=data.match(regex);

if(matches){

console.log(`Word "${word}" found ${matches.length} times in the file.`);

}else{

console.log(`Word "${word}" not found in the file.`);

});

const filePath='sample.txt';

const wordToSearch='Good';

searchWordInFile(filePath,wordToSearch);

b)

b5.js

function Bill(units)

const rate=0.50;
const Amt=units*rate;

return Amt;

module.exports={Bill};

slip14b.js

let app=require("./b5");

let prompt=require("prompt-sync")();

let unit=prompt("Enter Unit:");

console.log("Electricity Bill:",app.Bill(unit));

SLIP 16
Q.1

a)

b)

#include<iostream.h>

using namespace std;

class Matrix{

private:

int rows;

int cols;

int** data;

public:

Matrix(int r, int c) : rows(r), cols(c) {

data=new int*[rows];

for(int i=0;i<rows;i++){

data[i]=new int[cols];

~Matrix(){

for(int i=0;i<rows;i++){

delete[] data[i];

}
delete[] data;

void acceptMatrix(){

cout<<”Enter the elements of the matrix:”<<endl;

for(int i=0;i<rows;i++){

for(int j=0;j<cols;j++){

cin>>data[i][j];

void displayMatrix() const{

cout<<”Matrix:”<<endl;

for(int i=0;i<rows;i++){

for(j=0;j<cols;j++){

cout<<data[i][j];

cout<<endl;

Matrix operator-() const {

Matrix transpose(cols, rows);

for(int i=0;i<cols;i++){

for(int j=0;j<rows;j++){

transpose.data[i][j];

return tanspose;

Matrix& operator++(){

for(int i=0;i<rows;i++){

for(j=0;j<cols;j++){

++data[i][j];

}
}

return *this;

};

int main(){

int rows,cols;

cout<<”Enter the number of rows and columns of the matrix:”;

cin>>rows>>cols;

Matrix matrix(rows,cols);

matrix.acceptMatrix();

cout<<”\nOriginal”;

matrix.displayMatrix();

Matrix transpose= -matrix;

cout<<”\nTranspose”;

transpose.displayMatrix();

matrix++;

cout<<”\nMatrix after incrementing elements by 1:”<<endl;

matrix.displayMatrix();

return 0;

Q.2

a)

const EventEmitter=require(‘events’);

const eventEmitter=new EventEmitter();

eventEmitter.on(‘event1’, () => {

console.log(‘Event 1 occurred’);

});

eventEmitter.on(‘event2’, () => {

console.log(‘Event 2 occurred’);

});

console.log(‘Listening for events…’);

process.stdin.on(‘data’, (data) => {


const input=data.toString().trim().toLowerCase();

if(input === ‘1’){

eventEmitter.emit(‘event1’);

}else if(input === ‘2’){

eventEmitter.emit(‘event2’);

}else if(input === ‘3’){

console.log(‘Exiting…’);

}else{

console.log(‘Invalid input.Type “event1” or “event2” to trigger events, or “exit” to quit.’);

});

b)

var mysql=require('mysql');

var con=mysql.createConnection({

host: "localhost",

user: "root",

password: "12345",

database: "employeedb",

port: "3306"

});

con.connect(function(err){

if(err) throw err;

var sql="UPDATE Employee SET salary=50000 WHERE Eno=2";

con.query(sql,function(err,result,display){

if(err) throw err;

console.log(result.affectedRows + "record updated");

});

con.query("SELECT * FROM Employee",function(err,result,fields){

if(err) throw err;

console.log(result);

});

});
SLIP 19
Q.1

a)

#include<iostream.h>

class Distance{
private:

int meter;

int centimeter;

public:

Distance(int m, int cm) : meter(m), centimeter(cm) {}

Distance Larger(const Distance& d){

if(this->meter > d.meter||(meter==d.meter && centimeter > d.centimeter)){

return *this;

}else{

return d;

void display() const {

cout<<”Meter:”<<meter<<”Centimeter:”<<centimeter<<endl;

};

int main(){

Distance d1(5, 60);

Distance d2(6, 30);

Distance largerDistance=d1.Larger(d2);

cout<<”The larger distances is:”<<endl;

largerDistances.display();

return 0;

b)
Q.2

a)

const fs=require(‘fs’);

function showStartupInfo(){

console.log(“Node.js application started.”);

function openFile(filePath){

fs.access(filePath, fs.constants.F_OK, (err) => {

if(err){

console.error(`Error: File ‘${filePath}’ not found.`);

}else{

console.warn(`Warning: File ‘${filePath}’ already exists.`);

});

function main(){

showStartupInfo();

const filePath=’example.txt’;

openFile(filePath);

main();

b)

SLIP 20
Q.1

a)

#include<iostream.h>

using namespace std;

class Number{

private:
int num;

public:

Number(int n=0) : num(n) {}

Number& operator++() {

++num;

return *this;

Number operator++(int) {

Number temp= *this;

++(*this);

return temp;

void display() {

cout<<”Number:”<<num<<endl;;

};

int main(){

Number numObj(5);

cout<<”Original value:”<<numObj.display()<<endl;

++numObj;

cout<<”After pre-increment:”<<numObj.display()<<endl;

numObj++;

cout<<”After post-increment:”<<numObj.display()<<endl;

return 0;

b)

Q.2

a)

const fs=require(‘fs’);

const EventEmitter=require(‘events’);

class FileHandler extends EventEmitter{


readFileContents(filename){

fs.readFile(filename,’utf8’,(err,data) => {

if(err){

this.emit(‘error’,err);

}else{

this.emit(‘fileRead’,data);

});

const fileHandler=new FileHandler();

fileHandler.on(‘fileRead’,(data) => {

console.log(‘File Contents:’);

console.log(data);

});

fileHandler.on(‘error’,(err) => {

console.error(‘Error reading file:’,err);

});

const filename=’example.txt’;

fileHandler.readFileContents(filename);

b)

index.html

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width,initial-scale=1.0">

<title>SYBBA(CA) Course Structure</title>

</head>

<body>

<h1>SYBBA(CA) Course Structure</h1>

<h2>First Semester</h2>
<ul>

<li>Digital Marketing</li>

<li>Data Structure</li>

<li>Software Engineering</li>

<li>Big Data</li>

<li>Angular JS</li>

</ul>

<h2>Second Semester</h2>

<ul>

<li>Networking</li>

<li>Object Oriented Concept Through CPP</li>

<li>Operating System</li>

<li>Node JS</li>

</ul>

</body>

</html>

slip20b.js

const express=require('express');

const app=express();

const port=3030;

app.get('/',(req,res)=>{

res.sendFile(__dirname+'/index.html');

});

app.listen(port,()=>{

console.log(`Server is running on http://localhost:${port}`);

});

SLIP 22
Q.1

a)

b)
Q.2

a)

const fs=require(‘fs’);

function countLines(filePath) {

try {

const fileContent=fs.readFileSync(filePath, ‘utf8’);

const lines=fileContent.split(‘\n’);

return lines.length;

}catch(err){

console.error(‘Error reading file:’, err);

return -1;

const filePath=’sample.txt’;

const lineCount=countLines(filePath);

if(lineCount !== -1) {

console.log(`Number of lines in the file: ${lineCount}`);

}else{

console.log(‘Failed to count lines. Check the file path and permissions.’);

b)

SLIP 23
Q.1

a)

#include<iostream.h>

#include<string.h>

class Mystring {

private:
char *str;

public:

Mystring(const char *s=””)

str=new char[strlen(s)+1];

strcpy(str,s);

~Mystring() {

delete[] str;

void display() const {

cout<<endl<<str;

Mystring operator+(const MyString& other) const {

char *temp=new char[strlen(str)+strlen(other.str)+1];

strcpy(temp,str);

strcat(temp,other.str);

MyString result(temp);

delete[] temp;

return result;

};

int main() {

MyString str1(“Hello”);

MyString str2(“World!”);

cout<<”String 1:”;

str1.display();

cout<<endl;

cout<<”String 2:”;

str2.display();

cout<<endl;

MyString concatenatedStr=str1+str2;

cout<<”Concatenated String:”;
concatenatedStr.display();

cout<<endl;

return 0;

b)

Q.2

a)

const fs=require(‘fs’);

function searchAndReplace(filename, searchWord, replaceWord) {

fs.readFile(filename, ‘utf8’, (err, data) => {

if(err) {

console.error(‘Error reading file:’, err);

return;

const regex=new RegExp(‘\\b${searchWord}\\b’, ‘g’);

const replacedData=data.replace(regex, ‘**${replaceWord}**’);

fs.writeFile(filename, replacedData, ‘utf8’, (err) => {

if(err) => {

console.error(‘Error writing file:’, err);

return;

console.log(`Replacement complete. “${searchWord}” replaced with “$


{replaceWord}” in ${filename}.`);

});

});

const filename=’sample.txt’;

const searchWord=’SYBBA(CA)’;

const replaceWord=’TYBBA(CA)’;

searchAndReplace(filename, searchWord, replaceWord);


b)

npm install pdfkit

eTicket.js

const PDFDocument=require('pdfkit');

const fs=require('fs');

function generateETicket(ticketDetails){

const doc=new PDFDocument();

const stream=fs.createWriteStream('eticket.pdf');

doc.pipe(stream);

doc.fontSize(18).text('Railway eTicket',{align:'center'});

doc.moveDown();

doc.fontSize(12).text(`Name:${ticketDetails.name}`);

doc.text(`Train No:${ticketDetails.trainNo}`);

doc.text(`From:${ticketDetails.from}`);

doc.text(`To:${ticketDetails.to}`);

doc.text(`Date:${ticketDetails.date}`);

doc.text(`Class:${ticketDetails.class}`);

doc.text(`Seat No:${ticketDetails.seatNo}`);

doc.end();

console.log('eTicket generated successfully.');

module.exports=generateETicket;

slip23b.js

const generateETicket=require('./eTicket');

const ticketDetails={

name: 'Soham Phansalkar',

trainNo: '12345',

from: 'Mumbai',

to: 'Pune',

date: '2024-04-02',

class: 'Sleeper',

seatNo: 'A1'

};
generateETicket(ticketDetails);

SLIP 26
Q.1

a)

#include<iostream.h>

float average(int num1,int num2,int num3)

return (num1+num2+num3)/3;

float average(float num1,float num2,float num3)

return (num1+num2+num3)/3;

int main()

int int1=10,int2=20,int3=30;

cout<<”Average of three integers:”<<average(int1,int2,int3)<<endl;

float float1=10,float2=20,float3=30;

cout<<”Average of three floats:”<<average(float1,float2,float3)<<endl;

return 0;

b)

Q.2

a)

const EventEmitter=require('events');

class MyEmitter extends EventEmitter{

constructor(){

super();

raiseEvent(){
setTimeout(()=>{

this.emit('customEvent','Event emitted after 2 seconds');

},2000);

const myEmitter=new MyEmitter();

myEmitter.on('customEvent',(message)=>{

console.log('Received message:',message);

});

myEmitter.raiseEvent();

b)

const express=require('express');

const app=express();

app.get('/',(req,res)=>{

res.send(`

<h1>Welcome to Our Departmental Store Portal</h1>

<ul>

<li><a href="/products">Products</a></li>

<li><a href="/departments">Departments</a></li>

<li><a href="/contact">Contact</a></li>

</ul>

`);

});

app.get('/products',(req,res)=>

res.send(`<h2>List Of Products</h2>

<ul>

<li>Electronics</li>

<li>Cloths</li>

<li>Groceries</li>

</ul>`);

});
app.get('/departments',(req,res)=>

res.send(`<h2>List Of Departments</h2>

<ul>

<li>Electronics</li>

<li>Clothing</li>

<li>Groceries</li>

</ul>`);

});

app.get('/contact',(req,res)=>

res.send(`<h2>Contact Us</h2>

<ul>

<li>Phone:892178xxxx</li>

<li>Email:dstore71@gmail.com</li>

<li>Address:Pune</li>

</ul>`);

});

app.listen(5000);

console.log("Successfully Run!");

SLIP 27
Q.1

a)

#include<iostream.h>

#include<string.h>

const int MAX_LENGTH=100;

class College

private:

int College_id;

char College_Name[MAX_LENGTH];

int Establishment_year;
char University_Name[MAX_LENGTH];

public:

friend istream& operator>>(istream& in,College& college)

cout<<”Enter College ID:”;

in>>college.College_id;

cout<<”Enter College Name:”;

in.ignore();

in.getline(college.College_Name,MAX_LENGTH);

cout<<”Establishment Year:”;

in>>college.Establishment_year;

cout<<”Enter University Name:”;

in.ignore();

in.getline(college.University_Name,MAX_LENGTH);

return in;

friend ostream& operator<<(ostream& out,const College& college)

out<<”College ID:”<<college.College_id<<endl;

out<<”College Name:”<<college.College_Name<<endl;

out<<”Establishment Year:”<<college.Establishment_year<<endl;

out<<”University Name:”<<college.University_Name<<endl;

return out;

};

int main()

College college;

cout<<”Enter College Details:”<<endl;

cin>>college;

cout<<”College Information:”<<endl;

cout<<college;

return 0;
}

b)

Q.2

a)

const fs=require('fs');

const path=require('path');

const directoryName='example_directory';

const fileContents='This is a sample file content.';

fs.mkdir(directoryName,(err)=>{

if(err){

console.error('Error creating directory:',err);

}else{

console.log('Directory created successfully.');

const filePath=path.join(__dirname,directoryName,'example_file.txt');

fs.writeFile(filePath,fileContents,(err)=>{

if(err){

console.error('Error creating file:',err);

}else{

console.log('File created successfully.');

});

});

b)

validate4.js

function Name(name)

return name.match(/^[A-Za-z]+$/)!=null;

function Dob(dob)
{

const dobDate=new Date(dob);

return dobDate.getTime()?dobDate:null;

function Email(email)

return email.includes('@')&&email.includes('.');

function Mobile(mno)

return mno.match(/^\d{10}$/);

module.exports={Name,Dob,Email,Mobile};

slip27b.js

const http=require('http');

const qs=require('querystring');

const {Name,Email,Mobile}=require('./validate4');

http.createServer((req,res)=>

if(req.method=='GET'&&req.url=='/register')

res.writeHead(200,{'Content-Type':'text/html'});

res.end(`

<form method="post" action="/register">

Name:

<input type="text" id="name" name="name"><br>

Email:

<input type="text" id="email" name="email"><br>

Mobile Number:

<input type="text" id="mno" name="mno"><br>

Date Of Birth:

<input type="date" id="bdate" name="bdate"><br>

Age:
<input type="number" id="age" name="age"><br>

Address:

<input type="text" id="add" name="add"><br>

<button type="submit">Register</button>

</form>

`);

else if(req.method=='POST'&&req.url=='/register')

let body='';

req.on('data',(data)=>

body=body+data;

});

req.on('end',()=>

const Data=qs.parse(body);

const name=Data.name;

const email=Data.email;

const mno=Data.mno;

const dob=Data.bdate;

const age=Data.age;

const add=Data.add;

if(!Name(name))

res.end('Enter Name Field Proper!');

return;

if(!Email(email))

res.end('Invalid Email Id!');

return;

}
if(!Mobile(mno))

res.end('Mobile Number Contains 10 Digits Only!');

console.log(`Student Registered:

Name:${name}

Email:${email}

Mobile Number:${mno}

Date of Birth:${dob}

Age:${age}

Address:${add}

`);

res.end('Student registered successfully');

});

else

res.writeHead(404,{'Content-Type':'text/plain'});

res.end('Not Found');

}).listen(3037);

console.log("Successfully Run.");

SLIP 29
Q.1

a)

b)

Q.2

a)

rectangle.js

class rectangle{
constructor(length,width){

this.length=length;

this.width=width;

calculateArea(){

return this.length*this.width;

};

module.exports=rectangle;

app.js

const rectangle=new Rectangle(5,2);

const area=rectangle.calculateArea();

console.log('Rectangle Details:');

console.log('Length:',rectangle.lenth);

console.log('Width:',rectangle.width);

console.log('Area:',area);

b)

SLIP 30
Q.1

a)

#include<iostream.h>

const int MAX_SIZE=100;

class Integer_Array;

class Float_Array;

float average(const Integer_Array& intArray);

float average(const Float_Array& floatArray);

class Integer_Array

private:

int size;
int arr[MAX_SIZE];

public:

Integer_Array(int s):size(s) {}

void accept()

cout<<”Enter”<<size<<”intger elements:”<<endl;

for(int i=0;i<size;i++)

cin>>arr[i];

void display() const

cout<<”Integer Array Elements:”<<endl;

for(int i=0;i<size;i++)

cout<<arr[i]<<””;

cout<<endl;

friend float average(const Integer_Array& intArray);

};

class Float_Array

private:

int size;

int arr[MAX_SIZE];

public:

Integer_Array(int s):size(s) {}

void accept()

cout<<”Enter”<<size<<”float elements:”<<endl;

for(int i=0;i<size;i++)
{

cin>>arr[i];

void display() const

cout<<”Float Array Elements:”<<endl;

for(int i=0;i<size;i++)

cout<<arr[i]<<””;

cout<<endl;

friend float average(const Float_Array& floatArray);

};

float average(const Integer_Array& intArray)

int sum=0;

for(int i=0;i<intArray.size;i++)

sum+=intArray.arr[i];

return (sum)/intArray.size;

float average(const Float_Array& floatArray)

float sum=0;

for(int i=0;i<floatArray.size;i++)

sum+=floatArray.arr[i];

return (sum)/floatArray.size;

}
int main()

int intSize,floatSize;

cout<<”Enter size of integer array:”;

cin>>intSize;

Integer_Array intArray(intSize);

intArray.accept();

intArray.display();

cout<<”Average of Integer Array:”<<average(intArray)<<end;

cout<<”\nEnter size of float array:”;

cin>>floatSize;

Float_Array floatArray(floatSize);

floatArray.accept();

floatArray.display();

cout<<”Average of Float Array:”<<average(floatArray)<<end;

return 0;

b)

Q.2

a)

circle.js

const PIE=3.14;

function area(r){

return PIE*r*r;

};

function circum(r){

return 2*PIE*r;

};

module.exports={area,circum};

app.js

let app=require("./circle");
const readline=require('readline');

const rl=readline.createInterface({

input:process.stdin,

output:process.stdout

});

rl.question('Enter a radius:',(r)=>{

console.log("Area of circle is:",app.area(r));

console.log("Circumference of circle is:",app.circum(r));

});

b)

slip30DB.js

let mysql=require("mysql");

let con=mysql.createConnection({

host: "localhost",

user: "root",

password: "12345",

port: "3306",

});

con.connect(function(err){

if (err) {

console.log(err);

} else {

console.log("connected");

});

con.query("CREATE DATABASE hospitalDB",function(err,result){

if(err) throw err;

console.log("Database Created");

});

Slip30b.js

let mysql=require("mysql");

let con=mysql.createConnection({
host: "localhost",

user: "root",

password: "12345",

port: "3306",

database: "hospitalDB"

});

con.connect(function(err){

if (err) {

console.log(err);

} else {

console.log("connected");

});

var sql="CREATE TABLE hospital(hReg int,hName varchar(30),address varchar(30),contact int)";

con.query(sql,function(err,result){

if(err) throw err;

console.log("Table Created");

});

You might also like