plz give me solution

W

wahid

• Write a program, that will have letter grade as
input of 3 subjects, and their corresponding
credit hour, and calculate the CGPA based on
those three subjects. (Use getch to input letter
grades) The Grade Point Associated with the
letter grades is: A = 4.0, B = 3.5, C = 3.0, D =
2.5, F = 0.0

CGPA = ( ∑CHi GPi ) / (∑CHi )

CH = Credit Hours
GP = Grade Point

• Enter Letter grade 1: A
• Enter Credit hours: 1.5
• Enter Letter grade 1: C
• Enter Credit hours: 3
• Enter Letter grade 1: B
• Enter Credit hours: 3
• CGPA = 3.40000
 
S

spinoza1111

• Write a program, that will have letter grade as
input of 3 subjects, and their corresponding
credit hour, and calculate the CGPA based on
those three subjects. (Use getch to input letter
grades)  The Grade Point Associated with the
letter grades is: A  = 4.0, B = 3.5, C = 3.0, D =
2.5, F = 0.0

CGPA = ( ∑CHi GPi ) / (∑CHi )

CH = Credit Hours
GP = Grade Point

• Enter Letter grade 1: A
• Enter Credit hours: 1.5
• Enter Letter grade 1: C
• Enter Credit hours: 3
• Enter Letter grade 1: B
• Enter Credit hours: 3
• CGPA = 3.40000

We don't do homework assignments here. Instead, we fight each other
about C.
 
A

Antoninus Twink

• Write a program, that will have letter grade as input of 3 subjects,
and their corresponding credit hour, and calculate the CGPA based on
those three subjects. (Use getch to input letter grades)

#include <stdio.h>
#include <ctype.h>
#include <curses.h>

#define NSUBJS 3

int main(void)
{
int i, c, rv = 0;
double num = 0, denom = 0, ch, gp;
if(initscr() && cbreak() == OK && noecho() == OK) {
for(i = 0; i < NSUBJS; i++) {
printw("Enter letter grade %d: ", i + 1);
refresh();
for(;;) {
c = toupper(getch());
if(c >= 'A' && c <= 'D' || c == 'F')
break;
}
if(c == 'F')
gp = 0;
else
gp = 4 - .5 * (c - 'A');
printw("%c\n", c);
nocbreak();
echo();
do {
printw("Enter credit hours: ");
refresh();
} while(scanw("%lf", &ch) != 1);
cbreak();
noecho();
num += gp * ch;
denom += ch;
}
if(denom > 0)
printw("CGPA = %f\n", num / denom);
else
printw("Zero credit hours: can't form average\n");
printw("Press any key to exit...");
refresh();
getch();
endwin();
} else
rv = 1;
return rv;
}
 
T

Thad Smith

wahid said:
• Write a program, that will have letter grade as
input of 3 subjects, and their corresponding
credit hour, and calculate the CGPA based on
those three subjects. (Use getch to input letter
grades) The Grade Point Associated with the
letter grades is: A = 4.0, B = 3.5, C = 3.0, D =
2.5, F = 0.0

CGPA = ( ∑CHi GPi ) / (∑CHi )

CH = Credit Hours
GP = Grade Point

• Enter Letter grade 1: A
• Enter Credit hours: 1.5
• Enter Letter grade 1: C
• Enter Credit hours: 3
• Enter Letter grade 1: B
• Enter Credit hours: 3
• CGPA = 3.40000

There are three values for letter grade 1: A, C, and B. Normal computers
require separate variables for each letter grade. A quantum computer, however,
is able to hold multiple grades at the same time for a single class. You need a
quantum computer for this problem.
 
K

Keith Thompson

pete said:
wahid said:
• Write a program, that will have letter grade as
input of 3 subjects, and their corresponding
credit hour, and calculate the CGPA based on
those three subjects.
[snip]

/* BEGIN new.c */
[...]

/* END new.c */

pete, just who do you think you're helping?
 
K

Keith Thompson

pete said:
Keith said:
pete said:
wahid wrote:

• Write a program, that will have letter grade as
input of 3 subjects, and their corresponding
credit hour, and calculate the CGPA based on
those three subjects.
[snip]

/* BEGIN new.c */

[...]

/* END new.c */


pete, just who do you think you're helping?

Maybe pedagogy is on topic at alt.comp.lang.learn.c-c++ ?

Certainly, but I'm not aware that helping students cheat is on topic
anywhere.
 
S

Seebs

Still not. getc() blocks, getch() does not. I think (?)

The question is hard to answer portably. The classic DOS "getch()"
blocked, but returned as soon as a character was available, while
the default behavior of getc() on most systems is to be line buffered
when on a terminal. However, I think there have been systems or
compilers where getch() existed, but had different semantics.

-s
 
E

Ersek, Laszlo

The question is hard to answer portably. The classic DOS "getch()"
blocked, but returned as soon as a character was available, while
the default behavior of getc() on most systems is to be line buffered
when on a terminal. However, I think there have been systems or
compilers where getch() existed, but had different semantics.

getch() is an XCURSES function (among others).

http://www.opengroup.org/onlinepubs/007908775/xcurses/getch.html

The above is the SUSv2 link. The SUSv1 isn't available anymore on the
net to my knowledge, but its reference page on getch() mentions this:

CHANGE HISTORY
First released in Issue 2. [...]

Which probably refers to

Issue 2
X/Open Portability Guide, January 1987

I think the assignment is to write a simple Curses program or so (I've
been largely ignoring this thread till now).

The Curses input model:

http://www.opengroup.org/onlinepubs/007908775/xcurses/intov.html#tag_001_005
http://www.opengroup.org/onlinepubs/007908775/xbd/termios.html

Cheers,
lacos
 
J

James Dow Allen

• Write a program,...
[snip]
• Enter Letter grade 1: A

This looks like your first bug right here!
Can't do this problem without help and you're
expecting an A ?

By the way, I suspect some of the responses posted
may actually be entrants for the contest at:
http://underhanded.xcott.com/
I'd go with one of these! If instructor thinks
you're good enough to win that contest, maybe
you will get an A !

Hope this helps,
James
 
O

osmium

Richard Heathfield said:
According to the spec, it should be used for garnering input. So it could
be a wrapper for getc*, fgets, fscanf, whatever.


No, it means exactly what the programmer says it means. It's in user
namespace, so it's up to us what we do with that name, just as it's up to
us what we do with almost every other name.

The one thing we can't do with that name is assume that there is some
well-defined functional purpose attached to it, until /we/ provide that
purpose by writing the getch function.

In the US, if an instructor says use getch() (as in this case), it means
what the *instructor* says it means, not what some student, or his advisor,
or some random programmer says it means. Apparently, the English system is
different, or perhaps you haven't been exposed to it.

Whether the instructor should be teaching an obsolescent, but very useful,
dialect of C is an entirely separate issue. The point of the assignment was
to startle, amaze and perhaps amuse the user when he finally realizes that
input and output are two different things.

We have not the foggiest notion of what the instructor said he would teach,
that information is in the syllabus for the course, which we haven't seen.
By the way, as far as I know it is still legal in most of the world to teach
latin and other obsolete subjects.
 
M

Michael Foukarakis

The reason is say there's no solution - yes, we can define getch, but what
should it do? We can't make an assumption that getch is an alias for getc or
getchar or whatever. For all we know, getch could mean anything. A function
known as getch has been available in a few non-standard implementations, but
we don't know which, so using the return getc(fp) idea makes an assumption
that may or may not be accurate.
Thankfully, you don't have to worry about all that. getch() is already
implemented as part of the ncurses library routines, part of most
standard implementations.
 
N

Nick Keighley

• Write a program, that will have letter grade as
input of 3 subjects, and their corresponding
credit hour, and calculate the CGPA based on
those three subjects. (Use getch to input letter
grades)  The Grade Point Associated with the
letter grades is: A  = 4.0, B = 3.5, C = 3.0, D =
2.5, F = 0.0

CGPA = ( ∑CHi GPi ) / (∑CHi )

CH = Credit Hours
GP = Grade Point

• Enter Letter grade 1: A
• Enter Credit hours: 1.5
• Enter Letter grade 1: C
• Enter Credit hours: 3
• Enter Letter grade 1: B
• Enter Credit hours: 3
• CGPA = 3.40000

translate this p-code into C (I'll leave you to do the i/o)

;; defines fold
(load "library/srfi-1.scm")

(define (cpga credit-hours grade grade-point)
(/
(fold (lambda (ch g acc) (+ acc (* ch (grade-point g)))) 0
credit-hours grade)
(fold (lambda (ch acc) (+ acc ch)) 0 credit-hours) ))

(define (grade->grade-point grade)
(cond
((eq? grade 'A) 4.0)
((eq? grade 'B) 3.5)
((eq? grade 'C) 3.0)
((eq? grade 'D) 2.5)
((eq? grade 'F) 0.0)
(else (error "bad grade")) ))

(define (test)
(cpga '(1.5 3 3) '(A C B) grade->grade-point) )


typing (test) yields 3.4
 
B

Ben Bacarisse

Richard Heathfield said:
You're forgetting context. The article was posted in comp.lang.c
(only), so we can reasonably assume that the intended solution relies
only upon the core C language.

I don't find that assumption reasonable. I can see that it is
reasonable to give such answers, but I can't see how one can infer
that a beginner intended to get such answers.

<snip>
 
A

Andrew Poelstra

Thankfully, you don't have to worry about all that. getch() is already
implemented as part of the ncurses library routines, part of most
standard implementations.

Ah, but what standard (or what library)? There are more than one
that define getch() but none of them are C standards. This is
where the confusion stems from, though it is rather exagerrated
by some here to make a point about topicality.
 
D

Default User

Richard said:
We can infer this from the fact that all newcomers to a Usenet
newsgroup spend six months reading the feed before they post their
first article

Six MONTHS! That's . . . amazing. I've never heard anyone suggest that
before. Six weeks, maybe. Let's hope no newbies need assistance in
their current class.

Yes, yes, they could spend time trying to read six months of backlog,
if they have nothing else to do with their time for a few hundred hours.

Regardless of whether you think that they did insufficient research
into the group first, it's still a lot more handy for all concerned to
just instruct them on the topicality, rather than the Richard
Heathfield willful misunderstanding game.



Brian
 
S

Seebs

You're forgetting context. The article was posted in comp.lang.c (only),
so we can reasonably assume that the intended solution relies only upon
the core C language.

I don't think this is a reasonable assumption. It's certainly not a safe
assumption.

A student new to C, still learning from college courses, is almost certainly
not going to have started out with a clear notion of the boundary between
the C language and a particular implementation's extensions.

-s
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top