Good Programming Structure of a Simple C++ Program
Comment Section
\* a line of single space must be given */
Header Files Section
\* a line of single space must be given */
Definition Section
\* a line of single space must be given */
Global Declaration Section
\* a line of single space must be given */
Definition of the class
\* a line of single space must be given */
void main()
{
Declaration Section
\* a line of single space must be given */
Input Section
\* a line of single space must be given */
Calculation Section
\* a line of single space must be given */
Output Section
}
Write the following good steps to write a simple C++ program
Step 1: Comment Section
Step 2: Header Files Section
Step 3: Definition Section
Step 4: Global Declaration Section
Step 5: Definition of the Class
Step 6: Specification of main function
void main()
Step 7: Body of the main function
void main()
{
\* a line of single space must be given */
}
Step 8: Within main() function,
(a) Declaration Section
(b) Input Section
(c) Calculation Section
(d) Output Section
About Comment Section (that is, Step 1:)
1. The comment statement is used to identify the purpose of the program
2. Usually specified at the start of a program. (That is, to give about program details)
3. Types of comments in C++
Two type of comments may be used in C++. Use the following general forms for a
comment statement in C++
Type-1 (/* */)
Single line Comment:
(a) The single line comments begin with /* and end at the end of the line with */
(b) Single-line comments are especially useful when short, line-by-line descriptions are needed.
General Form: /* a comment details */
Example: /* This is a single-line comment */
Multiple line comment:
(a) The multi-line comments start with /* and end with a */,
(b) Multi-line comments may not be nested. That is, one comment may not contain another comment.
(c) Programmers use multi-line comments for longer remarks
General Form: /* Comment line-1
Comment line-2
Comment line-3 */
Example: /* This is a
multi-line
comment */
Note: There must be no spaces between the asterisk and the slash.
Type-2:
Single line Comment:
(a) The single line comments begin with /* and end at the end of the line.
(b) Single-line comments are especially useful when short, line-by-line descriptions are needed.
General Form: // a comment details
Example: // This is a single-line comment */
4. The comment statement is not an executable statement.
5. This statement may or may not be present in the program as per the programmers wish.
6. The compiler skips the comment line when it encounters a comment statement
7. Comment statements may be included in between the program to understand each line of the program.
8. It is a good programming practice to include comment statements in a program. /* important point */
Comment Section
\* a line of single space must be given */
Header Files Section
\* a line of single space must be given */
Definition Section
\* a line of single space must be given */
Global Declaration Section
\* a line of single space must be given */
Definition of the class
\* a line of single space must be given */
void main()
{
Declaration Section
\* a line of single space must be given */
Input Section
\* a line of single space must be given */
Calculation Section
\* a line of single space must be given */
Output Section
}
Write the following good steps to write a simple C++ program
Step 1: Comment Section
Step 2: Header Files Section
Step 3: Definition Section
Step 4: Global Declaration Section
Step 5: Definition of the Class
Step 6: Specification of main function
void main()
Step 7: Body of the main function
void main()
{
\* a line of single space must be given */
}
Step 8: Within main() function,
(a) Declaration Section
(b) Input Section
(c) Calculation Section
(d) Output Section
About Comment Section (that is, Step 1:)
1. The comment statement is used to identify the purpose of the program
2. Usually specified at the start of a program. (That is, to give about program details)
3. Types of comments in C++
Two type of comments may be used in C++. Use the following general forms for a
comment statement in C++
Type-1 (/* */)
Single line Comment:
(a) The single line comments begin with /* and end at the end of the line with */
(b) Single-line comments are especially useful when short, line-by-line descriptions are needed.
General Form: /* a comment details */
Example: /* This is a single-line comment */
Multiple line comment:
(a) The multi-line comments start with /* and end with a */,
(b) Multi-line comments may not be nested. That is, one comment may not contain another comment.
(c) Programmers use multi-line comments for longer remarks
General Form: /* Comment line-1
Comment line-2
Comment line-3 */
Example: /* This is a
multi-line
comment */
Note: There must be no spaces between the asterisk and the slash.
Type-2:
Single line Comment:
(a) The single line comments begin with /* and end at the end of the line.
(b) Single-line comments are especially useful when short, line-by-line descriptions are needed.
General Form: // a comment details
Example: // This is a single-line comment */
4. The comment statement is not an executable statement.
5. This statement may or may not be present in the program as per the programmers wish.
6. The compiler skips the comment line when it encounters a comment statement
7. Comment statements may be included in between the program to understand each line of the program.
8. It is a good programming practice to include comment statements in a program. /* important point */
Write the steps for the definition of Emp Class
Step 1: Specification of the Class class Emp ----------------------------------------------------------------------------------------------------------------------- Step 2: Body of the Class class Emp { }; -------------------------------------------------------------------------------------------------------- Step 3: Declaration of Data Members class Emp { int eno; char ename[15]; int salary; }; ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Step 3: Declaration of Data Members class Emp { private: int eno; char ename[15]; int salary; }; ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Step 4: Declaration of Member Functions class Emp { public: void getEmpDetails(); void putEmpDetails(); }; ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Step 5: Definition of the Class class Emp { private: int eno; char ename[15]; int salary; public: void getEmpDetails(); void putEmpDetails(); }; |
Write the steps for the definition of Student Class
Step 1: Specification of the Class class Student ---------------------------------------------------------------------------------- Step 2: Body of the Class class Student { }; ---------------------------------------------------------------------------------- Step 3: Declaration of Data Members class Student { int rno; char sname[15]; int marks[5]; }; Step 3: Declaration of Data Members class Student { private: int rno; char sname[15]; int marks[5]; }; Step 4: Declaration of Member Functions class Student { public: void getStudentDetails(); void putStudentDetails(); }; Step 5: Definition of the Class class Student { private: int rno; char sname[15]; int marks[5]; public: void getStudentDetails(); void putStudentDetails(); }; |