A program of reverse a number using recursion in C?
(in C#)
string Reverse (string input) {
There are two cases; the recursive case and the trivial case.
The trivial case is when the string has zero or one character. In this case, the reversal of the string is the same.
if (input.Length <=1 ) return input;
For any other string, you can reverse it by reversing the "tail" of the string, and then putting the "head" on the end.
else return Reverse (input.Substring(1)) + input[0];
}
What is the difference between abstract class and static class?
An ADT is simply a base class that has one or more pure-virtual methods. A pure-virtual method is similar to a virtual method except that the ADT need not provide any implementation for that method. Even if it does provide a generic implementation, all derivatives must override that method, even if only to call the generic base class method. This ensures that all derivatives provide their own specialised implementations. A derivative that does not provide an implementation for all the pure-virtual methods it inherits becomes an ADT itself. However any implementations that it does provide can subsequently be inherited by its derivatives (those methods effectively become virtual methods rather than a pure-virtual method). Only classes that provide or inherit a complete implementation of all pure-virtual methods can physically be instantiated.
Going back to our shape class, the shape::draw() method is an ideal candidate for a pure-virtual function since it is impossible to draw a shape without knowing what type of shape it is. However, a circle class would be expected to know how to draw itself thus it can provide the specific implementation for drawing circles. Similarly, rectangles and triangles will provide their own specific implementations. This then makes it possible to store a collection of generic shapes and have them draw themselves without the need to know their actual type; as with all virtual methods, the derivatives behave according to their actual type.
Note that static classes have no need for any constructors, operators or destructors (they have no this pointer since there can never be any instances of the class), thus the compiler-generated default constructor, copy constructor, destructor and assignment operator must all be declared private. Some languages may do this automatically but in C++ (which has no concept of static classes) you must explicitly declare them as such.
While static classes do have their uses, bear in mind that the point of having a class in the first place is in order to instantiate independent objects from the class. Thus the only time you should ever use a static class is when the class data members must exist for the entire duration of the program and you want to ensure there can only ever be one instance of those members. However, for memory efficiency alone, a singleton class would be the preferred method. Moreover, if some or all of the static methods are closely associated with a generic class, then it makes more sense to encapsulate those methods as static members of that generic class rather than as a completely separate static class.
How do you prepare for Dot net certification?
Dot net is most popular programming language for Microsoft .NET Framework. You can go through from the book . Just see professional book by Wrox. The best way is also for industrial training and more you should go through practical often. Now a day online classes are also available.
The C# sharp programming language is a relatively young programming language created by Microsoft. It is heavily influenced by another (and older) programming language called C++, which in itself is often regarded as a succesor to the programming language C. As far to my knowledge C# is only used in order to develop .NET based applications.
How should you Swap 2 numbers in a single line?
Swapping two values in a single statement is made possible through a series of three XOR/assign operations, alternating the operands.
Consider the following declarations:
int x = 0;
int y = 1;
The following statement will swap the values of x and y:
x ^= y ^= x ^= y; // swap
The same statement implemented as a function:
void swap(int &x, int &y){ x ^= y ^= x ^= y; }
What is the C sharp programming language?
While I generally prefer "C" as a more robust language, I also consider anything that is released by Microsoft to be unreliable and likely to fail. Java is the product of Sun Microsystems, and has a very good reputation. While I'm not a Java programmer, I have heard nothing but good reports about Java.
AnswerThese two languages are functionally nearly identical. If one can do something, you can bet that the other can do it just as easily. Each has a huge library of built in packages full of classes to help you solve any problem you need to handle.How do you write a program in c sharp to identify whether a character vowels and consonants?
<html>
<head>
<title>Assignment1</title>
</head>
<body>
Enter the String:<br><br>
<form action="ass1.php" method="post">
Name: <input type="text" name="fname" />
<input type="submit" name="Submit" />
</form>
<?php
if(isset($_POST['Submit']))
{
$vowels=array("a","e","i","o","u");
$length=strlen($_POST['fname']);
$count = 0;
for ($i = 0; $i!= $length; $i++)
{
if (array_search($_POST['fname'][$i], $vowels))
{
$count++;
}
}
}
echo 'There are ('.$count.') vowels in the string ('. $_POST['fname'].')';
?>
</body>
</html>
Write a program to merge two linked list and find out the running time?
#include<stdio.h>
#include<conio.h>
#define null 0
void create();
void display();
void insert();
void delet();
void erase();
void create2();
void display2();
void insert2();
void delet2();
void erase2();
void link1();
void link2();
void merge();
struct node
{
int info;
struct node *next;
}*start,*ptr,*temp,*prev;
struct node2
{
int info;
struct node2 *nex;
}*start2,*ptr2,*temp2,*prev2;
void main()
{
int op;
clrscr();
do
{
printf("\n1.link1\n2.link2\n3.merge\n4.exit");
printf("\nEnter your option");
scanf("%d",&op);
switch(op)
{
case 1:
link1();
break;
case 2:
link2();
break;
case 3:
merge();
break;
case 4:
break;
default:
printf("\nEnter correct option");
}
}while(op!=4);
getch();
}
void create()
{
int data;
printf("\nEnter the data");
scanf("%d",&data);
do
{
ptr=malloc(sizeof(struct node));
ptr->info=data;
ptr->next=NULL;
if(start==NULL)
start=ptr;
else
{
temp=start;
while(temp->next!=NULL)
{
temp=temp->next;
}
temp->next=ptr;
}
printf("\nEnter the data & Press 0 to terminate");
scanf("%d",&data);
}while(data!=0);
}
void display()
{
temp=start;
if(start==NULL)
printf("\nList is empty");
else
{
printf("\nElements of list:\n");
while(temp->next!=NULL)
{
printf("%d\t",temp->info);
temp=temp->next;
}
printf("%d\t",temp->info);
}
}
void insert()
{
int data,pos;
printf("\nEnter data & position to insert the element");
scanf("d",&data,&pos);
temp=start;
ptr=malloc(sizeof(struct node));
ptr->info=data;
while(temp->next!=NULL)
{
if(temp->info==pos)
{
ptr->next=temp->next;
temp->next=ptr;
break;
}
else
temp=temp->next;
}
if(temp->next==NULL)
{
temp->next=ptr;
ptr->next=NULL;
}
}
void delet()
{
int pos,flag=0;
if(start==NULL)
printf("List is empty");
else
{
printf("Enter element to be deleted");
scanf("%d",&pos);
temp=start;
if(start->info==pos)
{
flag=1;
start=start->next;
free(temp);
}
else
{
while(temp->next!=NULL)
{
prev=temp;
temp=temp->next;
if(temp->info==pos)
{
flag=1;
prev->next=temp->next;
free(temp);
break;
}
}
}
if(flag==0)
printf("\nElement is not present in list");
}
}
void erase()
{
if(start==NULL)
printf("\nList is empty");
else
{
while(start->next!=NULL)
{
temp=start;
start=start->next;
free(temp);
}
temp=start;
start=start->next;
free(temp);
printf("list is erased");
}
}
void create2()
{
int data;
printf("\nEnter the data");
scanf("%d",&data);
do
{
ptr2=malloc(sizeof(struct node2));
ptr2->info=data;
ptr2->nex=NULL;
if(start2==NULL)
start2=ptr2;
else
{
temp2=start2;
while(temp2->nex!=NULL)
{
temp2=temp2->nex;
}
temp2->nex=ptr2;
}
printf("\nEnter the data & Press 0 to terminate");
scanf("%d",&data);
}while(data!=0);
}
void display2()
{
temp2=start2;
if(start2==NULL)
printf("\nList is empty");
else
{
printf("\nElements of list:\n");
while(temp2->nex!=NULL)
{
printf("%d\t",temp2->info);
temp2=temp2->nex;
}
printf("%d\t",temp2->info);
}
}
void insert2()
{
int data,pos;
printf("\nEnter data & position to insert the element");
scanf("d",&data,&pos);
temp2=start2;
ptr2=malloc(sizeof(struct node2));
ptr2->info=data;
while(temp2->nex!=NULL)
{
if(temp2->info==pos)
{
ptr2->nex=temp2->nex;
temp2->nex=ptr2;
break;
}
else
temp2=temp2->nex;
}
if(temp2->nex==NULL)
{
temp2->nex=ptr2;
ptr2->nex=NULL;
}
}
void delet2()
{
int pos,flag=0;
if(start2==NULL)
printf("List is empty");
else
{
printf("Enter element to be deleted");
scanf("%d",&pos);
temp2=start2;
if(start2->info==pos)
{
flag=1;
start2=start2->nex;
free(temp2);
}
else
{
while(temp2->nex!=NULL)
{
prev2=temp2;
temp2=temp2->nex;
if(temp2->info==pos)
{
flag=1;
prev2->nex=temp2->nex;
free(temp2);
break;
}
}
}
if(flag==0)
printf("\nElement is not present in list");
}
}
void erase2()
{
if(start2==NULL)
printf("\nList is empty");
else
{
while(start2->nex!=NULL)
{
temp2=start2;
start2=start2->nex;
free(temp2);
}
temp2=start2;
start2=start2->nex;
free(temp2);
printf("list is erased");
}
}
void link1()
{
int op;
start=NULL;
do
{
printf("\n1.create\n2.display\n3.insert\n4.delete\n5.erase\n6.exit");
printf("\nEnter your option");
scanf("%d",&op);
switch(op)
{
case 1:
create();
break;
case 2:
display();
break;
case 3:
insert();
break;
case 4:
delet();
break;
case 5:
erase();
break;
case 6:
break;
default:
printf("\nEnter correct option");
}
}while(op!=6);
getch();
}
void link2()
{
int op;
start2=NULL;
do
{
printf("\n1.create\n2.display\n3.insert\n4.delete\n5.erase\n6.exit");
printf("\nEnter your option");
scanf("%d",&op);
switch(op)
{
case 1:
create2();
break;
case 2:
display2();
break;
case 3:
insert2();
break;
case 4:
delet2();
break;
case 5:
erase2();
break;
case 6:
break;
default:
printf("\nEnter correct option");
}
}while(op!=6);
getch();
}
void merge()
{
if(start==NULL)
{
start=start2;
}
else
{
temp=start;
while(temp->next!=NULL)
{
temp=temp->next;
}
temp->next=start2;
}
temp=start;
if(start==NULL)
printf("\nList is empty");
else
{
printf("\nElements of list:\n");
while(temp!=NULL)
{
printf("%d\t",temp->info);
temp=temp->next;
}
}
getch();
}
the above listed program is definitely good one, here is a program which just does merging job, http://www.refcode.net/2013/02/merging-linked-lists.html
C sharp dot net example programs for beginers?
using System;
using System.Collections.Generic;
using System.Text;
namespace Average_of_three_Nos
{
class Program
{
static void Main(string[] args)
{
string no1, no2, no3;
int n1, n2, n3;
int average;
Console.WriteLine("Enter First Number");
no1 = Console.ReadLine();
n1 = Int32.Parse(no1);
Console.WriteLine("Enter Second Number");
no2 = Console.ReadLine();
n2 = Int32.Parse(no2);
Console.WriteLine("Enter third Number");
no3 = Console.ReadLine();
n3 = Int32.Parse(no3);
average = (n1 + n2 + n3) / 3;
Console.WriteLine("Average of three Numbers : "+ average);
}
}
}
Program #2:This program will take two positive numbers as its input and then find GCD of them.
using System;
using System.Collections.Generic;
using System.Text;
namespace GCD
{
class Program
{
static void Main(string[] args)
{
Program obj = new Program();
string no1, no2;
int n1, n2;
Console.WriteLine("Enter First Number");
no1 = Console.ReadLine();
n1 = Int32.Parse(no1);
Console.WriteLine("Enter Second Number");
no2 = Console.ReadLine();
n2 = Int32.Parse(no2);
int g=obj.find_gcd(n1, n2);
Console.WriteLine("GCD=" + g);
}
int find_gcd(int a, int b)
{
int c;
if(a
{
c = a;
a = b;
b = c;
}
while(true)
{
c = a%b;
if(c==0)
return b;
a = b;
b = c;
}
}
}
}
Write an algorithm to find the greatest number out of the gioven four numbers?
In C#: int[] list = new int[] { 1 , 2, 3, 4}; int highest = int.MinValue; foreach(int i in list) { if(i > highest) { highest = i; } } Console.WriteLine(highest.ToString() + " is the highest number");
Can you use c plus plus instead of c sharp in aspnet?
No, not directly. But maybe yes indirectly
The code behind languages of a web page in asp.net are either VB.NET or C#.
No, you cannot develop / write codes in C++ in these code-behind
You still can call out to some components written in C++ from these code-behind pages via C# or VB.NET codes
What is the Difference between virtual methods and non virtual methods in c sharp?
A function is a method that returns a value other than void. Methods includes functions, subroutines, constructors, destructors, and properties.
Can anyone 1 pls give a real time example and usage of abstract class and interface in c sharp?
Abstract classes and Interfaces are both examples of contracts with no default implementation. Interfaces are more readily interchangeable between applications (because they can be interpreted as jump tables). Because of this COM in Windows makes heavy usage of interfaces with several master ones being the source of all functionality (e.g., IUnknown).
If a programmer wanted to define a type of thing (e.g., MusicalInstrument), that had certain abilities (e.g. Play) without defining how a MusicalInstrument plays... This could be done with an Interface or an Abstract class.
If the programmer wanted to provide some base functionality to whomever was going to implement this functionality (e.g., Vloume, Output Stream) then this would be more appropriate for an Abstract class.
Abstract classes can even build on interfaces:
public interface IMusicalInstrument
{ void Play(); }
public abstract class MusicalInstrument:IMusicalInstrument
{ private int vol = 10;
public virtual SetVolume(int newVol){vol = newVol;}
public abstract void Play(); }
public class Horn:MusicalInstrument
{ public override void Play(){//* Play something *//} }
Write a program to generate uppercase using cSharp?
string s = "asdfqwer";
s = s.ToUpper(System.Globalization.CultureInfo.CurrentCulture);
Where can you get a Jetbrains ReSharper discount?
The best place to check for Jetbrains discount is the Jetbrains website. The company often offers discounts and specials, especially for the those starting a software business.
What does the 'does not exist in current context' error mean in c sharp?
It means you are trying to modify an entity from outwith the scope of that entity. The following shows an example:
public void button1_Click(object sender, EventArgs e)
{
int x = 42;
timer1.Start();
}
public void timer1_Tick(object sender, EventArgs e)
{
if (x==42) // error: x does not exist in current context
{
// do something...
}
}
Here, the x variable is declared local to the button1_Click event. That is; it is scoped to that function and is only accessible within the context of that function. The timer1_Tick event is a separate function, outwith the scope of the button1_Click event. As such, the timer1_Tick function cannot access x.
In order for both functions to access variable x, that variable must be declared in a scope that is accessible to both functions. Given that both functions are members of the same class, it would make sense to declare x at class scope:
int x = 0;
public void button1_Click(object sender, EventArgs e) {
x = 42;
timer1.Start();
}
public void timer1_Tick(object sender, EventArgs e)
{
if (x==42)
{
// do something...
}
}
Note that the point of declaration defines the scope of the declared entity and that the scope defines the context in which that entity is visible.
How do you unchecked the selected radio button in Visual Studio?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
...
if (radioButton1.Checked == true)
{
radioButton2.Select();
MessageBox.Show("dione");
}
It means Terminate-Stay-Resident. A TSR is a program that remains in memory when the program ends.
What is the code to retrieve data from sql in Net?
at the top
using System.Data.SqlClient;
in the main body (perhaps a click event)
//creates a connection object with a given connection string
SqlDataConnection conn = New SqlDataConnection("connection String");
//creates a command object with the sql and the connection it is to use
SqlCommand cmd = new SqlCommand("SQL String",conn);
//create a data reader to store the data retrieved from the database
SqlDataReader rdr;
//open the connection
conn.Open();
//executes the sql and stores the result in the rdr (Use if there is more than one //cell retrieved from database e.g all records where a value is greater than 0
rdr = cmd.ExecuteReader();
//if there is only one cell retrieved such as only the orderid for a specific order then //use:
variable = cmd.ExecuteScalar();
//then do something with the data WARNING: the connection MUST be open to use the data reader but not with the scalar method
//close the connection
conn.Close();
Hope this helps!
steve
Which situation constructor is used?
Constructor is necessary when you are about to use instance of a class.
Can methods in c sharp declared outside the class?
C# is a completely object-oriented language, everything is an object.
Every datatype, is a superset of the object class.
I'm sorry to say, but every method must be declared inside of a class. :(
What is socket programming in C?
There is nothing called "socket programming in C."
Sockets can be programmed in any programming language. What follows below is a basic idea on how to program sockets.
Socket programming refers to the use of a set of APIs for sending and receiving data over a network. The socket APIs originated on the BSD OS standardized by POSIX and are now found on UNIX, Linux, Windows, and Mac OS.
The concept of a socket is an abstraction for an end point in network communication through which data can be sent to and received from.
The major socket API functions are:
* socket() -- creates a socket of specified type and protocol * bind() -- assigns a local name or address to the socket (in the IP protocol this is usually an IP address and port * connect() -- connects a socket to a remote end point * listen() -- changes the socket's state to listen for incoming connections * accept() -- accepts an incoming connection and returns a new socket for communication over that connection * send() -- send data to remote end point specified with connect() call * sendto() -- in connectionless protocols such as UDP, sends data to a specified remote end point * recv() -- receive data from remote end point (after connection established) * recvfrom() -- receive data from a specified remote end point in connectionless protocol * getsockopt() -- gets current value for a particular socket option
* setsocketoption() -- set value of a particular socket option
How would you define Continue statement?
A continue statement is used to "branch" to the end of a loop without exiting the loop. If we wish to exit the loop entirely, use a break or return statement.
for (int i=1; i<10; ++i) {
if (i==5) continue;
printf (%d ", i);
}
printf ("\n");
The above loop will print the following:
1 2 3 4 6 7 8 9