Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Other Programming > Intro Programming
Password Reminder
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Intro Programming What is a loop? Which language is best for beginners? What is "object oreinted?" All those types of questions and more are welcome here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Intro Programming section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 23rd, 2008, 07:19 AM
Authorized User
Join Date: Jan 2007
Location: , , .
Posts: 46
Thanks: 2
Thanked 1 Time in 1 Post
Default About Functions and refinement in program

I need to have critical comments about the following piece of code. I am learning to write my own functions in C++. Could someone guide me on how to make this program more refined and how can i make practice on making my own functions:

//Function declaration to calculate percentage
float CalcPerc(float,float);

//Function declaration to calculate GPA
 float CalcGPA(float);

//Function declaration to calculate CGPA
float CalcCGPA(float,float,float);

//Function declaration to decide Grade
char CalcGrade(float);

      float TotMrks,MrksObt;
      float perc;
      float gpa;
      float gpa1,gpa2,gpa3;
      float cgpa;

      char grade;

      for (int subj=1;subj<=3;subj++)
        cout<<"\nPlease enter the total marks and marks obtained in Subject "<<subj;;

        cout<<"\nTotal Marks: ";

        cout<<"Marks Obtained: ";

        perc = CalcPerc(MrksObt,TotMrks) ;
        cout<<"Percentage: "<<perc<<" %"<<"\n";

      gpa = CalcGPA(perc);
      cout<<"GPA: "<<gpa<<"\n";

           switch (subj)
           case 1:

          case 2:


      cgpa = CalcCGPA(gpa1,gpa2,gpa3);
      cout<<"\n"<<"CGPA: "<<cgpa<<"\n";

      grade = CalcGrade(cgpa);
      cout<<"Grade: "<<grade<<"\n";


//Function for calculating percentage
float CalcPerc(float MO, float TM)
            return (MO/TM * 100);

//Function for calculating GPA
float CalcGPA(float percentage)
    return (percentage/100) * 5;

//Function for calculating CGPA
float CalcCGPA(float GPA1,float GPA2,float GPA3)
      return (GPA1 + GPA2 + GPA3)/3;

//Function for assigning grade
char CalcGrade(float CGPA)
     if (CGPA >= 4)
        return 'A';
     else if (CGPA >= 3 && CGPA < 4)
        return 'B';
     else if (CGPA >= 2 && CGPA < 3)
        return 'C';
     else if (CGPA >= 1 && CGPA < 2)
        return 'D';
     else if (CGPA < 1)
        return 'F';


Life is an endless journey towards perfection

Life is an endless journey towards perfection
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
weird program flow with nested functions zayasv General .NET 1 January 6th, 2006 11:06 AM
weird program flow with nested functions zayasv VB.NET 0 October 26th, 2005 11:17 AM
Setup Project: Program not added in Start>Program arif_1947 VS.NET 2002/2003 2 March 31st, 2005 06:40 AM
Start a program inside another program Silje Classic ASP Professional 1 November 16th, 2004 02:08 AM
Help with Functions megabytes C# 1 August 7th, 2003 12:48 PM

All times are GMT -4. The time now is 03:30 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.