private void ShellSort(long[] inputArray)
{
    long j, temp = 0;
    int increment = (inputArray.Length) / 2;
    while (increment > 0)
    {
        for (int index = 0; index < inputArray.Length; index++)
        {
            j = index;
            temp = inputArray[index];
            while ((j >= increment) && inputArray[j - increment] > temp)
            {
                inputArray[j] = inputArray[j - increment];
                j = j - increment;
            }
            inputArray[j] = temp;
        }
        if (increment / 2 != 0)
            increment = increment / 2;
        else if (increment == 1)
            increment = 0;
        else
            increment = 1;
    }
}


private void InsertionSort(long[] inputArray)
{
    long j = 0 ;
    long temp = 0 ;
    for (int index = 1; index < inputArray.Length; index++)
    {
        j = index;
        temp = inputArray[index];
        while ((j > 0) && (inputArray[j - 1] > temp))
        {
            inputArray[j] = inputArray[j - 1];
            j = j - 1;
        }
        inputArray[j] = temp;
    }
}
private void HeapSort(long[] inputArray)
{
    for (int index = (inputArray.Length / 2) - 1; index >= 0; index--)
        Heapify(inputArray, index, inputArray.Length);
    for (int index = inputArray.Length - 1; index >= 1; index--)
    {
        SwapWithTemp(ref inputArray[0], ref inputArray[index]);
        Heapify(inputArray, 0, index - 1);
    }
}

private void Heapify(long[] inputArray, int root, int bottom)
{
    bool completed = false;
    int maxChild;

    while((root*2 <= bottom) && (!completed))
    {
        if (root * 2 == bottom)
            maxChild = root * 2;
        else if (inputArray[root * 2] > inputArray[root * 2 + 1])
            maxChild = root * 2;
        else
            maxChild = root * 2 + 1;
        if (inputArray[root] < inputArray[maxChild])
        {
            SwapWithTemp(ref inputArray[root], ref inputArray[maxChild]);
            root = maxChild;
        }
        else
        {
            completed = true;
        }
    }
}
private void SelectionSort(long[] inputArray)
{
    long index_of_min = 0;
    for (int iterator = 0; iterator < inputArray.Length - 1; iterator++)
    {
        index_of_min = iterator;
        for (int index = iterator+1; index < inputArray.Length; index++)
        {
            if (inputArray[index] < inputArray[index_of_min])
                index_of_min = index;
        }
        Swap(ref inputArray[iterator], ref inputArray[index_of_min]);
    }
}
private void QuickSort(long[] inputArray)
{
    int left = 0;
    int right = inputArray.Length - 1;
    InternalQuickSort(inputArray, left, right);
}


// Internal recursive sort algorithm for quick sort
// using divide and conquer. Sorting is done based on pivot
</summary>
private void BubbleSort(long[] inputArray)
{
    for (int iterator = 0; iterator < inputArray.Length; iterator++)
    {
        for (int index = 0; index < inputArray.Length - 1; index++)
        {
            if (inputArray[index] > inputArray[index + 1])
            {
                Swap(ref inputArray[index], ref inputArray[index+1]);
            }
        }
    }
}
 class gpa_cgpa(object):
      arg1 = None
      arg2 = None
      subdata = None
      credits = None
      init_course = 0
      init_credit =0
      total_credit =0
      temp = 0
     

      def getcourse(self):
          self.arg1 = input("No of course you have registered:")
          pass

      def getsubjectdata(self):
          self.subdata = raw_input("Enter the grade:")
          pass

      def getgradedata(self):
          grade = {'s':10,'a':9,'b':8,'c':7,'d':6,'e':5,'u':0,'i':0}
          x=grade[self.subdata]
          return x
   
      def getcredit(self):
          self.credits = input("Enter the credit for a subject :")
          pass

      def gpa(self):
          print "calculate GPA :"
          sem = raw_input("Enter the semester : ")
          self.getcourse()
          if self.arg1 >=2:
             self.calculateGpa()
          else:
            print " In order to calculate Gpa you should have atleast 2 subjects minimum"
          pass
     
      def calculateGpa(self):
          while self.init_course!=self.arg1:
              self.init_course=self.init_course+1
              self.getcredit()
              self.init_credit = self.credits
              self.getsubjectdata()
              self.temp = self.init_credit*self.getgradedata()+self.temp
              self.total_credit=self.total_credit+self.init_credit

          gpa = round((self.temp+0)/(self.total_credit+.0),2)
          print "you have registered for total credits:"+" "+str(self.total_credit)+" "+"and you have acquired GPA:\""+str(gpa)+"\""
          pass
   


      def cgpa(self):
          print  "Calculate your cgpa : "
          semester = input("Enter how many semester cgpa has to be found of :")
          counter =0
          tempinit = 0
          temptotalcredit =0
          while counter!=semester:
                   counter = counter+1
                   print "Please enter the details of the semester"+" "+str(counter)
                   self.getcourse()
                   self.calculateGpa()
                   tempinit = self.temp+tempinit
                   temptotalcredit = temptotalcredit + self.total_credit
                # re-assigning
                   self.arg1=0
                   self.initCourse =0
                   self.temp=0
                   self.total_credits=0
                   print "\n"
               
          cgpa = round((tempinit+.0)/(temptotalcredit+.0),2)
           
          print "you have registered for total credits:"+" "+str(temptotalcredit)+" "+"and you have acquired CGPA:\""+str(cgpa)+"\" "
          pass


if __name__ == '__main__': # main method
    #how to calculate it

    Init = gpa_cgpa() # Creating Instance

    # for calculation of Cgpa (cumulative grade point average)
    Init.cgpa()

    # In Order to calculate Gpa for single semester
    #Init.gpa()
 


Calculate your cgpa:
Enter how many semester cgpa has to be found of: 2
Please enter the details of the semester 1
No of course you have registered: 2
Enter the credits for a subject:4
Enter the grade: a
Enter the credits for a subject:4
Enter the grade: c
you have registered for total credits: 8 and you have acquired GPA:"8.0"


Please enter the details of the semester 2
No of course you have registered: 3
Enter the credits for a subject:4
Enter the grade: b
Enter the credits for a subject:5
Enter the grade: a
Enter the credits for a subject:3
Enter the grade: c
you have registered for total credits: 12 and you have acquired GPA:"8.17"


you have registered for total credits: 20 and you have acquired CGPA:"8.1"    

"""

Previous PostOlder Posts Home