Monday, 30 September 2024

Journal Program 13

 #include<iostream.h>

#include<conio.h>

class Cricketer

{

int age,tmatch,trun,twicket;

char name[20],country[20],type[10];

public:

void getData()

{

cout<<"Enter name=";

cin>>name;

cout<<"Enter age=";

cin>>age;

cout<<"Enter country=";

cin>>country;

cout<<"Enter type(Bat/Bow)=";

cin>>type;

cout<<"Enter total matches=";

cin>>tmatch;

cout<<"Enter total runs=";

cin>>trun;

cout<<"Enter total wickets=";

cin>>twicket;

}

void putData()

{

cout<<endl<<"Name="<<name;

cout<<endl<<"Age="<<age;

cout<<endl<<"Country="<<country;

cout<<endl<<"Type="<<type;

cout<<endl<<"Total Matches="<<tmatch;

cout<<endl<<"Total Runs="<<trun;

cout<<endl<<"Total Wickets="<<twicket;

}

};

int main()

{

clrscr();

Cricketer c[5];

int i;

cout<<"Enter total cricketers = ";

cin>>n;

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

{

c[i].getData();

}

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

{

c[i].putData();

}

getch();

return 0;

}




Journal Program 11

 #include<iostream.h>

#include<conio.h>

#include<stdio.h>

#include<process.h>

class Factorial

{

int i,fact,n;

public:

Factorial()

{

cout<<"\n Enter value of n : ";

cin>>n;

}

void for_fact()

{

fact=1;

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

{

fact=fact * i;

}

cout<<"\n "<<n<<"! = "<<fact;

}

void do_fact()

{

fact=1;

i=1;

do

{

   fact = fact * i;

   i++;

}while(i<=n);

cout<<"\n "<<n<<"! = "<<fact;

}


void while_fact()

{

fact=1;

i=1;

while(i<=n)

{

fact=fact*i;

i++;

}

cout<<"\n "<<n<<"! = "<<fact;

}

};

int main()

{

clrscr();

int choice;

char ch;

Factorial obj1;

do

{

cout<<endl<<"1:Factorial using For Loop ";

cout<<endl<<"2:Factorial using Do..While Loop ";

cout<<endl<<"3:Factorial using While Loop ";

cout<<endl<<"4:Exit";


cout<<endl<<"\nEnter your choice=";

cin>>choice;

switch(choice)

{

case 1:

obj1.for_fact();

break;

case 2:

obj1.do_fact();

break;

case 3:

obj1.while_fact();

break;


case 4:

exit(0);

break;

default:

cout<<endl<<"Invalid choice";

}

cout<<"\nDo you want to cont...";

cin>>ch;

}while(ch=='y'||ch=='Y');

return 0;

}

Journal Program 7

 #include<iostream.h>

#include<conio.h>

#include<string.h>

#include<process.h>

#include<ctype.h>

class String

{

char str[100];

public:

void getData()

{

cout<<"Enter string : ";

cin>>str;

}

void strlen1()

{

int len;

len=strlen(str);

cout<<"\nLength of "<<str<< " is "<<len;

}

void strrev1()

{

cout<<"\nReverse of "<<str<<" is :"<<strrev(str);

}

void strupr1()

{

cout<<"\nUpper Case of string is ="<<strupr(str);

}

void strlwr1()

{

cout<<"\nLower Case of string is ="<<strlwr(str);

}


};

int main()

{

clrscr();

int choice;

char ch;

String s;

s.getData();

do

{

cout<<endl<<"1:Reverse String";

cout<<endl<<"2:Convert the string in Uppercase";

cout<<endl<<"3:Convert the string in Lowercase";

cout<<endl<<"4:String Length";

cout<<endl<<"5:Exit";


cout<<endl<<"\nEnter your choice=";

cin>>choice;

switch(choice)

{

case 1:

s.strrev1();

break;

case 2:

s.strupr1();

break;

case 3:

s.strlwr1();

break;

case 4:

s.strlen1();

break;

case 5: exit(0);

break;

default:

cout<<endl<<"Invalid choice";

}

cout<<"\nDo you want to cont...";

cin>>ch;

}while(ch=='y'||ch=='Y');

return 0;

}

Journal PRogram 6

 #include<iostream.h>

#include<conio.h>

#include<string.h>

#include<process.h>

class String

{

char str1[100],str2[100];

public:

void getData()

{

cout<<"Enter first string : ";

cin>>str1;

cout<<"Enter second string : ";

cin>>str2;


}

void strlen1()

{

int len1,len2;

len1=strlen(str1);

len2=strlen(str2);

cout<<"\nLength of "<<str1<< " is "<<len1;

cout<<"\nLength of "<<str2<< " is "<<len2;


}

void strcpy1()

{

cout<<"\nAfter Copy String2 in to String1 :";

strcpy(str1,str2);

cout<<"\nString 1 ="<<str1;

}

void strcat1()

{

strcat(str1,str2);

cout<<"\nConcated String is ="<<str1;

}

void strcmp1()

{

if(strcmp(str1,str2)==0)

cout<<"\nTwo Strings are equal";

else

cout<<"\nTwo Strings are not equal";

}


};

int main()

{

clrscr();

int choice;

char ch;

String s;

s.getData();

do

{

cout<<endl<<"1:String Length";

cout<<endl<<"2:Copy in another string";

cout<<endl<<"3:To combine two string";

cout<<endl<<"4:To compare two strings";

cout<<endl<<"5:Exit";


cout<<endl<<"\nEnter your choice=";

cin>>choice;

switch(choice)

{

case 1:

s.strlen1();

break;

case 2:

s.strcpy1();

break;

case 3:

s.strcat1();

break;

case 4:

s.strcmp1();

break;

case 5: exit(0);

break;

default:

cout<<endl<<"Invalid choice";

}

cout<<"\nDo you want to cont...";

cin>>ch;

}while(ch=='y'||ch=='Y');

return 0;

}

Journal Program 10

 #include<iostream.h>

#include<conio.h>

class Swap

{


public:

int a,b;

float x,y;

Swap(int m,int n)

{

a=m;

b=n;

cout<<"\n Before interchange :";

cout<<"\n Value of a : "<<a;

cout<<"\n Value of b : "<<b;


a=a+b;

b=a-b;

a=a-b;

cout<<"\n After interchange :";

cout<<"\n Value of a : "<<a;

cout<<"\n Value of b : "<<b;

}

Swap(float j,float k)

{

x=j;

y=k;

cout<<"\n Before interchange :";

cout<<"\n Value of x : "<<x;

cout<<"\n Value of y : "<<y;


x=x+y;

y=x-y;

x=x-y;

cout<<"\n After interchange :";

cout<<"\n Value of x : "<<x;

cout<<"\n Value of y : "<<y;

}

};

int main()

{

clrscr();

Swap s1(10,20);

Swap s2(3.14f,4.13f);

getch();

return 0;

}


Journal Program 9

 #include<iostream.h>

#include<conio.h>

#include<stdio.h>

#include<process.h>

class OddEven

{

public:

int sum,n;

OddEven()

{

cout<<"\n Enter value of n : ";

cin>>n;

}

void oddSum()

{

int i,count=0,sum=0;

for(i=1;count<n;i=i+2)

{

count++;

cout<<i<<" + ";

sum=sum+i;

}

cout<<"\b\b\b";

cout<<" = "<<sum;

}

void evenSum()

{

int i,count=0,sum=0;

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

{

count++;

cout<<i<<" + ";

sum=sum+i;

}

cout<<"\b\b\b";

cout<<" = "<<sum;

}

};

int main()

{

clrscr();

int choice;

char ch;

OddEven obj1;

do

{

cout<<endl<<"1:Sum of first "<<obj1.n<<" odd numbers ";

cout<<endl<<"2:Sum of first "<<obj1.n<<" even numbers ";

cout<<endl<<"3:Exit";


cout<<endl<<"\nEnter your choice=";

cin>>choice;

switch(choice)

{

case 1:

obj1.oddSum();

break;

case 2:

obj1.evenSum();

break;

case 3:

exit(0);

break;

default:

cout<<endl<<"Invalid choice";

}

cout<<"\nDo you want to cont...";

cin>>ch;

}while(ch=='y'||ch=='Y');

return 0;

}


Journal PRogram 2

 #include<iostream.h>

#include<conio.h>

class Fact

{

int n;

public :

void getData()

{

cout<<"\n Enter value of n : ";

cin>>n;

}

void putData();

};

void Fact::putData()

{

int i,f=1;

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

{

f=f*i;

}

cout<<"\n Factorial of "<<n<<" is "<<f;

}


int main()

{

clrscr();

Fact f;

f.getData();

f.putData();

getch();

return 0;

}


Journal Program 1

 #include<iostream.h>

#include<conio.h>

class Fibo

{

int n;

public :

void getData()

{

cout<<"\n Enter value of n : ";

cin>>n;

}

void putData()

{

int a,b,c,i;

a=1;

b=1;

cout<<a<<"  "<<b<<"  ";

for(i=1;i<(n-1);i++)

{

c=a+b;

a=b;

b=c;

cout<<c<<"  ";

}

}

#include<iostream.h>

#include<conio.h>

class Fibo

{

int n;

public :

void getData()

{

cout<<"\n Enter value of n : ";

cin>>n;

}

void putData()

{

int a,b,c,i;

a=1;

b=1;

cout<<a<<"  "<<b<<"  ";

for(i=1;i<(n-1);i++)

{

c=a+b;

a=b;

b=c;

cout<<c<<"  ";

}

}


};


int main()

{

clrscr();

Fibo f;

f.getData();

f.putData();

getch();

return 0;

}

};


int main()

{

clrscr();

Fibo f;

f.getData();

f.putData();

getch();

return 0;

}


Wednesday, 18 September 2024

WRITE A JAVASCRIPT TO PRINT SUM OF GIVEN ODD OR EVEN NUMBERS


CODE:-

<html>

<head>

<title>Even Or Odd Sum</title>

<style type="text/css">

body{

background-color:yellow;

}

.tab{

text-transform:capitalize;

background-color:lightgrey;

}

.v2{

text-align:center;

}

.v1{

background-color:purple;

color:white;

text-transform:uppercase;

}

</style>

<script type="text/javascript">

function check()

{

var no=parseInt(document.f1.no.value);

var even=0,odd=0,sodd=0,seven=0;

for(var i=1;i<=no;i++)

{

if(i%2==0)

{

even++;

seven=seven+i;

}

else

{

odd++;

sodd=sodd+i;

}

}

document.f1.even.value=even;

document.f1.seven.value=seven;

document.f1.odd.value=odd;

document.f1.sodd.value=sodd;

return false;

}

</script>

</head>

<body>

<center>

<form name="f1" method="post" onsubmit="return check()">

<table border="1" class="tab">

<tr class="v1">

<th colspan="2"><h5>sum of even or odd number</h5></th>

</tr>

<tr>

<th>enter number:-</th>

<td><input type="text" name="no" size="5" style="border-radius:15px;"></td>

</tr>

<tr class="v2">

<td colspan="2">

<input type="submit" name="submit" value="Submit" style="border-radius:10px;background-color:lightgreen;border-color:orange;color:red;">

<input type="reset" name="reset" value="Reset" style="border-radius:10px;background-color:lightgreen;border-color:orange;color:red;">

</td>

</tr>

<tr>

<th>even numbers:-</th>

<td><input type="text" name="even" size="5" style="border-radius:15px;"></td>

</tr>

<tr>

<th>odd numbers:-</th>

<td><input type="text" name="odd" size="5" style="border-radius:15px;"></td>

</tr>

<tr>

<th>sum of even numbers:-</th>

<td><input type="text" name="seven" size="5" style="border-radius:15px;"></td>

</tr>

<tr>

<th>sum of odd numbers:-</th>

<td><input type="text" name="sodd" size="5" style="border-radius:15px;"></td>

</tr>

</table>

</form>

</center>

</body>

</html>


WRITE A JAVASCRIPT TO PRINT FACTORIAL OF GIVEN NUMBER

CODE:-

<html>

<head>

<title>Factorial</title>

<style type="text/css">

body{

background-color:lightgreen;

}

.tab{

background-color:yellow;

color:;

text-transform:capitalize;

}

.v1{

text-align:center;

background-color:lightblue;

}

.v2{

text-align:center;

background-color:blue;

color:white;

}

</style>

<script type="text/javascript">

function check()

{

var a=document.f1.no.value;

var i,fact=1;

for(i=1;i<=a;i++)

{

fact=fact*i;

}

document.f1.ans.value=fact;

return false;

}

</script>

</head>

<body>

<center>

<form name="f1" method="post" onsubmit="return check()">

<table border="1" cellspacing="0" class="tab">

<tr class="v2">

<th colspan="2">factorial of given number</th>

</tr>

<tr>

<th>enter number:</th>

<td><input type="text" name="no" size="5" style="border-radius:10px;"></td>

</tr>

<tr class="v1">

<td colspan="2">

<input type="submit" name="submit" value="Submit" style="border-radius:8px;background-color:red;color:white;font-weight:bold;border-color:green;">

<input type="reset" name="reset" value="Reset" style="border-radius:8px;background-color:red;color:white;font-weight:bold;border-color:green;">

</td>

</tr>

<tr>

<th>factorial is:</th>

<td><input type="text" name="ans" size="5" style="border-radius:10px;"></td>

</tr>

</table>

</form>

</center>

</body>

</html>


WRITE A JAVASCRIPT TO PRINT GIVEN NUMBER IS PALINDROME OR NOT


CODE:-

<html>

<head>

<title>Palindrome</title>

<style type="text/css">

body{

background-color:lightgreen;

}

.v1{

text-align:center;

}

.tab{

background-color:lightblue;

text-transform:capitalize;

}

.v2{

text-align:center;

text-transform:capitalize;

background-color:lightgrey;

color:red;

}

</style>

<script type="text/javascript">

function check()

{

var no,i,temp,rem,rev=0;

no=parseInt(document.f1.no.value);

temp=no;

while(no>0)

{

rem=no%10;

no=parseInt(no/10);

rev=(rev*10)+rem;

}

if(rev==temp)

{

var an=["Yes"];

document.f1.ans.value=an;

}

else

{

var a=["No"];

document.f1.ans.value=a;

}

return false;

}

</script>

</head>

<body>

<center>

<form name="f1" method="post" onsubmit="return check()">

<table border="1" cellspacing="0" class="tab">

<tr class="v1">

<th colspan="2">to check palindrome of given number</th>

</tr>

<tr>

<th>enter number:-</th>

<td><input type="text" name="no" size="5" style="border-radius:10px;"></td>

</tr>

<tr class="v1">

<td colspan="2">

<input type="submit" name="submit" value="Submit" style="border-radius:8px;background-color:red;color:white;font-weight:bold;border-color:green;">

<input type="reset" name="reset" value="Reset" style="border-radius:8px;background-color:red;color:white;font-weight:bold;border-color:green;">

</td>

</tr>

<tr>

<th>given number:-</th>

<td><input type="text" name="ans" size="5" style="border-radius:10px;"></td>

</tr>

</table>

</form>

</center>

</body>

</html>


WRITE A JAVASCRIPT TO READ TIME AND PEFORM HOUR MINUTE SECOND

 Write a JavaScript program to read a time from user and perform the following, if entered value is time then perform the following

 

1.Display the hour from the time

2.Display the minute from the time

3.Display the second from the time

4.Change the hour to next hour

5.Change the minute to next minute

6.change the second to next second


<html>

<head>

<title>Time Processor</title>

<script>

function processTime() 

{

  var timeInput = document.getElementById("timeInput").value;

  var timeParts = timeInput.split(":");

if (timeParts.length !== 3) 

{

    alert("Invalid time format.Please enter time in HH:MM:SS format.");

    return;

  }


  var hour = parseInt(timeParts[0]);

  var minute = parseInt(timeParts[1]);

  var second = parseInt(timeParts[2]);


  document.getElementById("hr").value = hour;

  document.getElementById("min").value = minute;

  document.getElementById("sec").value = second;


  var nexthr=(hour + 1)%24;    document.getElementById("nexthr").value=nexthr;


  var nextmin=(minute + 1)%60;

  document.getElementById("nextmin").value=nextmin;


  var nextsec=(second + 1)%60;

  document.getElementById("nextsec").value=nextsec;

}

</script>

</head>

<body>

<h1>Time Processor</h1> 

<h3> Enter Time (HH:MM:SS): <input type="text" id="timeInput" value="00:00:00">

<button onclick="processTime()">Process Time</button> </h3>

<table border="1">

<tr>

  <td> Hour: </td> 

<td> <input type="text" id="hr" readonly> </td>

</tr>

<tr>

<td> Minute </td>

<td> <input type="text" id="min" readonly> </td>

</tr>

<tr>

<td> Second: </td>

<td> <input type="text" id="sec" readonly> </td>

</tr>

<tr>

<td> Next Hour: </td>

<td> <input type="text" id="nexthr" readonly> </td>

</tr>

<tr>

<td> Next Minute:</td>

<td> <input type="text" id="nextmin" readonly> </td>

</tr>

</tr>

<td> Next Second:</td>

<td> <input type="text" id="nextsec" readonly> </td>

</tr>

</table>

</body>

</html>

WRITE A JAVASCRIPT TO READ DATE AND PEFORM DAY NO YEAR MONTH

Write a JavaScript program to read a date from user and perform the following, if entered value is date then perform the following

 

1.Display the day no from the date

2.Display the year from the date

3.Display the month from the date

4.Change the date to next day

5.Change the year to next year

6.change the month to next month 


<html>

  <head>

<style type="text/css">

td{text-align:center;

}

}

</style>

  <script>

      function processDate() 

{

        var dateInput = document.getElementById("dateInput").value;

        var date = new Date(dateInput);


        

        document.getElementById("day").value = date.getDate();


        

        document.getElementById("year").value = date.getFullYear();


        var monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];

        document.getElementById("month").value = monthNames[date.getMonth()];


        var nextDay = new Date(date);

        nextDay.setDate(nextDay.getDate() + 1);

        document.getElementById("nextDay").value = nextDay.toLocaleDateString();


        var nextYear = new Date(date);

        nextYear.setFullYear(nextYear.getFullYear() + 1);

        nextYear.setDate(date.getDate());

        document.getElementById("nextYear").value = nextYear.toLocaleDateString();


        var nextMonth = new Date(date);

        nextMonth.setMonth(nextMonth.getMonth() + 1);

        nextMonth.setDate(date.getDate());

        document.getElementById("nextMonth").value = nextMonth.toLocaleDateString();

      }

    </script>

</head>

<body>

<h3 align="center"> <input type="date" id="dateInput"> </td>

    <button onclick="processDate()"> Process Date </button> </h3>

    <table border="1" align="center"> 

<tr> 

<td> Day: </td>

<td> <input type="text" id="day"> </td>

</tr>

<tr>

<td> Year: </td>

<td> <input type="text" id="year"> </td>

</tr>

<tr>

<td> Month: </td>

<td> <input type="text" id="month"> </td>

</tr>

    <tr>

<td> Next Day: </td>

<td> <input type="text" id="nextDay"> </td>

</tr>

<tr>

<td> Next Year: </td>

<td> <input type="text" id="nextYear"> </td>

</tr>

<tr>

<td> Next Month: </td>

<td> <input type="text" id="nextMonth"> </td>

</tr>

</table>

  </body>

</html>

Tuesday, 17 September 2024

WRITE A JAVASCRIPT TO PERFORM AIRTHMETIC OPERATION ON BUTTON CLICK EVENT

 




<html>

<head><title>Example-8</title>

<script language="JavaScript">

function add() {

var num1=document.getElementById("txt_num1").value;

var num2=document.getElementById("txt_num2").value;

var n1=parseInt(num1);

var n2=parseInt(num2);

var ans=n1+n2;

document.getElementById("txt_res").value=ans;

}

function sub() {

var num1=document.getElementById("txt_num1").value;

var num2=document.getElementById("txt_num2").value;

var n1=parseInt(num1);

var n2=parseInt(num2);

var ans=n1-n2;

document.getElementById("txt_res").value=ans;

}

function mul() {

var num1=document.getElementById("txt_num1").value;

var num2=document.getElementById("txt_num2").value;

var n1=parseInt(num1);

var n2=parseInt(num2);

var ans=n1*n2;

document.getElementById("txt_res").value=ans;

}

function div() {

var num1=document.getElementById("txt_num1").value;

var num2=document.getElementById("txt_num2").value;

var n1=parseInt(num1);

var n2=parseInt(num2);

var ans=n2/n1;

document.getElementById("txt_res").value=ans;

}

</script>

</head>


<body>

<form method="POST">

<table border="2px">

<tr>

<th>Number1:</th>

<td><input type="text" id="txt_num1"/></td>

</tr>

<tr>

<th>Number2:</th>

<td><input type="text" id="txt_num2"/></td>

</tr>

<tr>

<td colspan="2" align="center"><input type="button" value="ADD"

onclick="add()"/>

<input type="button" value="SUB" onclick="sub()"/>

<input type="button" value="MUL" onclick="mul()"/>

<input type="button" value="DIV" onclick="div()"/></td>

</tr>

<tr>

<th>RESULT:</th>

<td><input type="text" id="txt_res"/></td>

</tr>

</table>

</form>

</body>

</html>

WRITE A JAVASCRIPT TO INPUT FORM DATA AND PRINT THEM



CODE


 <html>

<head><title>Example-12</title>

<script language="JavaScript">

function showData() {

var rno=parseInt(document.getElementById("txt_rno").value);

var name=document.getElementById("txt_name").value;

var male=document.getElementById("male").checked;

if(male == true)

var male1="Male";

else

male1="Female";

//alert(male1);

var read1=document.getElementById("read").checked;

var write1=document.getElementById("write").checked;

var speak1=document.getElementById("speak").checked;

//alert(read1);

if(read1 == true && write1 == true && speak1 == true) {

var a="Read, Write, Speak";

document.write("Hello Sir/Madam, "+name+", Your registration Number: "+rno+"has been selected due to your english ability: "+a+"Your gender is: "+male1);

}

else if(read1 == true && write1 == true) {

var a="Read, Write";

document.write("Hello Sir/Madam, "+name+", Your registration Number: "+rno+"has been selected due to your english ability: "+a+"Your gender is: "+male1);

}

else if(read1 == true && speak1 == true) {

var a="Read, Speak";

document.write("Hello Sir/Madam, "+name+", Your registration Number: "+rno+"has been selected due to your english ability: "+a+"Your gender is: "+male1);

}

else if(write1 == true && speak1 == true) {

var a="Write, Speak";

document.write("Hello Sir/Madam, "+name+", Your registration Number: "+rno+"has been selected due to your english ability: "+a+"Your gender is: "+male1);

}

else if(read1 == true) {

var a="Read";

document.write("Hello Sir/Madam, "+name+", Your registration Number: "+rno+"has been selected due to your english ability: "+a+"Your gender is: "+male1);

}

else if(write1 == true) {

var a="Write";

document.write("Hello Sir/Madam, "+name+", Your registration Number: "+rno+"has been selected due to your english ability: "+a+"Your gender is: "+male1);

}

else if(speak1 == true) {

var a="Speak";

document.write("Hello Sir/Madam, "+name+", Your registration Number: "+rno+"has been selected due to your english ability: "+a+"Your gender is: "+male1);

}

else {

alert("Please provide valid data");

}

}

</script>

</head>


<body>

<form method="POST" action="P12.html">

<table border="2px">

<tr>

<th align="center" colspan="2"><u>User Login Form:</u></th>

</tr>

<tr>

<th>Registeration Number:</th>

<td><input type="text" id="txt_rno" required/></td>

</tr>

<tr>

<th>Name:</th>

<td><input type="text" id="txt_name" required/></td>

</tr>

<tr>

<th>Gender:</th>

<td><input type="radio" name="gen" value="Male" id="male"/>Male

<input type="radio" name="gen" value="Female" id="female"/>Female</td>

</tr>

<tr>

<th>English Ability:</th>

<td><input type="checkbox" name="chk_read" value="Read" id="read" />Read

<input type="checkbox" name="chk_write" value="Write" id="write" />Write

<input type="checkbox" name="chk_speak" value="Speak" id="speak" />Speak</td>

</tr>

<tr>

<td colspan="2" align="center"><input type="button" value="CLICK" onclick="showData()"/>

<input type="reset" value="Reset"/></td>

</tr>

</table>

</form>

</body>

</html>