CS201 Assignment # 1 Solution

Embed Size (px)

Citation preview

  • 8/8/2019 CS201 Assignment # 1 Solution

    1/4

    Instructions: Please read the following instructions carefully

    before submitting your assignment:

    It should be clear that your assignment will not get any credit

    if: The assignment is submitted after due date. The submitted assignment does not open or file is corrupt.All types of plagiarism are strictly prohibited.

    Note:You have to upload only .cpp file. Assignment in any other

    format (extension) will not be accepted. If you will submit code any

    other file format like .doc or .txt etc. you will get zero marks.

    ObjectiveThe objective of this assignment is to provide hands on experience of

    usingBasic concepts of C/C++ language and ProgrammingWriting, Compiling and Executing a C programConditional statements of C languageLoops in C languageGuidelinesCode should be properly aligned and well commented.Follow C/C++ rules while writing variables names, function namesetc.Use only Dev-C++ IDE for this assignment.AssignmentProblem Statement: Calculating No. of A Grades in Class

    You are required to write a program which should take input from userin the form of characters A or B. Based upon users input you should

    calculate no. of A grades. You should use while loop or do/while loop

    for taking input and if / else condition for making decisions.

    Detailed Description:

    The program should display like;

    Please Enter Grade (A OR B )Then the program should take 10 inputs one by one,

    After taking 10 inputs, you should display no. of A grades.

    If A grades are less than or equal to 2, you should display a

    message Your class is Poor!.

    If A grades are less than or equal to 7, you should display a

    message Your class is Good!.

  • 8/8/2019 CS201 Assignment # 1 Solution

    2/4

    If A grades are greater than or equal to 8, you should displaya message Your class is Brilliant!.

    The user should enter either A or B. If user has entered otherthan A or B, e.g. C,D,E etc. Your program should display a

    message like;

    "Please Enter 'A' or 'B' grade only!"Sample Input and Output

    Please Enter Grade of student 1 : A Please Enter Grade of student 2 :

    A Please Enter Grade of student 3 : B Please Enter Grade of student4 : A Please Enter Grade of student 5 : B Please Enter Grade of

    student 6 : B Please Enter Grade of student 7 : A Please Enter Gradeof student 8 : B Please Enter Grade of student 9 : CPlease Enter A

    or B grade only! Please Enter Grade of student 9 : A Please Enter

    Grade of student 10 : A

    Total No. of A Grades = 6

    Your Class is Good!Deadline:Your Assignment solution must be uploaded/submitted on orbefore November 05, 2010

    ...............using namespace std;

    #include

    #include

    main()

    {

    int totalstudent=1;int A =0,B=0;

    char grad(1);

    while (totalstudent

  • 8/8/2019 CS201 Assignment # 1 Solution

    3/4

    cin>>grad;if (grad=='a' or grad =='A')

    {A = A+1;

    totalstudent++;

    }else if (grad=='b' or grad =='B')

    {B += 1;

    totalstudent++;

    }else

    {cout"\nPlease Enter 'A' or 'B' grade only! \n";

    }}

    cout"Total No. of A Grades "A" :\n";

    if (A

  • 8/8/2019 CS201 Assignment # 1 Solution

    4/4