Sponsored Links


Results 1 to 3 of 3

Thread: CS201-Introduction to Programming Assignement No.1 Due Date 14th May 2014

  1. #1
    Senior Member
    Join Date
    Dec 2013
    Posts
    607

    CS201-Introduction to Programming Assignement No.1 Due Date 14th May 2014

    Sponsored Links1




    CS201-Introduction to Programming Assignement No.1 Solutions

    Please read the following instructions carefully before submitting 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.
    Assignment is copied(partial or full) from any source (websites, forums, students, etc)

    Note: You have to upload only .cpp file. Assignment in any other format (extension) will not be accepted and will be awarded with zero marks. For example, if you submit code in .doc (Word document) or .txt files or .exe file, no reward will be given in any case.

    Objective:
    The objective of this assignment is to provide hands on experience of
    Basic concepts of C/C++ language and Programming
    Dealing with Data types
    Conditional statements of C/C++ language
    Repetition Structures (Loop)
    Switch statement

    Guidelines:
    Code should be properly indented and well commented.
    Follow C/C++ rules while writing variable names, function names etc
    Use only dev-C++ for this assignment.

    Assignment
    Problem Statement:
    You are required to write a C++ program using loop and switch statement. The program should display even or odd numbers from 1 to 50 depending upon the option given

    Detailed Description:
    The program should prompt the user for one character option (either ‘e’, ‘E’ or ‘o’, ‘O’).
    It should respond in the following ways:

    If user enters character option ‘e’ or ‘E’ then it should display the even numbers from 1 to 50.
    If user enters character option ‘o’ or ‘O’ then it should display the odd numbers from 1 to 50.
    Sample output of the program:

    If user enters ‘e’ then it displays the even numbers from 1 to 50.
    If user enters ‘E’ then it displays the even numbers from 1 to 50
    If user enters ‘o’ then it displays the odd numbers from 1 to 50.
    If user enters ‘O’ then it displays the odd numbers from 1 to 50.




    Sponsored Links

  2. #2
    Administrator Vuhelper's Avatar
    Join Date
    Apr 2011
    Posts
    9,578


    #include <cstdlib>
    #include <iostream>

    using namespace std;

    int main(int argc, char *argv[])
    {
    cout "Please enter the option <e, E or o, O>:";
    char option=0;
    cin >> option;
    switch(option)
    {
    case 'e':
    case 'E':
    cout"\n";
    cout "Even number 1 to 50" endl "\n";
    for(int i=1; i<=50; i++)
    {
    if(i%2==0)
    {
    cout i ",";
    }
    }
    break;

    case 'o':
    case 'O':
    cout"\n";
    cout "Odd Number 1 to 50" endl "\n";
    for(int i=1; i<=50; i++ )
    {
    if(i%2==1)
    {
    cout i ", ";
    }
    }
    break;
    default:
    cout"\n";
    cout "your choice is Wrong please Enter [e,E,o,O]";
    }

    cout"\n";
    coutendl;

    system("PAUSE");
    return EXIT_SUCCESS;
    }


    #include <cstdlib>
    #include <iostream>

    using namespace std;

    int main(int argc, char *argv[])
    {
    cout "Please enter the option <e, E or o, O>:";
    char option=0;
    cin >> option;
    switch(option)
    {
    case 'e':
    case 'E':
    cout"\n";
    cout "Even number 1 to 50" endl "\n";
    for(int i=1; i<=50; i++)
    {
    if(i%2==0)
    {
    cout i ",";
    }
    }
    break;

    case 'o':
    case 'O':
    cout"\n";
    cout "Odd Number 1 to 50" endl "\n";
    for(int i=1; i<=50; i++ )
    {
    if(i%2==1)
    {
    cout i ", ";
    }
    }
    break;
    default:
    cout"\n";
    cout "your choice is Wrong please Enter [e,E,o,O]";
    }

    cout"\n";
    coutendl;

    system("PAUSE");
    return EXIT_SUCCESS;
    }

  3. #3
    Senior Member
    Join Date
    Oct 2012
    Posts
    323
    there are two ways to stop the output
    1. last statement in the main program should be
    system("pasue");
    2. last statement should be:
    getch();
    for the 2nd step you need to add one header file conio.h
    in the beginning write #include<conio.h>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 3
    Last Post: 12-11-2014, 03:33 PM
  2. Replies: 2
    Last Post: 08-08-2014, 11:18 PM
  3. CS201-Introduction to Programming Assignment No.2 Spring semester 2014
    By vuassignments in forum Assignments & Solutions
    Replies: 0
    Last Post: 07-09-2014, 04:14 PM
  4. CS201-Introduction to Programming Quiz No.3 Discussion and Solutions Fall 2014
    By vuassignments in forum MCQ's & Quiz Discussion
    Replies: 0
    Last Post: 07-04-2014, 02:15 AM
  5. CS201-Introduction to Programming Quiz No.1 Solutions Spring 2014
    By vuassignments in forum MCQ's & Quiz Discussion
    Replies: 0
    Last Post: 05-15-2014, 04:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
-: Vuhelp Disclaimer :-
None of the files shown here are hosted or transmitted by this server. The links are provided solely by this site's users. The administrator's or staff of Vuhelp.net cannot be held responsible for what its users post, or any other actions of its users. You may not use this site to distribute or download any material when you do not have the legal rights to do so. It is your own responsibility to adhere to these terms. If you have any doubts about legality of content or you have any suspicions, feel free to contact us.
Online Education | JhelumSoft