Question

Programming Fundamental (C++) Lab C++ Lab Rafat Amareh Faculty of Engineering and Information Technology Assignment Write a
0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE IN C++ :

#include<bits/stdc++.h>

using namespace std;

float factorial(float n)
{
return (n==1 || n==0) ? 1: n * factorial(n - 1);
}

void F()
{
cout << "Enter value of n to print a series upto n terms\n";
int n;
cin >> n;
int i = 2,k = 1,l = 3,j = 1;
float ans=0;
while(j<=n){
ans+=(pow(k,i)/factorial(l));
i+=2;
k+=1;
l+=2;
j+=1;
}
cout << "Value of the series is ...\n" << ans;
}

void SumOddDigits(int n){
int r,sd=0;
while ( n > 0)
{
r = n % 10;
if(r%2!=0)
{
sd = sd + r;
}
n = n/ 10;
}

cout << "Sum of Odd digits for given number is " << sd;

}

void PrintDigits(int n){
int d;
cout << "Digits of given number are \n";
while(n!=0){
d=n%10;
n=n/10;
cout << d << " ";
}

}

void Shape(int n){
cout << "Required Pattern is \n";
for(int i = 0;i < n;i++){
for(int j = 0;j <= i;j++){
if(j%2==0)
cout << "1" << " ";
else
cout << "0" << " ";
}
cout << "\n";
}

}

int a[6];

void FillArray(){
cout << "Enter 5 elements to fill in array\n";
cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];
cout << "Array filled with given elements\n";

}

void Largest(){
int m=-1000000;
for(int i = 0;i < 5;i++){
if(a[i]>m)
m=a[i];
}
cout << "Largest Element in the array is " << m;

}

int main()
{
int choice;
do{
cout << "\nMain Menu : \n a) Press 1 to perform Sin(x),series.\n b) Press 2 to perform Sum Odd digits , Print digits , Print Shape.\n c) Press 3 to perform Array.\n d) Press 0 to exit.";
cout << "\n\n Please Enter you choice\n";
cin >> choice;
switch(choice){

case 1 :
int choice1;
do{
cout << "\n 1) Press 1 to perform Sin(x).\n 2) Press 2 to compute a series named F.\n 3) Press 3 to return to main menu.";

cout << "\n\n Please Enter you choice\n";
cin >> choice1;
switch(choice1){

case 1:
cout << "Enter Value of x \n";
float x;
cin >> x;
cout << "Value of sin(x) is " << sin(x);
cout << "\n";
break;

case 2:
F();
cout << "\n";
break;

}
}
while(choice1!=3);


case 2:
if (choice1==3){
choice1=0;
break;
}
int choice2;
do{
cout << "\n 1) Press 1 to Sum Odd Digits.\n 2) Press 2 to Print Digits. F\n 3) Press 3 to Print Shape.\n 4) Press 4 to return to main menu.";

cout << "\n\n Please Enter you choice\n";
cin >> choice2;
switch(choice2){

case 1:
int x1;
cout << "Enter a number to sum its odd digits.\n";
cin >> x1;
SumOddDigits(x1);
cout << "\n";
break;

case 2:
int x2;
cout << "Enter a number to print its digits.\n";
cin >> x2;
PrintDigits(x2);
cout << "\n";
break;

case 3:
int x3;
cout << "Enter number of rows to print a shape.\n";
cin >> x3;
Shape(x3);
cout << "\n";
break;
}
}
while(choice2!=4);

case 3:
if(choice2==4){
choice2=0;
break;
}
int choice3;
do{
cout << "\n 1) Press 1 to Fill an array with 5 elements.\n 2) Press 2 to Print Largest element in an array.\n 3) Press 3 to return to main menu.";

cout << "\n\n Please Enter you choice\n";
cin >> choice3;
switch(choice3){

case 1:
FillArray();
cout << "\n";
break;

case 2:
Largest();
cout << "\n";
break;

}
}
while(choice3!=3);

}
}
while(choice!=0);

}

Add a comment
Know the answer?
Add Answer to:
Programming Fundamental (C++) Lab C++ Lab Ra'fat Amareh Faculty of Engineering and Information Technology Assignment Write...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a C program Design a program that uses an array to store 10 randomly generated...

    Write a C program Design a program that uses an array to store 10 randomly generated integer numbers in the range from 1 to 50. The program should first generate random numbers and save these numbers into the array. It will then provide the following menu options to the user: Display 10 random numbers stored in the array Compute and display the largest number in the array Compute and display the average value of all numbers Exit The options 2...

  • **IN C*** * In this lab, you will write a program with three recursive functions you...

    **IN C*** * In this lab, you will write a program with three recursive functions you will call in your main. For the purposes of this lab, keep all functions in a single source file: main.c Here are the three functions you will write. For each function, the output example is for this array: int array[ ] = { 35, 25, 20, 15, 10 }; • Function 1: This function is named printReverse(). It takes in an array of integers...

  • Using C++ language please not matlab a. Write a function, called SumOfDigits that is able to...

    Using C++ language please not matlab a. Write a function, called SumOfDigits that is able to calculate the summation of a five-digit number. This function receives one integer parameter 'a', then returns the sum of 5 digits of the number. [2.5 marks] b. Write a function, called Armstrong that prints all Armstrong numbers in the range of 0 and 500. An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is...

  • C++ programming For this assignment, write a program that will act as a geometry calculator. The...

    C++ programming For this assignment, write a program that will act as a geometry calculator. The program will be menu-driven and should continue to execute as long as the user wants to continue. Basic Program Logic The program should start by displaying a menu similar to the following: Geometry Calculator 1. Calculate the area of a circle 2. Calculate the area of a triangle 3. Quit Enter your choice(1-3): and get the user's choice as an integer. After the choice...

  • In C++ please! Please include .cpp and .hpp files! Thank you! Recursive Functions Goals Create and...

    In C++ please! Please include .cpp and .hpp files! Thank you! Recursive Functions Goals Create and use recursive functions In this lab, we will write a program that uses three recursive functions. Requirements: Important: You must use the array for this lab, no vectors allowed. First Recursive Function Write a function that recursively prints a string in reverse. The function has ONLY one parameter of type string. It prints the reversed character to the screen followed by a newline character....

  • dont use switch E) 120 pts.] Write another function int main ) in C++(and comment the...

    dont use switch E) 120 pts.] Write another function int main ) in C++(and comment the main in Q1.D) that displays the following menu using a do while loop: please choose from the following Menu: I: Populate array with 5 elements 2: Print Array 3: Reverse Array 0: Exit Based, on the user choice, you should call the appropriate function. For example, if the user: - chooses 1, then in function main you should call function populateArray (A, 5); -...

  • ‘C’ programming language question Write a MENU DRIVEN program to A) Count the number of vowels...

    ‘C’ programming language question Write a MENU DRIVEN program to A) Count the number of vowels in the string B) Count the number of consonants in the string C) Convert the string to uppercase D) Convert the string to lowercase E) Display the current string X) Exit the program The program should start with a user prompt to enter a string, and let them type it in. Then the menu would be displayed. User may enter option in small case...

  • Write a C program to do the following 1) request user to enter 10 integer into...

    Write a C program to do the following 1) request user to enter 10 integer into an array 2) sort the array in ascending order 3) display the sorted array 4) count the number of odd and even number in the array and print out the result 5) add the value of the odd number and even number and calculate the average of the odd and even number. display the result 6) write function addNumber() to add all the number...

  • I have to use java programs using netbeans. this course is introduction to java programming so...

    I have to use java programs using netbeans. this course is introduction to java programming so i have to write it in a simple way using till chapter 6 (arrays) you can use (loops , methods , arrays) You will implement a menu-based system for Hangman Game. Hangman is a popular game that allows one player to choose a word and another player to guess it one letter at a time. Implement your system to perform the following tasks: Design...

  • (+30) Provide a python program which will Populate an array(list) of size 25 with integers in...

    (+30) Provide a python program which will Populate an array(list) of size 25 with integers in the range -100 (negative 100)   to +100 inclusive Display the array and its length (use the len function) Display the average of all the integers in the array Display the number of even integers (how many) Display the number of odd integers (how many) Display the number of integers > 0   (how many) Display the number of integers < 0   (how many) Display the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT