for my own Idea I just declare function prototypes at the beginning because I don't what to see anything as much as possible like functions above main.... I just like that way..hihi
.. Im not a good programmer but I know I can teach some basics of C++ like displaying something in the CLI..
.. Im a very bad programmer...
Actually Romel, your way is the prefer method and taught in most college classes, at least over here. It also has the advantage of simplifying the process of separating related routines into their own header/code, object or library files for future use in other projects. Why reinvent the wheel?
You simply cut and past the prototypes into a .h file, cut and paste the subroutines into a .c file, which can be included into a new project by #include <newheader.h>. Also the subroutine code and be compiled into an object module or into a separate library .lib file.
I've seen worse. A LOT WORSE! I think you're being a little hard on yourself and you should have not problem being a tutor. And you're right, it will only help/force you to improve your C programming skills. If you need to brush up on certain areas, let me know, I can refer you to several online references and textbooks. I personally have a library of over 4000 technical books, one wall is dedicated to only programming languages, many are C and C++ texts.
Good Luck with your tutorship.
#include <iostream> //include this to use cout function
#include<conio.h> //include to use getchar(); funtion
using namespace std; //include this to use cout function
float calculate_quiz(); //Funtion prototypes.
float calculate_exam(); //You need to declare it here
float calculate_attendance(); //if you have funtions below the
float final_grade(float grade); //main funtion
/* main Funtion */
main()
{
float raw_grade, grade; //declaration
int choice; //of variables
here: //jump label
system("cls"); //clear screen funtion
cout<<" This System is a Student Grade Calculator\n\n";
cout<<" Pls. ENTER The Following Needed Data\n" ;
raw_grade = calculate_quiz() + calculate_exam() + calculate_attendance(); //sum of all computations
grade = final_grade(raw_grade); //calculating the final grade
cout<<"\nGrade: "<<grade; //Display final grade
// cout<<"\nraw grade: "<<raw_grade;
cout<<"\n\n\nCalculate Another Student Grade?\n(press 1 if YES and 0 if NO)";
cin>>choice;
if(choice == 1)
goto here; //jump label to repear first step
else
exit; //Exit command
}
float calculate_quiz() //funtion for calculating quiz
{
float quiz; //declare quiz as foat variable
cout<<"\nENTER QUIZ: ";
cin>>quiz; //store user input to quiz variable
quiz = quiz*0.50; //compute the percentage of quiz
return quiz; //return the value of quiz to be calculated in later application
}
float calculate_exam() ////funtion for calculating exam
{
float exam;
cout<<"\nENTER EXAM: ";
cin>>exam;
exam = exam*0.30;
return exam;
}
float calculate_attendance() //funtion for calculating attendance
{
float attendance;
cout<<"\nENTER ATTENDANCE: ";
cin>>attendance;
attendance = attendance*0.20;
return attendance;
}
float final_grade(float grade) //function for selecting final grade range
{
float final_grade;
if(grade<75)
final_grade = 5.0;
/* conditional statements */
if(grade >= 75 && grade <= 77)
final_grade = 3.0;
if(grade >= 78 && grade <= 80)
final_grade = 2.75;
if(grade >= 81 && grade <= 83)
final_grade = 2.5;
if(grade >= 84 && grade <= 86)
final_grade = 2.25;
if(grade >= 87 && grade <= 89)
final_grade = 2.0;
if(grade >= 90 && grade <= 92)
final_grade = 1.75;
if(grade >= 93 && grade <= 95)
final_grade = 1.5;
if(grade >= 96 && grade <= 98)
final_grade = 1.25;
if(grade >= 99 && grade <= 100)
final_grade = 1.0;
return final_grade;
}
This afternoon I will continue my PWM lesson...
Are you still have problems with certain areas of PWM? If so, let me know. Good online PIC specific tutorials covering PWM in C language seem to be lacking. I have several textbooks which cover PIC generation of PWM fairly well, I may have some appnotes as well.
The pulse width modulation (PWM) mode produces a PWM output at 10-bit resolution.
A PWM output is basically a square waveform with a specified period and duty cycle.
if you use timer2 to generate the pwm then you have to play with the registers.. but if you are deriving pwm directly from the pwm channel then it is not required...
#include<htc.h>
void init_pwm();
void pwm(unsigned char period, unsigned char duty);
void main()
{
init_pwm();
while(1)
{
pwm(50,20);
}
}
void init_pwm()
{
TRISC = 0; //set PORTC as output
CCP1CON |= 0b1100; //enable PWM mode
T2CONbits.TMR2ON = 1;
T2CONbits.T2CKPS0 = 1; //prescaler 4
}
void pwm(unsigned char period, unsigned char duty)
{
PR2 = period;
CCPR1L = duty;
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?