Latest Activity In Study Groups

Join Your Study Groups

VU Past Papers, MCQs and More

We non-commercial site working hard since 2009 to facilitate learning Read More. We can't keep up without your support. Donate.


Instructions:

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 by the user.

 

 

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. 

Views: 5305

Attachments:

Replies to This Discussion

good job

@Ahmad Prince, Thanks Dear Brother 

Ahmad bahi ye to run ni ho rha...E or e write kr k enter press karyn to screen hi disappear ho jati h

plzz help me

@Lucky, check attachment "Assignment No1_CS201_Solved.cpp" file. it will fixed your issue.

#include <iostream>

using namespace std;

int main () {

char character;

cout "Please enter the option <e, E or o, O>: ";

cin >> character;

int digit = 1;

switch ( character ) {
case 'e':

cout "Even numbers from 1 to 50 " endl;
while (digit <= 50) {

if ( digit % 2 == 0 ) {
cout digit ", ";
}

digit++;
}

break;

case 'E' :

cout "Even numbers from 1 to 50 " endl;
while (digit <= 50) {

if ( digit % 2 == 0 ) {
cout digit ", ";
}

digit++;
}

break;

case 'o' :

cout "Odd numbers from 1 to 50 " endl;
while (digit <= 50) {

if ( digit % 2 == 1 ) {
cout digit ", ";
}

digit++;
}
break;

case 'O' :

cout "Odd numbers from 1 to 50 " endl;
while (digit <= 50) {

if ( digit % 2 == 1 ) {
cout digit ", ";
}

digit++;
}

break;
}

}

Note: For original code, download ".txt" file attachment. All answers are just contribution for helping other students, Please don't copy and paste it, Just try to understand major concepts. Best of luck...

Attachments:

really nice attempt by you

Ahmad

Bro! one way is to create functions for both even and odd numbers and just call them

in o or O and e or E cases respectively.

Please Discuss here about this assignment.Thanks

Our main purpose here discussion not just Solution

We are here with you hands in hands to facilitate your learning and do not appreciate the idea of copying or replicating solutions.

u r right M.Tariq

Ahmad gud..keep it up 

can doc.comand compulsory

H@A M.I.T student wat do u men by doc.comand?

RSS

© 2021   Created by + M.Tariq Malik.   Powered by

Promote Us  |  Report an Issue  |  Privacy Policy  |  Terms of Service