Showing posts with label IT Programming. Show all posts
Showing posts with label IT Programming. Show all posts

Monday, October 21, 2013

I need to produce output like this. in first line there should be 1 esoteric (*), in 2nd line 3 esoteric (***), in 3rd line 5 esoteric (*****), in 4th line 7 esoteric (*******), and then decreasing to 5, 3 and 1 esoteric in c++.

i think you need output like this.
*
***
*****
*******
*****
***

*
here is its c++ code.

#include <iostream>
using namespace std;

void main()
{
int row,star,star2;
for(row=1;row<=7;row++)
{
    if(row<=4)
                {             
                for(star=1;star<=2*row-1;star++)
                   {
                      cout<<"*";
                   }
                }
   if(row>=5)
                {
           for(star2=1;star2<=15-2*row;star2++)
                 {
                   cout<<"*";
                  }
               }

 cout<<endl;

}
}

it is just easy to understand , i hope you will learn it.

Friday, October 11, 2013

I need to calculate LCM of two numbers. There should be two classes written for it, PrimeFactor and LCM. I am badly stuck in its implementation. can someone help me please?

Here is code according to your requirement. it is running and easy to understand code. 

#include <iostream.h>

class PrimeFactor   //prime factor class
{
public:

       int number;
       int A[10];
       int B[10];
       int size;

       int* Prime_Factor()   //prime factor function
       {
              int PN[6]={2,3,5,7,11,13};
              int j=0, i=0;
             
              int x=number;
              while (x!=1)
              {
                     if ((x%PN[j])==0)
                     {
                           x=x/PN[j];
                           A[i]=PN[j];
                           i++;
                     }
                     else
                           j++;  
              }
              size=i;
              return A;
       }
};
class LCM:public PrimeFactor //LCM class inheriting PrimeFactor Class
{
public:
       int Calculate_LCM(LCM help)   //function to calculate LCM
       {
              int lcm=1;
              for (int i=0;i<this->size;i++)                  //For First Prime Factors Array
                     for (int j=0;j<help.size;j++)            //For Second Prime Factors Array
                     {if ((this->A[i])==(help.A[j]))  //Pairing
                                  if (this->A[i]!=0)
                                         {
                                                lcm=lcm*this->A[i];
                                                this->A[i]=0;
                                                help.A[j]=0;
                                 

                     }}
                     return lcm;
       }
};
void main()
{
       LCM P1, P2;
       int*k1;
       cout<<"\nEnter a number: ";
       cin>>P1.number;
       k1=P1.Prime_Factor();             //Prime Factors for First Number
       cout<<"The Factors of "<<P1.number<<" are:"<<endl;
       for (int i=0;i<P1.size;i++)
       {
                     cout<<*k1<<"  ";
                     k1++;
       }
       int*k2;
       cout<<"\nEnter a number: ";
       cin>>P2.number;
       k2=P2.Prime_Factor();             //Prime Factors for Second Number
       cout<<"The Factors of "<<P2.number<<" are:"<<endl;
       for (i=0;i<P2.size;i++)
       {
                     cout<<*k2<<"  ";
                     k2++;
       }
       int a;
       a=P1.Calculate_LCM(P2);
       cout<<endl<<"The LCM is "<<a<<endl;//Passing Prime Factors of First and Second Number to LCM Function


Monday, September 23, 2013

What is Wickr? What are its benefits as compared to facebook and other social media forums and messengers?

Wickr is messaging software that is believed to be more secure for messaging and file sharing online as compared to Skype, Facebook and SnapChat. It is claimed by developers of Wickr that Wickr does not collect any personal information of users nor the messages and files shared by Wickr can be read, hence allowing people to maintain their security from spying from thieves and rogue government. It has the logo that private correspondence is a universal human right and there must be means of private communication through technology.
Wickr has previously developed its version for Apple devices and now has released its software tailored for smart phones and tablets running on android OS. This release of version for android has great challenges from governments and corporation because such software can help people to carry on crimes without being caught.
The number of users and details has not yet been released by Wickr but it is reported that the use of Wickr is growing exponentially since releasing a free version for Apple mobile devices. Wickr's business plan is to have hundreds of millions of people globally use free versions of the application while a small percentage opt to pay for premium features such as being able to control larger data files.

Saturday, September 21, 2013

What is Biometrics? What are its applications?

Biometrics involves identification of a person by biological markers like fingerprints, facial features and irises. In the past the concept was present just in science fiction movies but today the advancement in computers have made it possible to come into reality. It was a very expensive technology that was used by security agencies and military but today it is present in ATM’s , schools and hospitals.

This technology is becoming so common that Apple’s latest iPhone 5s has included a feature to unlock its phone using fingerprint. The Android operating system has simplified the process with a feature called “face unlock,” that opens the phone by facial recognition. The Ice-cream sandwich 4.0 Android Operating System has a face unlock security system that is a bit mature and has passed the demo stage. Although there is a possibility that similar looking people may unlock your phone but in future more improvements are expected and will become a breakthrough in biometrics application. The security of a device is improved by biometrics because passwords can be hacked and private information can be leaked.
But it must also be realized that biometrics are also risky as it seems. Biometrics identifies people within certain degrees of certainty. It is also common that people leave their fingerprints on everything they touch that can be copied and used by criminals to set someone else up for their crimes. And once compromised, fingerprints cannot be reset, like passwords, or replaced, like passports.

Friday, September 6, 2013

What are differences between Thread and Process and what is the syntax to use threads in ASP.NET?

A process is an executing instance of an application while a thread is a path of execution within a process. For example, when you open Microsoft Word, you start a process that runs Word. A process can consist of multiple threads. When you start Word, the operating system creates a process and begins executing the primary thread of that process. A thread can do anything a process can do.

Here’s a summary of the differences between threads and processes:

1. Threads are easier to create than processes because they don't require a separate address space and share the same address space within a process whereas processes don’t share the same address space or heap memory.

2. Multithreading requires careful programming since threads share data structures (which allow them to read from and write to the same data structures) that should only be modified by one thread at a time.  Unlike threads, processes don't share the same address space. Communication between processes also known as inter-process communication (IPC) is also quite difficult and resource-intensive.
   
3. Threads are considered ‘lightweight’ because they use far less resources than processes and are used for small tasks while processes are used for more ‘heavyweight’ tasks basically for the execution of applications.
   
4. Processes are independent of each other but as threads share the same address space are interdependent. So, caution must be taken to prevent threads step over each other.
   
A common use for multithreading or multiprocessing is to maintain a responsive user interface for users while a time-consuming task executes. If the time-consuming task runs on a parallel "worker" process or thread, the main thread is free to continue processing keyboard and mouse events.

You can create and run following sample program to see the application of threads:

using System;
using System.Threading;
class TestThread
{
  static void Main(  )
  {
    Thread t = new Thread (WriteThreadB);          // Kick off a new thread
    t.Start();    // running WriteThreadB (  )
    // Simultaneously, do something on the main thread.
    for (int i = 0; i < 1000; i++)
       Console.Write ("Thread A ");
  }
  static void WriteThreadB (  )
  {
      for (int i = 0; i < 1000; i++)
          Console.Write ("Thread B");
  }
}

Monday, September 2, 2013

What is the difference between Server.Transfer() and Response.Redirect()?

In ASP.Net, both "Server" and "Response" are objects of ASP.Net. Server.Transfer() and Response.Redirect() both are used to transfer a user from one page to another page. But there are some significant dissimilarities between both the objects which are as follow:

 1.Response.Redirect() is used to redirect the user’s browser to another page or site, update the address bar and add it to the browser history. On your browser you can click back whereas Server.Transfer() does not change the address bar, we cannot hit back. You should use Server.Transfer() when you don’t want the user to see where he is going, mostly on a "loading" type page.

 2.Response.Redirect() redirects the request to some plain HTML pages on our server or to some other web server while Server.Transfer() transfers current page request to another .aspx page on the same server.

 3.Response.Redirect() performs additional round trip back to the client where the client’s browser is redirected to the new page. On the other hand, Server.Transfer() preserves server resources and avoids the unnecessary round-trip to the server so this provides a faster response with a little less overhead on the server.

 4.Response.Redirect() doesn’t preserve Query String and Form Variables from the original request while Server.Transfer() reserves Query String and Form Variables (optionally).

 5.Response.Redirect() enables to see the new redirected URL where it is redirected in the browser (and be able to bookmark it if it’s necessary). The user’s browser history list is updated to reflect the new address whereas Server.Transfer() doesn’t show the real URL where it redirects the request in the users Web Browser.

 6.Response.Redirect() simply sends a message down to the (HTTP 302) browser however, Server.Transfer() happens without the browser knowing anything, the browser request a page, but the server returns the content of another.

 I hope this article will be helpful for you!

Tuesday, August 20, 2013

What is C++? List down the main differences between C and C++?

C++ is a powerful general-purpose and object-oriented programming language created by Bjarne Stroustrup, released in 1985.  It can be used to create small programs or large applications. It can be used to make CGI scripts or console-only DOS programs. C++ allows you to create programs to do almost anything you need to do. The C and C++ programming languages are closely related.

The C and C++ programming languages are closely related. Basically, C++ produced out of C. But C++ introduces many new features that are not available in C. This article mainly focuses on differences between C and C++.

Differences:

1.      C++ is a Compiled Language whereas C is an Interpreted Language
Compiled languages are translated to the target machine's native language by a program called compiler. Only once program needs to be compiled then it resides in complied form and results in Fast execution especially if the compiler is effective at optimizing.

Interpreted languages are read by a program called an interpreter and are executed by that program. Interpreted languages are usually much slower than an equivalent compiled program because interpret need to translate code to that machine code every time program executes.
So, C++ is faster than C Language.

2.      C++ is an Object Oriented Language while C is a Procedural Language
C follows the procedural programming paradigm while C++ is a multi-paradigm language (procedural as well as object oriented) which means functions are the building blocks of a C program while objects are building blocks of a C++ program.

3.      Syntax Differences:
Both C and C++ have different syntax. Let's look at a simple working "Hello World" program which says "hello" to the users of your software or application:

//C hello world example
#include <stdio.h>
 int main()
{
  printf("Hello World\n");
  return 0;
}

//C++ hello world example
#include <iostream>
 using namespace std;
 int main()
{
  cout<<" Hello World!\n";
  cin.get();
}

4.      The “NAMESPACE” feature in C++ is not available in C
C++ uses NAMESPACE which avoids name collisions. For instance, two courses offered in the same university cannot have the same course code while two courses in different universities might have the same course code. The universities are two different namespaces and hence contain the same course codes (identifiers) but the same university (one namespace) cannot have two courses with the same code (identifier).

5.      C++ is Type-Safe but C is not
Unlike C, C++ is a strongly typed called a type-safe language. Type Safety is the extent to which a programming language avoids type errors. A type error is flawed or undesirable program behavior caused by the inconsistent data types for the program's constants, variables or functions for example, assigning a floating variable (float) to an integer variable (int) in C++ is not allowed.

6.      C++ allows using functions inside Structures while C does not
In case of C++, functions can be used inside a structure while structures cannot contain functions in C.

7.      C++ supports function overloading while C does not
Overloading means two functions having the same name in the same program. This can be done in C++ with the help of Polymorphism whereas C does not support this feature of OOP.

8.      C++ allows the use of reference variables while C does not
Reference variables allow two variable names to point to the same memory location. We cannot get benefit of this feature in C language.

9.      Exception Handling is not supported by C but C++ provides support for it
C does not support exception handling “properly” but it can always be implemented by other methods.

10.  new[] and delete[]
In C, there's only one main memory allocation function “malloc()”. You use it to allocate memory to both single elements as well as arrays. Here is sample code:

int *x = malloc( sizeof(int) );
int * TestArray = malloc( sizeof(int) * 10 );

and you always release the memory in the same way as below:

free( x );
free(TestArray);

In C++, however, memory allocation for arrays is somewhat different than for single objects; you use the new[] operator and you must match calls to new[] with calls to delete[].

int *x = new int;
int *TestArray = new int[10];
delete x;
delete[] TestArray;

The short explanation is that when you have arrays of objects, you need to use delete[] to properly call the destructor for each element of the array, whereas delete will not work for arrays.

Monday, August 12, 2013

What are functions and why do we use them? What is meant by function overloading?

Function is a chunk of statements called from some other part of a program. It is easy to organize program through functions. It can reduce programming mistakes and code repetition. Additionally, it can enhance code readability and we can trace errors easily. There are three things to keep in mind for writing a function in our program:

1. Function prototype
2. Fnction call
3. Function definition

Function prototype should be before function call so that compiler can have knowledge of function before calling instruction (otherwise it will raise error). Function definition syntax is as follows:

 return-type function-name( datatype parameter1, datatype parameter2, ...)
 { statements }

Where: return-type is the data type of the data returned by the function. Function-name is name of function. parameters (you can specify any number of parameters) statements are the commands. It is a block of statements surrounded by braces { }.

 Lets write a sample code of adding two numbers with the help of function.

#include void add (int int); //function declaration 
void main() 
{ 
int x,y; 
cout<<"enter two numbers for addition"; 
cin>>x>>y; 
add(x,y); ///function call
} 

void add(int a,int b) //function definition
{
int c;
c=a+b;
cout<"addition of two numbers is"<<c;
}

This is a simple code. You can do many other complex examples also for understanding functions.
now functions can be of different types. these are function pass by value, function pass by reference, inline function and function overloading.

Function overloading, (as the name is reflecting overloading means more than one) is concept where we can write more than one function having same name in one program. such as i can write one more add() function in above program. But there are certain rules for it. you must fulfill at least any one of following condition.

1. No of function arguments should be different OR
2. Type of at least one argument should be different OR
3. Return type of functions should be different.

Here is modified version of above add() function. Now i want to add not only two int numbers but i also want to do the same task but with float and double numbers. Here is the code:

#include<iostream.h>
void add (int,int); //first function declaration
void add (double,float); // second function declaration
void main()
{
int x,y;
double d;
float f;
cout<<"enter two numbers for addition";
cin>>x>>y;
cout<<"enter more two numbers for addition";
cin>>d>>f;
add(x,y); ///function call
add(d,f); /second function call
}
void add(int a,int b) //function definition
{
int c;
c=a+b;
cout<"addition of two numbers is"<<c;
}

void add(double a,float b) //function definition
{
double c;
c=a+b;
cout<"addition of two numbers is"<<c;
}

I hope it will have clear now the concept of basic function and function overloading.

Wednesday, August 7, 2013

What are .NET Assemblies? What is the difference between Private, Shared and Satellite Assembly? How to view Assemblies meta data?

In any programming environment, it is actually essential to be able to encapsulate dedicated functionality in libraries. We like to build such modules that can be kept at one place and used in different locations. To achieve this, “Assemblies” concept has been introduced into .net framework that can be part of a single or shared application.

Assemblies are primary building blocks of .NET Framework applications that contain Metadata, manifest and Intermediate Language Code. They form the fundamental unit of deployment, version control, reuse, activation scoping, and security permissions. An assembly is a collection of types and resources that are built to work together and form a logical unit of functionality. An assembly provides the common language runtime with the information it needs to be aware of type implementations.

An assembly performs following key functions:

1. It contains MSIL code and assembly manifest that the common language runtime executes. Each assembly can have only one entry point (that is; DllMain, WinMain, or Main).
2.  An assembly is the unit that forms a security boundary at which certain permissions are requested or granted that assembly requires.
3.  It forms a type boundary which means every type's identity includes the name of the assembly in which it resides. A type called TypeA loaded in the scope of one assembly is different than a type called TypeA loaded in the scope of another assembly.
4.  It forms a reference scope boundary. The assembly's manifest contains assembly metadata that is used for resolving types and filling resource requests. It identifies the types and resources that are exposed outside the assembly. The manifest also counts other assemblies on which it depends.
5.  It forms a version boundary. The assembly is the smallest versionable unit in the common language runtime; all types and resources in the same assembly are versioned as a unit. The assembly's manifest describes the version dependencies you specify for any dependent assemblies.
6. It forms a deployment unit. When an application starts, only the assemblies that the application initially calls must be present. Other assemblies, such as localization resources or assemblies containing utility classes can be retrieved on demand. This allows applications to be kept simple and thin when first called. 
7. It is the unit at which side-by-side storage and execution of multiple versions of an application or component is supported by different versions of the same assembly.

There are three types of assemblies as:

a. Private Assemblies: are accessible by a single application. They reside within the application folder and are unique by name. They can be directly accessed by keeping them to the bin folder.
b. Shared or Public Assemblies: are shared between numerous applications to ensure reusability. They are located in Global Assembly Cache.
c. Satellite Assemblies: are assemblies to provide support for multiple languages based on diverse cultures. These are kept in different modules based on the different categories available.

View Assemblies Meta Data:

Assemblies meta data can viewed with all the methods and types in a tree representation by the tool Intermediate Language Disassembler (ILDASM).

Tuesday, August 6, 2013

What is the main difference between .toString() and Convert.toString()? When to use which method?

“.ToString()” and "Convert.toString()"  are the major formatting methods in the .NET Framework which are used to convert an object to its equivalent string representation so that it is suitable for display or use as a string. It's important to understand the behavior and differences of both the methods to determine when to use what. Here are the differences:

Differences:

1.       “Object.ToString()” is a virtual function in the base class Object. Any class can override .ToString() to provide its own implementation whereas “Convert.ToString()” is a static method that attempts to take many different arguments and convert them into a meaningful string.
2.       The key different between both is that "Convert.toString()" function handles NULLS whereas “.ToString()” does not handles NULL values and throws a NULL reference exception when used for NULLS. So, good developers always use “Convert.toString()” which is more safer. 
3.        When “Convert.ToString()” is applied on a string value it simply returns the value while .ToString() on a sting returns this (a reference to the string itself).
4.       The “Convert.ToString()”, when called on an object will try to convert it via IConvertible interface first, if this fails and the object is not null then it will call the .ToString() on the object. If the object reference is null it returns an empty string. The default behavior of the .ToString() method on an object is to return the name of the type (this.GetType().ToString()). Calling the .ToString() method directly has less ovehead but we need to perform a null test on object first.

Here is the sample code with comments:

Object obj = null;
String objVal1 = obj.ToString(); //throws Null reference exception
String objVal2 = Convert.ToString(obj);  //returns NULL

What is a Theme? How can i apply Themes to an entire application by writing code just at one place in asp.net application?

A professional and unified graphic theme as well as writing the content with a professional tone is really very imperative for businesses and can add value to the business and customers growth. Basically, a theme is a set of property settings that let you to define the appearance of pages and controls and then apply the look consistently across pages in a single Web application or across all the Web applications residing on a server.

Themes are made up of following set of elements

1.  Skins
2.  Cascading Style Sheets (CSS)
3. Images and other Resources

      Themes are defined in special directory named as “App_Themes” in your Website or on your Web server. This folder contain subfolders consist of files (such as .skin, .css and image files) that defines the appearance of web pages and controls.

Themes can be applied to a page, a web site, or globally to all the websites. Setting a theme at the Web site level applies styles and skins to all the pages and controls used in the website unless you override a theme for an individual page or control. Setting a theme at the page level applies styles and skins to that page and all its controls only.

Here are the possible ways to apply themes in asp.net:

1. In the application's Web.config file, set the <pages> element to the name of the theme, either a global theme or a page theme as shown in the following example:

<configuration>
<system.web>
<pages theme=”Write your theme name here” />
</system.web>
</configuration>

A theme setting in the Web.config file applies to all ASP.NET Web pages in that application. Theme settings in the Web.config file follow normal configuration hierarchy conventions.

2. You can set theme as a style sheet theme as given in below example:

<configuration>
<system.web>
<pages styleSheetTheme =”Write your theme name here” />
</system.web>
</configuration>

3. You can also apply a theme to an individual page. For that, set the Theme or StyleSheetTheme attribute of the @ Page directive to the name of the theme of your choice as shown in the following example:

<%@ Page Theme="ThemeName" %>
<%@ Page StyleSheetTheme="ThemeName" %>

I hope this will help you!

Sunday, August 4, 2013

What is exception handling? How to handle exceptions at page level as well as application level by writing code at one place only?

Discovering and handling the parts of a program that are most likely to produce errors at execution time is called exception handling. A well-designed set of error handling code blocks can make a program or software more robust and less inclined to crashing because the application handles such errors. An unhandled exception causes the abnormal termination of the program and may result in data loss.

.Net provides an elegant way to handle runtime errors with the help of the try, catch, and finally keywords to handle page level errors. Here is the sample code:

public class ExceptionHandlingExample
{  
   public void DoWork()
    {    
        // Do some work that might throw exceptions.
    }
    public void MethodWithHandler()
    {
        try
        {
            DoWork();
        }
        catch (Exception e)
        {          
              // Handle the exception and continue executing.
        }
    }
}

You can handle default errors at the application level by adding an Application_Error handler in the Global.asax file of your application and a customErrors section to the Web.config file. A generic custom error page for most runtime errors is highly recommended. The customErrors section allows you to specify a default page where users will be redirected to when an error occurs. Here is the code section you need to write or modify in your Web.config file:

<configuration>
  <system.web>
    <customErrors mode="On" defaultRedirect="ErrorPage.aspx?handler=customErrors%20section%20-%20Web.config">
      <error statusCode="404" redirect="ErrorPage.aspx?msg=404&amp;handler=customErrors%20section%20-%20Web.config"/>
    </customErrors>
  </system.web>
</configuration>

To get error details on custom error page, Write following code in Global.asax file:

void Application_Error(object sender, EventArgs e)
{    
    Exception exc = Server.GetLastError();
    if (exc is HttpUnhandledException)
    {   
       // Pass the error on to the error page.
        Server.Transfer("ErrorPage.aspx?handler=Application_Error%20-%20Global.asax", true);
    }

}