Monday, August 5, 2013

Program to print all prime numbers from 1 to nth number :: logic building 6




typedef enum{false,true} bool;

void main()
{

      int inputNum;
      int count;
      int number;
      int i=0;
      bool flage = true;
     
      printf("Enter the number to print all prime numbers from 1 to :: ");
      scanf("%d",&inputNum);

      for(count = 2; count <=inputNum;count++)
      {
            i = 2;
            for(i = 2 ; i < count;i++)
            {
                  if(count%i == 0)
                  {
                        flage = false;
                       
                        break;
                  }
                 
            }
            if(flage == true)
            {
                  printf("\n%d",i);
                       
            }
            flage = true;
           
      }

      getch();

Program to enter the numbers till the user wants and at the end it should display the count of positive negative and zeros entered : Logic building(5)



      int inputNum;
      int positive = 0;
      int negative = 0;
      int Zero=0;
      int choice;

      do
      {
      printf("\nEnter the number ");
      scanf("%d",&inputNum);
     

      inputNum >= 0 ? (inputNum == 0 ? (Zero +=1) :(positive += 1)) : (negative +=1);

      printf("\nDo you want to enter more number(1/0) : ");
      scanf("%d",&choice);

      }
      while(choice==1);


      printf("\nPositive Number(s): %d \nNegative Number(s): %d \nZero(s): %d ",positive,negative,Zero);


       

Factorial , Armstrong numbers : Logic building (4)

Program to find the Factorial of a number

      int inputNum;
      int i;
      int factorial = 1;
      int value;
      printf("Please Enter Number less than or equal to 10:: ");
      scanf("%d",&inputNum);
     
      if(inputNum <= 10)
      {
      for(i =inputNum; i >= 1 ; i--)
      {
            value = i * factorial;
            printf("\n%d * %d = %d\n" , i,factorial,value);
            factorial = value;

      }
      printf("\nFactorial of %d is %d", inputNum,factorial );
      }
      else
      {
            printf("Please enter number less than or equal to 10");
      }


Program to print out all Armstrong numbers between given numbers

      int inputNum;
      int i;
      int armstrongNum ;
      int j;
      int digit;
      printf("Please Enter Number max limit");
      scanf("%d",&inputNum);

     
      for(i =1; i<= inputNum ; i++)
      {
            armstrongNum = 0;
            j = i;
            while( j > 0)
            {
                  digit = j%10;
                  armstrongNum += digit*digit*digit;
                   j = j/10;
            }
            if(armstrongNum == i)
            {
                  printf("%d\n", armstrongNum);
            }


      }

Program to find out first day of the input year : Logic building (3)


      int dayNum;
      int leapYear4, leapYear100, leapYear400;
      int inputYear;
     
      scanf("%d",&inputYear);
      leapYear4 = (inputYear - 1)/4;
      leapYear100 = (inputYear - 1)/100;
      leapYear400 = (inputYear - 1)/400;

      dayNum = (inputYear + leapYear4 - leapYear100 + leapYear400) %7;

      switch (dayNum)
      {
            case 1 :
                  printf("Monday");
                  break;
                 
            case 2 :
                  printf("Tuesday");
                  break;
            case 3 :
                 
                  printf("Wednesday");
                  break;
            case 4 :
                 
                  printf("Thursday");
                  break;
            case 5 :
                  printf("Friday");
                  break;
            case 6 :
                  printf("Saturday");
                  break;
            case 0 :
                  printf("Sunday");
                  break;
      }

Sunday, August 4, 2013

Program to determine whether the year is a leap year or not :: Logic building (2)


Before writing the program for finding Leap year, I just want to give you a brief history about the leap year and what it is.

It takes the Earth approximately 365 days, 5 hours, 48 minutes, and 46 seconds to circle once around the Sun. Leap Years are needed to keep our calendar alignment with the Earth's revolutions around the sun. So if we didn't add a day on February 29 nearly every 4 years, we would lose almost six hours off our calendar every year. After only 100 years, our calendar would be off by approximately 24 days!



To determine whether a year is a leap year or not , follow the below mentioned algorithm

Algorithm

1.       If the year is evenly divisible by 4, go to step 2. Otherwise, go to step 5.
2.       If the year is evenly divisible by 100, go to step 3. Otherwise, go to step 4.
3.       If the year is evenly divisible by 400, go to step 4. Otherwise, go to step 5.
4.       The year is a leap year (it has 366 days).
5.       The year is not a leap year (it has 365 days).



If the value in cell A1 is this        The formula returns
   ----------------------------------------------------------
   1992                                   Leap Year
   2000                                   Leap Year
   1900                                   NOT a Leap Year


Program to determine whether the year is a leap year or not


      int inputYear;
      printf("Please Enter Year");
      scanf("%d",&inputYear);
      if(inputYear%4 == 0)
            if(inputYear%100 == 0 )
                  {
                        if(inputYear%400 == 0)
                              printf("%d is a Leap Year",inputYear);
                              else
                              printf("%d is  not Leap Year",inputYear);}
            else
            {
                  printf("%d is Leap Year",inputYear);
            }
      else
      {
            printf("%d is not Leap Year",inputYear);


      }


Friday, August 2, 2013

Simple program :: Logic Building (1)


The below program is written in C , I think it's very easy for you guys to convert it into classic ASP.

Program to take input from the user and print a new number by adding one to each of its digits.  


void main()
{
      //Variable declaration

      int Count = 0;
      int NoOfdigits = 1;
      int InputNumber;
      int incri= 1;
      int FinalResult= 0;
      int i;

      //Taking input from the user
      printf("Enter the Number less than 10 digit ::");
      scanf("%i",&InputNumber);

      NoOfdigits = InputNumber;
     
//Calculating the length on input number
      while(NoOfdigits > 0)
      {
            NoOfdigits = NoOfdigits/10;
            Count = Count++;
           
      }
       
      //adding one in each digit of the input number
      for(i = 0 ; i < Count;i++)
      {
            FinalResult += ((InputNumber%10) +1)*incri;
            incri = incri*10;
            InputNumber = InputNumber/10;
      }

      printf("\n%d Final result after adding one in each digit ::",FinalResult);
      getch();

program to find out whether a input number is  an odd number or even number.

      int inputNumber;
      printf("Enter the number :\t");
      scanf("%d",&inputNumber);
     
      if(inputNumber >= 0)
      {
      if(inputNumber%2 == 0)
      {
            printf("Number is Even");
      }
      else
      {
            printf("Number is Odd");
      }
      }
      else
      {
            printf("Invalid Entry");

      }

Tuesday, May 1, 2012

Things that need to be keep in mind about Web Site Design


The biggest difficulty most Web developers face when building sites is that the mental processes involved in writing code, and designing graphics and layout are worlds apart. Developers who can not only write really tight, maintainable code but can also hold their own when it comes to designing company logos and laying out text are white tiger rare.

When I first started building Web sites, there were a few things I got wrong. Here's a list of what they were:

1. Not Everyone Works at 1024x768 Resolutions…

This was the first thing I got wrong.

Just because you've been using 1024x768 resolution on your desktop for the past six years, that doesn't mean other people don't use 640x480 screens.

Designing Web pages that look good at 1024x768 and 640x480 is an extremely difficult art. In short, you have to make the layout stretch and shrink in order to accommodate the user's browser size. Most public sites design for 640x480 resolution, which is why many sites seem to only take up a small region of the page In order to design for 640x480, don't make the elements that make up your page take more than 600 pixels total width. Intranets and private sites tend to have wider pages because they have a good idea of what their audience will be using.

Public sites, typically stick to the 640x480 layout. The magic number of 600 leaves space for the side of the browser and the scrollbars. Also, make sure that the important elements of the page fit into the first 400 pixels that make up the height. Allow 125 to 150 pixels for the left navigation bar (if you have one), leaving 450 pixels for the width content. Remember, you're building pages for iMacs and Linux boxes too.

2. Not Everyone Has 16 Million Colors…

You must design your graphics so they look good in 256 colors. In addition, graphics for logos and buttons, etc., should be in GIF format. In fact, the 256-color limit is not even true. When designing for the Web, you only have available to you 216 separate colors that you know will be there. This is known as the Webmaster Safety Palette and most graphic design programs, like Adobe Photoshop come with a palette that you can import into your graphics to ensure you're using the correct color spread.

3. Not Everyone Uses Internet Explorer

There are a lot of people who use Netscape. There's also a fair difference between Netscape and Internet Explorer, enough to make me have nightmares and spend hours re-engineering presentation code to make a site look cool in both.

4. Not everyone has a high speed internet connection

Luckily, I'm not alone on this one! Many Web developers forget that just because they have a high-bandwidth Internet connection, that doesn't mean everyone else does too. The issue is that if the site is not responsive, visitors to the site will grow frustrated and click out of the site and onto a competitor.

There are five tricks to enhancing the performance of your site:
   
1. Minimal use of graphics. Make sure you use just the right amount of graphics, and make sure that these graphics are as optimized as possible. 

 2. Make pages smaller. Convey just the right amount of information on a page. Don't keep the user waiting around to get all the information he or she needs. If necessary, spread information over a number of pages.   

 3. Keep URLs short. In dynamic sites, this is an interesting one. If you ever look at the URLs on Yahoo, you'll notice that instead of calling a folder "images", they'll call it just "i". The logic behind this is sound - there's no need to write "images" in full if the browser can understand "i". Wherever possible, keep the names of ASP pages and folders as short as possible.   

 4. Avoid the use of ActiveX controls or Java applets. Additional components that need to be downloaded and installed in order for your visitors to get the full benefit of site functionality can frustrate users both through the speed it takes to download the components, and possible problems they may encounter once they have been downloaded.

Tuesday, April 3, 2012

Designing the Model for E-Commerce Application in Classic ASP





In developing the business tier for our application we are going to build a series of objects that we can classify as belonging to one of three distinct groups

  • Infrastructure
  • Service
  • Data


Before we look at the precise objects we'll be building, let's discuss these general groupings.

Infrastructure Objects

Infrastructure objects provide access to the resources that an application will use. In our case, we only need to actively manage one resource - the connection to the database. The application will use more resources, like memory, disk drives, and so on, but the application framework provided by Visual Basic and the Web server (IIS) will do this for us.

One sure way of ensuring the presentation layer code is not allowed to circumvent the business rules is to never allow the ASP code direct access to any of the infrastructure objects. In our case, we do this by creating an object that is only accessible to objects in the model. In other words, this object is private to the model as a whole and the ASP code will not be able to directly access or call methods on it.

One sure way of ensuring the presentation layer code is not allowed to circumvent the business rules is to never allow the ASP code direct access to any of the infrastructure objects. In our case, we do this by creating an object that is only accessible to objects in the model. In other words, this object is private to the model as a whole and the ASP code will not be able to directly access or call methods on it.

Service Objects

Service objects provide access to application services. An application service is defined to be anything that an application can actually do. So, in our case we might have an object that can carry out operations like creating customers, deleting customers, viewing orders placed by a customer, etc. The activities outlined (for example the operation of creating a new customer) will have to conform to certain criteria - business rules.

We may decide that any object in our model can create a customer by calling the appropriate object; additionally we may decide that not only can another object call this object to create a customer but ASP code can as well. It is through these service objects that the presentation layer code can get to the business rules. We'll see more service objects in a little while.

Data Objects

Data objects define single instances of some entity in the system somewhere. This is a deliberately broad description, but in our case it nearly always refers to rows in the database. So, we may have an object to describe a single customer, or a single order, and so on. The advantage of this approach is that it lets you add a great degree of detail to the data objects.

Now we've seen the classifications, let's move on to see how we choose the actual objects we are going to put into our object model.

Choosing the Objects

Now we know what kinds of objects we are going to have in our model, we need to decide what objects will actually make up that model. To do this, we have to go through a process of deciding how the various users of the system will flow through the application. By that we mean that a user on the system will create some form of event (not the Visual Basic type) - they will do something that requires some action.

The Full Object Model for Ecommerce application
Infrastructure objects

Database - This object has a number of uses; it simplifies our database communications (which are subsequently achieved via the ADO Connection object) it provides a couple of extra functions to aid the ordering process, and allows direct access to the ADO Connection object. This object is not directly available to the ASP code.

Service objects

Catalog - This object provides access to the product catalogue. It enables creation of departments and products, and can query manufacturers, suppliers, departments, and products. It can also create instances of the Product data object.

Customers - This object manages customers. It can log a customer into the customers only areas of the site and can create new customers in the database and manage their address and credit card information.

Orders - This object manages orders. It can take a shopping basket and turn it into an order, and it can move an order through the order-processing pipeline It can also return audit trail information.

Search - This object provides a way of searching the product catalogue.

FireAndForget - This object provides a way of sending e-mails to customers and visitors at a given date and time

XML - This object provides a way of publishing data in our database as XML, and importing XML data into our system.

Data objects

Product - This object represents a single product stored in the database. It can return information about itself, get and set dynamic attribute data, and add and return up-sell/cross-sell recommendations.

Customer - This object represents a single customer stored in the database. It can return information about itself, along with stored address and credit card information and orders that have been placed.

Order - This object represents a single order stored in the database. It can return all of its information, including customer, addresses and credit cards, and the data that makes up the order.

Basket - This object represents a single cart (basket) stored in the database. Most often, this object is used to represent the current visitor's basket. It can return its contents and summary information (total price and total quantity), and it can add and remove items from itself.

Thursday, March 15, 2012

Objects vs Components


This article is in continuation with my previous article dated 27 Feb 2012

Components

Building on the idea of object-oriented programming comes component-oriented design, which facilitates even better reuse of the objects we design and build.

Objects vs Components

Objects are created from classes and classes are made up of source code - which is language specific and thus can only be used, easily, in one environment. In contrast components are pre-compiled units of binary code - thus they are language independent.

A component may consist of one object or a collection of objects.

A component based approach to software design enhances the OO approach we first looked at - in the case that a component consists of a group of objects, we can actually define which objects are accessible outside the component (and hence keep some objects restricted to being accessed by other objects inside the component) by defining the interface of the component.

COM

Of course the above section rather glosses over at least one very important topic; how do we get all these components talking to each other? That's where the Component Object Model (COM) comes in - it's Microsoft's standard for allowing objects and components to interact irrespective of the language in which the components were first built. So, using COM technology we can call up a component, and providing we know what interface it has, we can get it to go away and do things for us.

As part of the COM mechanism, components that we create in VB actually have a number of interfaces that are provided as part of the standard architecture in addition to any interfaces we define. We'll discuss this further at the appropriate time, but the important thing to note is that VB fits seamlessly into COM and as VB developers we are insulated from a great deal of complexity.

ActiveX

An ActiveX component is an application that stands alone and lets other applications use the classes and objects it contains.

Active Scripting

ASP pages are able to access ActiveX components through a technology called Active Scripting. We've skated over the previous general theory pretty quickly (as we alluded to, there are whole books written on the subject) but it's probably worth lingering over this particular aspect.

Active Scripting is a reusable scripting engine that, if you want, you can use in your own application. It can be found in use in Active Server Pages (ASP) and Windows Script Host (WSH). Active Scripting is capable of supporting many languages by allowing developers to write supporting language plug-ins.

Active Scripting ships with VBScript (a cut down version of Visual Basic) and JScript. Other vendors have developed PERL plug-ins, as well as support for other languages. Broadly, this means that you can write ASP code in whatever language plug-in you have available, as Active Scripting and the plug-in work together to make the call into the component and, through that call, tell Visual Basic to execute the code contained within the method or property.

ASP works (as illustrated below) by stripping out all of the VBScript code, creating an instance of Active Scripting, and asking it to execute the code on its behalf. ASP presents a set of its own ActiveX components to the context of the script (the environment that the script runs in). So, the Response object we call in ASP is actually an ActiveX component that ships with ASP, and when ASP fires up Active Scripting to run your code, it passes a reference to this component to Active Scripting and asks for it to be made available to your code as Response.


At this point we need to bring in the idea of a type library. A type library is a file that describes an object (here meaning component or control) in a standard format such that anything wanting to make use of that object can find out which classes are accessible (or supported). This type library is actually embedded into ActiveX DLL files created via Visual Basic; however, it's still available to programs interacting with it using COM.

So, when our ASP page attempts to call a method on the Response object, Active Scripting looks at the type information in the type library and determines if the method or property name is valid and, if it is valid, what parameters it takes (the type library is not just a list of the names of the methods and properties - it also includes the parameters that any call has and the possible types of value that can be returned). This inspection of the published information is part of the technology that makes up ActiveX, not Active Scripting.