C++ programming

Pages: 12
Jun 27, 2016 at 7:29pm
Write a program in C++ to prepare a frequency distribution table of the percentage marks in Computer studies of N students, to be taken as inputs, into the following categories

Category Marks(%)
Fail 0-34
Pass 35-59
Good 60-79
Very Good 80-89
Excellent 90 and above
Jun 27, 2016 at 7:44pm
Please note that this is not a homework site. We won't do your homework for you. The purpose of homework is that you learn by doing. However we are always willing to help solve problems you encountered, correct mistakes you made in your code and answer your questions.

We didn't see your attempts to solve this problem yourself and so we cannot correct mistakes you didn't made and answer questions you didn't ask. To get help you should do something yourself and get real problems with something. If your problem is "I don't understand a thing", then you should go back to basics and study again.
Jun 28, 2016 at 11:58am
why wont this compile correctly as per the question .plz help me.

#include<iostream.h>
#include<conio.h>
void main()
{
int marks[50], n;
cout<<"Enter number of students";
cin>>n;
int fail=0, pass=0, good=0, very good=0, excellent=0;
for(int i=0;i<n;i++)
{
cout<<"Enter the marks of students";
cin>>marks[i];
if ((marks[i]>=0) && (marks[i]<=34))
fail++;
else if ((marks[i]>=36) && (marks[i]<=59))
pass++;
else if ((marks[i]>=60) && (marks[i]<=79))
verygood++;
else if ((marks[i]>=80) && (marks[i]<=89))
excellent++;
else
(marks[i]>=90)
}
getch();
}
Jun 28, 2016 at 12:52pm
First of all, there is a format button that looks like "<>" that provides code tags. It will make it easier for us to review and comment on your post. Please edit you post, highlight the code, and click the button.

Second, C++ standards state that main() must return an int. Your teacher (or tutorial) is giving you bad habits by suggesting void main(). I would strongly suggest you change line 3 appropriately.

Third, if the code won't compile you probably received error messages. Please post what errors you got so we don't have to guess. My ESP is a little bit out of whack today.
Jun 28, 2016 at 1:35pm
why doesn't the output display like a frequency distribution table.

Enter number of students:
                                         //if entered 2
Enter the marks of students:
                                        // if entered 12,13
 


thats it. it wont display whether the mark is pass ,fail,....in a frequency distribution table
Last edited on Jun 28, 2016 at 1:55pm
Jun 28, 2016 at 1:37pm
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
#include<iostream.h>
#include<conio.h>
int main()
{
int marks[50], n;
cout<<"Enter number of students";
cin>>n;
int fail=0, pass=0, good=0, very good=0, excellent=0;
for(int i=0;i<n;i++)
{
cout<<"Enter the marks of students";
cin>>marks[i];
if ((marks[i]>=0) && (marks[i]<=34))
fail++;
else if ((marks[i]>=36) && (marks[i]<=59))
pass++;
else if ((marks[i]>=60) && (marks[i]<=79))
verygood++;
else if ((marks[i]>=80) && (marks[i]<=89))
excellent++;
else
(marks[i]>=90)
}
getch();
}
Jun 28, 2016 at 1:45pm
closed account (48T7M4Gy)
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
#include<iostream> //<--
//#include<conio.h>  //<-- what's this?

int main() //<-- int not void
{
    int marks[50] = {0}; //<-- initialize
    int n = 0; //<-- separate lines
    int fail=0, pass=0, good=0, very good=0, excellent=0;// put variables at top
    // very good is not a valid variable name
    
    cout<<"Enter number of students";
    cin>>n;
    
    for(int i=0;i<n;i++)
    {
        cout<<"Enter the marks of students";
        cin>>marks[i];
        
        if ((marks[i]>=0) && (marks[i]<=34))
            fail++;
        else if ((marks[i]>=36) && (marks[i]<=59))
            pass++;
        else if ((marks[i]>=60) && (marks[i]<=79))
            verygood++;
        else if ((marks[i]>=80) && (marks[i]<=89))
            excellent++;
        else
            (marks[i]>=90) //<-- what are round brackets for?
    }

    getch();//<-- what's this for?
    
    return 0; //<-- good practice
} 

/*
USE WHITESPACE, INDENTATION AND BLANK LINES
TO MAKE THE CODE READABLE

IF CASCADE IS TOO COMPLICATED

YOU MUST USE std::cout ETC OR using namespace std;
*/
Last edited on Jun 28, 2016 at 1:45pm
Jun 28, 2016 at 2:10pm
why doesn't the output display like a frequency distribution table.


Enter number of students:
                                         //if entered 2
Enter the marks of students:
                                        // if entered 12,13



thats it. it wont display whether the mark is pass ,fail,....in a frequency distribution table[
Jun 28, 2016 at 2:19pm
closed account (48T7M4Gy)
why doesn't the output display like a frequency distribution table.

You mean your program actually runs?
Jun 28, 2016 at 2:36pm
yes it runs but not according to what is asked in the question
how to create a frequency distribution table?
Jun 28, 2016 at 2:41pm
It doesn't display the results because you don't print the results anywhere. You collect the number of fails, passes, etc., but then you don't do anything with them. You need to print them out.
Last edited on Jun 28, 2016 at 2:42pm
Jun 28, 2016 at 2:52pm
closed account (48T7M4Gy)
int fail=0, pass=0, good=0, very good=0, excellent=0;


If you can get it to run suresh9 and print anything like you have quoted with a line like that is a miracle of major proportions. :)
Jun 28, 2016 at 2:55pm
could pls explain me how
The output should display the categories and the corresponding frequencies, i.e, the number of students in each category in two columns.
Jun 28, 2016 at 3:13pm
closed account (48T7M4Gy)
Please show us, with tags the latest code you have. What attempts have you made?
Jun 28, 2016 at 3:22pm
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
#include<iostream.h>
#include<conio.h>
int main()                  //int not void
{
int marks[50], n;
cout<<"Enter number of students";
cin>>n;
int fail=0, pass=0, good=0, verygood=0, excellent=0;        //verygood
for(int i=0;i<n;i++)
{
cout<<"Enter the marks of students";
cin>>marks[i];
if ((marks[i]>=0) && (marks[i]<=34))
fail++;
else if ((marks[i]>=36) && (marks[i]<=59))
pass++;
else if ((marks[i]>=60) && (marks[i]<=79))
good++;                                                                //good++ was missing earlier
else if ((marks[i]>=80) && (marks[i]<=89))
verygood++;
else if (marks[i]>=90)
excellent++;
}
getch();
}
Last edited on Jun 28, 2016 at 3:24pm
Jun 28, 2016 at 3:38pm
closed account (48T7M4Gy)
cout << "Fails = " << fail << "Pass = " << ... etc might be a start.


Jun 28, 2016 at 3:50pm
plz tell me clearly like earlier where to make changes
Jun 28, 2016 at 4:07pm
closed account (48T7M4Gy)
You have to complete the line I gave you and then put it after line 23.
Jun 28, 2016 at 4:10pm
ok i understood thank u
Jun 28, 2016 at 4:21pm
Now the program looks like this;
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
#include<iostream.h>
#include<conio.h>
int main()
{
int marks[50], n;
cout<<"Enter number of students";
cin>>n;
int fail=0, pass=0, good=0, verygood=0, excellent=0;
for(int i=0;i<n;i++)
{
cout<<"Enter the marks of students";
cin>>marks[i];
if ((marks[i]>=0) && (marks[i]<=34))
fail++;
else if ((marks[i]>=36) && (marks[i]<=59))
pass++;
else if ((marks[i]>=60) && (marks[i]<=79))
good++;
else if ((marks[i]>=80) && (marks[i]<=89))
verygood++;
else if (marks[i]>=90)
excellent++;
}
cout<<"fail="<<fail<<"\t"<<"pass="<<pass<<"\t"<<"good="<<good<<"\t"<<"verygood="<<verygood<<"\t"<<"excellent="<<excellent;
getch();
}




Enter number of students

enter the marks of students

fail=...   pass=...  good=.... verygood=...  excellent=...
Last edited on Jun 28, 2016 at 5:04pm
Pages: 12