0% found this document useful (0 votes)
235 views

Module2 Assign2.1 NestedIf

The document provides instructions for a programming assignment asking students to write a program using nested if statements that takes user input for gender and age or year level and status and outputs the corresponding category. It includes a sample C++ program code using nested ifs to categorize based on gender and age. The instructions provide sample output formats and require students to write their own code, run it, and provide two sample outputs, including one invalid combination.

Uploaded by

ai tsuki
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
235 views

Module2 Assign2.1 NestedIf

The document provides instructions for a programming assignment asking students to write a program using nested if statements that takes user input for gender and age or year level and status and outputs the corresponding category. It includes a sample C++ program code using nested ifs to categorize based on gender and age. The instructions provide sample output formats and require students to write their own code, run it, and provide two sample outputs, including one invalid combination.

Uploaded by

ai tsuki
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

TECHNOLOGICAL INSTITUTE OF THE PHILIPPINES

QUEZON CITY
COLLEGE OF INFORMATION TECHNOLOGY EDUCATION (CITE)
ITE001- Computer Programming 1

SAMPLE PROGRAM ONLY : Selection Control Structure using Nested If condition ( NOT GRADED)

INSTRUCTION: Read and study the assignment below. Solve the problem using C++ programming
language, compile, run and screen shot the correct output. Copy and paste the source code or program
code and the required sample output (screen shot) in the format below. The output should also display the
school name, course name, student name, program, section, date and title of assessment task.

PROBLEM: Write a program that will let the user input year level and status base on the table below. The output
should be based on the possible combination of year level and status.

GENDER AGE
INPUT OUTPUT INPUT OUTPUT
F or f Female 1 to 17 Minor
M or m Male 18 to 59 Adult
Other 60 and
Invalid Senior
input above
Others Invalid

//Sample if , if-else and nested if


#include<iostream>
using namespace std;
main()
{ int age; char gender;
cout<<("*** USING NESTED IF STATEMENT ****");
cout<<("\nEnter your gender : "); cin>> gender;
cout<<("\nEnter your age : "); cin>> age;
if (gender == 'F' || gender == 'f')
{ if ( age >=1 && age <=17)
cout<<" \nFemale & Minor";
else if ( age >=18 && age <=59)
cout<<" \nFemale & adult";
else if (age >= 60)
cout<<"\nFemale & Senior";
else cout<<"Female & Invalid";
}

else if (gender == 'M' || gender == 'm')


{ if ( age >=1 && age <=17)
cout<<" \nMale & Minor";
else if ( age >=18 && age <=59)
cout<<" \nMale & adult";
else if (age >= 60)
cout<<" \nMale & Senior";
else cout<<"Male & Invalid";
}

else
{ if ( age >=1 && age <=17)
cout<<" \nInvalid & Minor";
else if ( age >=18 && age <=59)
cout<<" \nInvalid & adult";
else if (age >= 60)
cout<<" \nInvalid & Senior";
else
cout<<" \nInvalid & Invalid";
}
}
TECHNOLOGICAL INSTITUTE OF THE PHILIPPINES
QUEZON CITY
COLLEGE OF INFORMATION TECHNOLOGY EDUCATION (CITE)
ITE001- Computer Programming 1
NAME: CANDELARIO, Lovely B.
PROGRAM/SECTION: IT11S2-A21
ASSESSMENT TASK: Selection Control Structure using Nested If () Condition (GRADED)

The following question supports the attainment of Course Intended Learning Outcomes (CILO): Design
computing based solution using control structures, functions, array and other statements.

INSTRUCTION: Read and study the assignment below. Solve the problem using C++ programming
language, compile, run and screen shot the correct output. Copy and paste the source code or program
code and the required sample output (screen shot) in the format below. The output should also display the
school name, course name, student name, program, section, date and title of assessment task.

PROBLEM: Write a program that will let the user input year level and status based on the table below. The output
should be based on the possible combination of year level and status.

YEAR LEVEL STATUS


INPUT OUTPUT INPUT OUTPUT
1 First Year R or r Regular
2 Second Year I or i Irregular
3 Third Year other letters Invalid
4 Fourth Year
other
Invalid
number

Sample Output(1):
Name : Juan Cruz
Section: IT11S1
Enter Year Level : 1
Enter Status :r
The student is First Year and Regular

Enter Year Level : 1


Enter Status :R
The student is First Year and Regular
Enter Year Level : 4
Enter Status :s
The student is Fourth Year and Invalid
ANSWER:

1. SOURCE CODE: Write or paste the program code below

#include<iostream>

using namespace std;

main()

{ int year; char status;

cout<<("Name: Lovely B. Candelario");

cout<<("\nSection: IT11S2-A21");

cout<<("\nEnter your Year Level: "); cin>> year;

cout<<("Enter your Status: "); cin>> status;

if (status == 'R' || status == 'r')

if ( year == 1)

cout<<" \nThe student is First Year and Regular";

else if ( year == 2)

cout<<" \nThe student is Second Year and Regular";

else if ( year == 3)

cout<<"\nThe student is Third Year and Regular";

else if ( year == 4)

cout<<"\nThe student is Fourth Year and Regular";

else cout<<"Invalid";

else if (status == 'I' || status == 'i')

if ( year == 1)
cout<<" \nThe student is First Year and Irregular";

else if ( year == 2)

cout<<" \nThe student is Second Year and Irregular";

else if ( year == 3)

cout<<"\nThe student is Third Year and Irregular";

else if ( year ==4)

cout<<"\nThe student is Fourth Year and Irregular";

else cout<<"Invalid";

else {

if ( year == 1)

cout<<" \nThe student is First Year and Invalid";

else if ( year == 2)

cout<<" \nThe student is Second Year and Invalid";

else if ( year == 3)

cout<<"\nThe student is Third Year and Invalid";

else if ( year ==4)

cout<<"\nThe student is Fourth Year and Invalid";

else cout<<"Invalid";

2. OUTPUT: Show two(2) sample output - one combination of year level and status and one show
invalid combination.
Honor Pledge
“I affirm that I have not given or received any unauthorized help on this
assignment and that this work is my own.”

You might also like