+ All Categories

maggu

Date post: 08-Nov-2014
Category:
Upload: manoj-kumar-jawlia
View: 59 times
Download: 47 times
Share this document with a friend
Popular Tags:
40
SUBMITTED TO: SUBMITTED BY: 1
Transcript
Page 1: maggu

SUBMITTED TO: SUBMITTED BY:Mrs. DEEPA GANGWANI YOGESH MAGGU

06315104411

1

Page 2: maggu

ACKNOWLEDGEMENT

I wish to thanks all the people who have directly or indirectly contributed towards the successful completion of this work.

First and Foremost, I wish to acknowledge the valuable guidance . I received from my teachers especially Mrs. Deepa Gangwani for his valuable suggestions and all time guidance during my lab duration and outside or inside the class.

I am also thankful from the core of my heart to my fellow classmates and friends, who have assisted me in creating and completing this project without which it would have very difficult for me to accomplish the assigned task.

INDEX2

Page 3: maggu

S. No

PROGRAMS

Page

No.

Sign.

1. W.A.P to print C# Programming on screen. 6

2. W.A.P to add two numbers. 7

3. W.A.P of Fibonacci series 8

4. W.A.P to find even and odd number. 10

5. W.A.P to add marks of student in five subjects and display their his/her details in the following format :

Name :Class :Total Marks :Percentage

12

6. W.A.P for the following in an interactive manner 1. Prime Number2. Factorial3. Table Generation4. Exit

14

7. W.A.P to print following output122333444455555

16

8. W.A.P to find whether a given number is Amstrong or not

18

9. W.A.P to input salary of 10 employees and find the enhanced salary of employees with 15% raise in

20

3

Page 4: maggu

their salaries.

10. Define a class library which includes of the following data members.

Title_bookAuthorB_codeDate_issuedDate_returned

Member Functions:Read_dataCompute_dataShow_data

If the library account holder did not returned the book within 7 days from the date the book issued, then compute fine @ Rs. 20 per day and show the record.

21

11. Mars is approx 34 miles away from earth. Assume there is someone on mars you want to talk with, what is the delay between the time a radio signal leaves earth and the time it arrives on mars. Suppose that the light travel approx 18600 miles per second. Now compute the delay, you will need to divide the distance by the speed of light. Display the delay in terms of second and minutes

23

12. W.A.P that display the truth table for C#’s logical operator (i.e. AND,OR,XOR,NOT)

24

13 Input the principal, the length of time, number of payments per year and the interest rate from user. Compute the regular payments on a loan by using

26

4

Page 5: maggu

following formula:

Payment= IntRate*(Principal/pay per year) ____________________________

1-((IntRate/PayperYear)+1)Payperyear*Numyears

14. W.A.P of Bubble Sort. 28

15. W.A.P that reads character from the keyboard. Convert lower case letter to uppercase and all uppercase characters to lowercase, display the result make no changes to any other character. The program should stop when the user presses the period key

29

16. W.A.P that uses an array to find the average of ten double values. Use any double values

30

17. Write a recursive method that display the content of a string backwards

31

Q1. Write a program to print C# Programming on screen.

PROGRAM :-

5

Page 6: maggu

using System;

class Nothing{

public static void Main(String []args){

Console.WriteLine("This is First C# Program "); }}

OUTPUT

Q2. Write a program to add two numbers.

PROGRAM :-

using System;class Add{

6

Page 7: maggu

static void Main(){

int n,m;

Console.WriteLine("Enter first number ");

n=int.Parse(Console.ReadLine());

Console.WriteLine("Enter second number ");

m=int.Parse(Console.ReadLine());

Console.WriteLine("The Addition is "+(n+m));}

}

OUTPUT

Q3. Write a program of Fibonacci series.

PROGRAM :-

using System;

class Fibbo

7

Page 8: maggu

{public static void Main(String []args){

int n,a=0,b=1,c=0;Console.WriteLine("enter the limit ");n=int.Parse(Console.ReadLine());for(int i=0;i<n;i++)

{ Console.Write(c+",");

a=b;b=c;c=a+b;

} }}

OUTPUT

Q4. Write a program to find even and odd number.

PROGRAM :-

using System;

8

Page 9: maggu

class EvenOdd{

static void Main(){

int n;Console.WriteLine("Enter a Number ");n=int.Parse(Console.ReadLine());if(n%2==0)Console.WriteLine(n+" is even");elseConsole.WriteLine(n+" is odd");}

}

OUTPUT

Q5. Write a program to add marks of student in five subjects and display their his/her details in the following format :

Name :Class :

9

Page 10: maggu

Total Marks :Percentage :

PROGRAM :-

using System;

class StudentInfo{

static void Main(){int []marks=new int[5];String name;String clas;double p;int tm=0;Console.WriteLine("Enter your name ");name=Console.ReadLine();Console.WriteLine("Enter your class ");clas=Console.ReadLine();for(int i=0;i<5;i++){Console.WriteLine("Enter your Marks in "+(i+1)+" Subject");marks[i]=int.Parse(Console.ReadLine());tm=tm+marks[i];}p=tm/5;Console.WriteLine();Console.WriteLine();Console.WriteLine("Your Details Are:");Console.WriteLine("Name:"+name);Console.WriteLine("Class:"+clas);Console.WriteLine("Total Marks:"+tm);Console.WriteLine("Percentage:"+p);}

}

10

Page 11: maggu

OUTPUT

Q6. Write a program for the following in an interactive manner

1. Prime Number2. Factorial3. Table Generation4. Exit

11

Page 12: maggu

PROGRAM :-

using System;class Interactive{

public void Prime(){int a,i;Console.WriteLine("enter a no.");a=int.Parse(Console.ReadLine());

if(a==2){Console.WriteLine(a+" is prime no.");return;

}for(i=2;i<a;i++){int r;r=a%i;

if(r==0){Console.WriteLine(a+" is not a prime");return;

}}

if(i==a){Console.WriteLine(a+" is a prime no.");}

}public void Factorial(){int n,d=1;Console.WriteLine("enter the number ");n=int.Parse(Console.ReadLine());for(int i=n;i>=1;i--)

{d=n*d;n--;

}Console.WriteLine("The Factorial of the number is="+d);}public void Table(){int n;Console.WriteLine("Enter a no. ");

12

Page 13: maggu

n=int.Parse(Console.ReadLine());Console.WriteLine("The Table is: ");for(int i=1;i<=10;i++)

{Console.WriteLine(n+"*"+i+"="+(n*i));}

}}

class InteractiveMainDemo{

static void Main(){Interactive i=new Interactive();int c;Console.WriteLine("Main Menu");Console.WriteLine("1.Prime Number");Console.WriteLine("2.Factorial");Console.WriteLine("3.Table Generation");Console.WriteLine("4.Exit");Console.WriteLine("Enter ur Choice ");c=int.Parse(Console.ReadLine());

switch(c){case 1:i.Prime();break;case 2:i.Factorial();break;case 3:i.Table();break;case 4:return;break;default:

Console.WriteLine("Wrong Choice");break;}

}}

13

Page 14: maggu

OUTPUT

Q7. Write a program to print following output122333444455555

14

Page 15: maggu

PROGRAM :-

using System;

class Series{

static void Main(){

int n;Console.WriteLine("Enter the limit");n=int.Parse(Console.ReadLine());Console.WriteLine();Console.WriteLine();

for(int i=1;i<=5;i++){

for(int j=1;j<=i;j++){Console.Write(j);

}Console.WriteLine();

} }

OUTPUT

15

Page 16: maggu

Q8. Write a program to find whether a given number is Armstrong or not.

PROGRAM :-

using System;class ArmstongDemo{

static void Main(){int n,m,a,b,c=0;Console.WriteLine("Enter a number ");n=int.Parse(Console.ReadLine());m=n;while(n>0)

{a=n%10;b=a*a*a;

16

Page 17: maggu

c=c+b;n=n/10;}

if(m==c)Console.WriteLine(m+" is armstrong");elseConsole.WriteLine(m+" is not armstrong");}

}

OUTPUT

Q9. Write a program to input salary of 10 employees and find the enhanced salary of employees with 15% raise in their salaries.

17

Page 18: maggu

PROGRAM :-

using System;class EmployeeSalaryDemo{

static void Main(){int []ei=new int[10];double []es=new double[10];

for(int i=0;i<10;i++){Console.WriteLine("enter the emp id of "+(i+1)+"

employee");ei[i]=int.Parse(Console.ReadLine());Console.WriteLine("enter the salary of "+(i+1)+" employee");es[i]=double.Parse(Console.ReadLine());}for(int i=0;i<10;i++){es[i]=es[i]+(0.15*es[i]);}Console.WriteLine();Console.WriteLine();Console.WriteLine("The Details are: ");Console.WriteLine("emp_id\tincreased salary");for(int i=0;i<10;i++){Console.WriteLine(ei[i]+"\t"+es[i]);}

}}

OUTPUT

18

Page 19: maggu

Q-10- Define a class library which includes of the following data members.

Title_bookAuthorB_codeDate_issuedDate_returned

Member Functions:Read_dataCompute_dataShow_data

If the library account holder did not returned the book within 7 days from the date the book issued, then compute fine @ Rs. 20 per day and show the record.

19

Page 20: maggu

PROGRAM :-

using System;class Library{String Book_Title;String Author;int B_Code,diff,fine;int[] d_i=new int[3];int[] d_r=new int[3];

public void Read_Data(){Console.WriteLine("enter the title of the book ");Book_Title=Console.ReadLine();Console.WriteLine("enter the author of the book ");Author=Console.ReadLine();Console.WriteLine("enter the code of the book ");B_Code=int.Parse(Console.ReadLine());Console.WriteLine("enter the issue date:");Console.WriteLine("enter day");d_i[0]=int.Parse(Console.ReadLine());Console.WriteLine("enter month");d_i[1]=int.Parse(Console.ReadLine());Console.WriteLine("enter year");d_i[2]=int.Parse(Console.ReadLine());Console.WriteLine("enter the Return date:");Console.WriteLine("enter day");d_r[0]=int.Parse(Console.ReadLine());Console.WriteLine("enter month");d_r[1]=int.Parse(Console.ReadLine());Console.WriteLine("enter year");d_r[2]=int.Parse(Console.ReadLine());}public void Compute_Data()

{ if(d_i[0]>d_r[0])diff=d_i[0]-d_r[0];

elsediff=d_i[0]-d_r[0];

if(diff<0)diff=diff*-1;if(diff>7)

20

Page 21: maggu

{fine=diff*20;}

}public void Show_Data()

{Console.WriteLine();Console.WriteLine();Console.WriteLine("The Details are:");Console.WriteLine("Book Title "+Book_Title);Console.WriteLine("Author "+Author);Console.WriteLine("Book Code "+B_Code);Console.WriteLine("Book Issued in dd-mm-yyyy

format:"+d_i[0]+"-"+d_i[1]+"-"+d_i[2]);Console.WriteLine("Book Returned in dd-mm-yyyy

format:"+d_r[0]+"-"+d_r[1]+"-"+d_r[2]);Console.WriteLine("Fine Generated "+fine);}

}

class LibraryDemo{

static void Main(){

Library l=new Library();l.Read_Data();l.Compute_Data();l.Show_Data();

}}

OUTPUT

21

Page 22: maggu

Q12. Write a program that display the truth table for C#’s logical operator (i.e. AND,OR,XOR,NOT)

PROGRAM :-

using System;class TruthTables{

public void And(){Console.WriteLine("The AND Table is ");Console.WriteLine("A\tB\toutput");Console.WriteLine("0\t0\t"+(0*0));Console.WriteLine("0\t1\t"+(0*1));Console.WriteLine("1\t0\t"+(1*0));Console.WriteLine("1\t1\t"+(1*1));

22

Page 23: maggu

}public void Or(){Console.WriteLine("The OR Table is ");Console.WriteLine("A\tB\toutput");Console.WriteLine("0\t0\t"+(0+0));Console.WriteLine("0\t1\t"+(0+1));Console.WriteLine("1\t0\t"+(1+0));Console.WriteLine("1\t1\t"+1);}public void Xor(){Console.WriteLine("The XOR Table is ");Console.WriteLine("A\tB\toutput");Console.WriteLine("0\t0\t"+(0*0));Console.WriteLine("0\t1\t"+(0+1));Console.WriteLine("1\t0\t"+(1+0));Console.WriteLine("1\t1\t"+0);}public void Not(){Console.WriteLine("The NOT Table is ");Console.WriteLine("A\toutput");Console.WriteLine("0\t"+1);Console.WriteLine("1\t"+0);}

}

class TruthTablesDemo{

static void Main(){TruthTables t=new TruthTables();int c;Console.WriteLine("MAIN MENU");Console.WriteLine("1.AND Table");Console.WriteLine("2.OR Table");Console.WriteLine("3.XOR Table");Console.WriteLine("4.NOT Table");Console.WriteLine("enter ur choice ");c=int.Parse(Console.ReadLine());

switch(c){case 1:t.And();break;

23

Page 24: maggu

case 2:t.Or();break;case 3:t.Xor();break;case 4:t.Not();break;case 5:return;break;default:Console.WriteLine("Wrong Choice");break;}

}}

OUTPUT

Q13. Input the principal, the length of time, number of payments per year and the interest rate from user. Compute the regular payments on a loan by using following formula:

24

Page 25: maggu

Payment= IntRate*(Principal/pay per year) ____________________________

1-((IntRate/PayperYear)+1)Payperyear*Numyears

PROGRAM :-

using System;class LoanPayment{

static void Main(){int p,t,ppy;double r,v1,v2,v3,v4,v5;Console.WriteLine("Enter the principal ");

p=int.Parse(Console.ReadLine());Console.WriteLine("Enter the time interval ");t=int.Parse(Console.ReadLine());Console.WriteLine("Enter the no. of payments per year ");ppy=int.Parse(Console.ReadLine());Console.WriteLine("Enter the interest rate ");r=float.Parse(Console.ReadLine());r=r/100;v1=r*(p/ppy);v2=(r/ppy)+1;v3=ppy*t;v4=Math.Pow(v2,v3);v5=1-(v1/v4);Console.WriteLine("The regular payments on a loan are "+v5);}

}

OUTPUT

25

Page 26: maggu

Q14. W.A.P of Bubble Sort.

PROGRAM :-

26

Page 27: maggu

using System; class AscendingBubbleSort { public static void Main() { int i,j,t; int []p=new int[10]; int []q=new int[10]; int []c=new int[20]; for(i=0;i<10;i++) { Console.WriteLine("Enter Value"); p[i]=int.Parse(Console.ReadLine()); } for(i=0;i<10;i++) { Console.WriteLine("Enter Value"); q[i]=int.Parse(Console.ReadLine()); } if(j<10) c[j]=p[j]; else c[j]=q[j-10]; for(i=0;i<20;i++) { for(j=0;j<20;j++) { if(c[i]>c[j]) { t=c[i]; c[i]=c[j]; c[j]=t; } } }

27

Page 28: maggu

for(i=0;i<20;i++) { Console.WriteLine (c[i]); } } }

Q15.WRITE A PROGRAM that reads charcter from the keyboard. Convert lower case letter to uppercase and all uppercase characters to lowercase, display the result make no changes to any other character. The program should stop when the user presses the period key.

PROGRAM :-

using System;class ReadString {static void Main() {string str;string str1="";Console.WriteLine("Enter some characters.");str = Console.ReadLine();Console.WriteLine("You entered: " + str);

foreach(char ch in str){

if(Char.IsLower(ch))

28

Page 29: maggu

str1+=Char.ToUpper(ch);elsestr1+=Char.ToLower(ch);

}Console.WriteLine("You formatted new string is: " + str1);}}

OUTPUT

Q16. WRITE A PROGRAM that uses an array to find the average of ten double values. Use any double values.

PROGRAM :-

using System;class DoubleAvg

29

Page 30: maggu

{static void Main(){double[] double_values=new double[10];double s=0,avg;

for(int i=0;i<10;i++){Console.WriteLine("enter "+(i+1)+" value");double_values[i]=double.Parse(Console.ReadLine());s=s+double_values[i];}avg=s/10;Console.WriteLine("the avg is "+avg);

}}

Output

Q17. Write a recursive method that display the content of a string backwards.

PROGRAM :-

using System;

30

Page 31: maggu

class RecursiveString{ public void DisplayReverse(String str)

{if(str.Length>0)DisplayReverse(str.Substring(1,str.Length-1));elsereturn;Console.Write(str[0]);

}}class RecursiveStringDemo{

static void Main(){string s;RecursiveString r=new RecursiveString();Console.WriteLine("enter a string ");s=Console.ReadLine();Console.WriteLine();Console.WriteLine("String before recursion ");Console.WriteLine(s);Console.WriteLine();Console.WriteLine("String after recursion ");r.DisplayReverse(s);}

}

31

Page 32: maggu

OUTPUT

32


Recommended