Quantcast
Channel: Java Question Bank » Cpp Programs
Viewing all articles
Browse latest Browse all 22

CPP Program using Functions

$
0
0

Write a complete C++ program which has the following FOUR (4) functions:
(i)    get name of student:
(ii)    get age of student
(iii)    get marks of student – there should be a loop to accept several entries of
marks until the user decides to terminate the loop
For each mark, you should keep track of the grade obtained and provide
a summary in listing. [Hint: You may use a counter for each grade]

If mark is less than 40 award Fail
If mark is more than 39 but less than 60 award Pass
If mark is more than 59 but less than 80 award Credit
If mark is more than 80 award Distinction
(iv)    Display average mark of student together with his or her age.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
 

Your program should have a main method which will invoke the above functions and display the following type output:

Please enter you name: Michael
Please enter you age: 38
Enter Mark: 78
Do you want to enter more marks (Y/N): Y
Enter Mark: 89
Do you want to enter more marks (Y/N): Y
Enter Mark: 77
Do you want to enter more marks (Y/N): y
Enter Mark: 112
Illegal Mark.
Enter Mark: 80
Do you want to enter more marks (Y/N): n

Average mark for Michael aged 38 is: 81
Fail: 0
Pass: 0
Credit: 2
Distinction: 2

Note: NO calculations should be present in the main method. All computations must be
done via functions.

*/

#include<iostream.h>
#include<stdio.h>

class student
{
char name[40];
int age;
int avgmark;

int Fail;
int Pass;
int Credit;
int Distinction;

public:

void getnameof student:
get age of student
get marks of student
void getdata();
void showdata();
};

void student::getdata()
{
int mark,noofsubjects=0;
char c;
avgmark=0;
cout<<"\nPlease enter you name:";
gets(name);
cout<<"Please enter you age   :";
cin>>age;

do
{
begin:
cout<<"Enter Mark:            :";
cin>>mark;
if( mark<0 || mark>100)
{
cout<<"Illegal Mark.\n\t\t";
goto begin;
}
noofsubjects++;
avgmark+=mark;

cout<<"Do you want to enter more marks (Y/N): ";
cin>>c;
}while(c=='y' || c=='Y');

avgmark/=noofsubjects;

}
void student::showdata()
{

}
void main()
{

student s1;
s1.getdata();
s1.showdata();

}

277 total views, 1 views today


Viewing all articles
Browse latest Browse all 22

Trending Articles