0% found this document useful (0 votes)
7 views6 pages

Programming Assignment - Class XII

The document outlines a programming assignment consisting of five questions, each requiring the development of a specific program. Tasks include processing sentences to count and rearrange words based on vowel criteria, finding Goldbach pairs for even integers, converting day numbers to dates, and checking for Armstrong and perfect numbers using class structures. The assignment includes instructions for submission and formatting requirements.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views6 pages

Programming Assignment - Class XII

The document outlines a programming assignment consisting of five questions, each requiring the development of a specific program. Tasks include processing sentences to count and rearrange words based on vowel criteria, finding Goldbach pairs for even integers, converting day numbers to dates, and checking for Armstrong and perfect numbers using class structures. The assignment includes instructions for submission and formatting requirements.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Programming Assignment

Question 1.

Write a program to accept a sentence which may be terminated by either '.', '?' or '!' only.
The words may be separated by more than one blank space and are in UPPER CASE.

Perform the following tasks:

Find the number of words beginning and ending with a vowel.


Place the words which begin and end with a vowel at the beginning, followed by the
remaining words as they occur in the sentence.
Test your program with the sample data and some random data:

Example 1

INPUT:
ANAMIKA AND SUSAN ARE NEVER GOING TO QUARREL ANYMORE.

OUTPUT:
NUMBER OF WORDS BEGINNING AND ENDING WITH A VOWEL = 3
ANAMIKA ARE ANYMORE AND SUSAN NEVER GOING TO QUARREL

Example 2

INPUT:
YOU MUST AIM TO BE A BETTER PERSON TOMORROW THAN YOU ARE TODAY.

OUTPUT:
NUMBER OF WORDS BEGINNING AND ENDING WITH A VOWEL = 2
A ARE YOU MUST AIM TO BE BETTER PERSON TOMORROW THAN YOU TODAY

Example 3

INPUT:
LOOK BEFORE YOU LEAP.

OUTPUT:
NUMBER OF WORDS BEGINNING AND ENDING WITH A VOWEL = 0
LOOK BEFORE YOU LEAP
Example 4

INPUT:
HOW ARE YOU@

OUTPUT:
INVALID INPUT

Question 2

A Goldbach number is a positive even integer that can be expressed as the sum of two odd
primes.

Note: All even integer numbers greater than 4 are Goldbach numbers.

Example:

6=3+3
10 = 3 + 7
10 = 5 + 5

Hence, 6 has one odd prime pair 3 and 3. Similarly, 10 has two odd prime pairs, i.e. 3 and 7,
5 and 5.

Write a program to accept an even integer 'N' where N > 9 and N < 50. Find all the odd prime
pairs whose sum is equal to the number 'N'.

Test your program with the following data and some random data:

Example 1

INPUT:
N = 14

OUTPUT:
PRIME PAIRS ARE:
3, 11
7, 7
Example 2

INPUT:
N = 30

OUTPUT:
PRIME PAIRS ARE:
7, 23
11, 19
13, 17

Example 3

INPUT:
N = 17

OUTPUT:
INVALID INPUT. NUMBER IS ODD.

Example 4

INPUT:
N = 126

OUTPUT:
INVALID INPUT. NUMBER OUT OF RANGE

Question 3

Design a program to accept a day number (between 1 and 366), year (in 4 digits) from the
user to generate and display the corresponding date. Also, accept 'N' (1 <= N <= 100) from
the user to compute and display the future date corresponding to 'N' days after the
generated date. Display an error message if the value of the day number, year and N are not
within the limit or not according to the condition specified.

Test your program with the following data and some random data:

Example 1

INPUT:
DAY NUMBER: 255
YEAR: 2018
DATE AFTER (N DAYS): 22

OUTPUT:
DATE: 12TH SEPTEMBER, 2018
DATE AFTER 22 DAYS: 4TH OCTOBER, 2018

Example 2

INPUT:
DAY NUMBER: 360
YEAR: 2018
DATE AFTER (N DAYS): 45

OUTPUT:
DATE: 26TH DECEMBER, 2018
DATE AFTER 45 DAYS: 9TH FEBRUARY, 2019

Example 3

INPUT:
DAY NUMBER: 500
YEAR: 2018
DATE AFTER (N DAYS): 33

OUTPUT:
DAY NUMBER OUT OF RANGE

Example 4

INPUT:
DAY NUMBER: 150
YEAR: 2018
DATE AFTER (N DAYS): 330

OUTPUT:
DATE AFTER (N DAYS) OUT OF RANGE
Question 4

Design a class ArmNum to check if a given number is an Armstrong number or not. [A


number is said to be Armstrong if sum of its digits raised to the power of length of the
number is equal to the number]
Example:
371 = 33 + 73 + 13
1634 = 14 + 64 + 34 + 44
54748 = 55 + 45 + 75 + 45 + 85
Thus, 371, 1634 and 54748 are all examples of Armstrong numbers.
Some of the members of the class are given below:
Class name: ArmNum
Data members/instance variables:
n: to store the number
1: to store the length of the number
Methods/Member functions:
ArmNum (int nn): parameterized constructor to initialize the data member n = nn
int sum_pow(int i): returns the sum of each digit raised to the power of the length of the
number using recursive technique eg., 34 will return 32 + 42 (as the length of the number is
2)
void isArmstrong(): checks whether the given number is an Armstrong number by invoking
the function sum_pow () and displays the result with an appropriate message.
Specify the class ArmNum giving details of the constructor( ), int sum_pow(int) and void
isArmstrong( ). Define a main() function to create an object and call the functions
accordingly to enable the task.

Question 5

Design a class Perfect to check if a given number is a perfect number or not. [A number is
said to be perfect if sum of the factors of the number excluding itself is equal to the original
number]
Example: 6 = 1 + 2 + 3 (where 1, 2 and 3 are factors of 6, excluding itself)
Some of the members of the class are given below:
Class name: Perfect
Data members/instance variables:
num: to store the number
Methods/Member functions:
Perfect (int nn): parameterized constructor to initialize the data member num=nn
int sum_of_factors(int i): returns the sum of the factors of the number(num), excluding itself,
using a recursive technique
void check(): checks whether the given number is perfect by invoking the function
sum_of_factors() and displays the result with an appropriate message
Specify the class Perfect giving details of the constructor(), int sum_of_factors(int) and void
check(). Define a main() function to create an object and call the functions accordingly to
enable the task.

Instructions:

• Write the assignment in a word file. Mail me at: [Link]@[Link]


• Write the program in the following order:
✓ Question, along with problem description(Give the heading problem
description after copying question and describe briefly in your own language,
what the program is about)
✓ Algorithm (don’t write as of now)
✓ Program
✓ Output
✓ Variable description

Submission: After summer vacation

You might also like