Using struct
B) Program Sample Run
Enter the data about the fruit.
Name: Apple
Color: green
Fat: 10
Sugar: 50
Carbohydrate: 100
Here are the details about the fruit.
The fruit's name is Apple.
Its color is green.
It contains 10 amount of fat, 50 amount of sugar, and 100 amount of carbohydrate.
Using Struct
1. Program Sample Run 1
For first point:
Enter the value of x coordinate: 0
Enter the value of y coordinate: 3
For second point:
Enter the value of x coordinate: 4
Enter the value of y coordinate: 0
The distance between two given points is 5.
2. Program Sample Run 2
For first point:
Enter the value of x coordinate: -2.1
Enter the value of y coordinate: 3
For second point:
Enter the value of x coordinate: -9.12
Enter the value of y coordinate: 5
Write a function named SameNumberOfFactors that takes two positive integer arguments and returns 1 if they have the same number of factors and 0 if they have not the same number of factors.
Create a C++ program that reads 5 items and their prices and quantities. The program's basic requirements are as follows.
1.Declare four arrays of five elements each: item, price, quantity, and amount.
2. Declare the functions computeAmount, computeTotalAmount, displayItems, and strNew.
3.The expected output is depicted in the figure below.
strNew code:
//function that will adjust the string into specified length by adding spaces
string strNew(string str, int n) {
int l;
l = n - str.length();
for (int i = 1; i <= l; i++) {
str = str + " ";
}
return str;
}//end of strNew functionOutput Example
Enter Item 1: Milk
Enter the price: 125.75
Enter the quantity: 3
Enter Item 2:
Enter Item 3:
Enter Item 4:
Enter Item 5:
Amount: 377.25
Total Amount: 377.25
=========================
Item Qty Price Amount
Milk 3 125.75 377.25
Cake 2 500 1000
Spaghetti 1 700 700
Fruits 10 50 500
Waffle 7 45 315
When will the ‘while’ loop be preferred over the for loop? Mention the scenario and write the
programme to demonstrate this?
Write an algorithm that displays an equivalent color once an input letter matches its first character.
For example b for Blue, r for Red, and so on. Here are the given criteria: (The letters as an input data and the color as output information).
Letters Color
‘B’ or ‘b’ Blue
‘R’ or ‘r’ Red
‘G’ or ‘g’ Green
‘Y’ or ‘y’ Yellow
Other letters “Unknown Color”
write a menu-driven program that asks the user to select a favorite color from the given colors. Keep asking the user three times for selecting the color from the list of the available colors. Do this with the help of a suitable loop and switch statement. Finally, you have to display the three favorite colors of the user.
Write a C++ program using a nested for loop to create multiplication table.
sample Output:
1 2 3 4 5 6 7 8 9 10
6
7
8
9
10
Using while loop, write a C++ program that will allow the users to enter the number of quizzes to compute and the program will automatically compute the average of the quizzes.
Sample Output:
Output:
Enter Number of Quiz: 4
Quiz 1: 90
Quiz 2: 89
Quiz 3: 94
Quiz 4: 100
Average: 93
Write a c++ program to find the length of the skirting board.Where she wants to replace the old skirting board and the coving 2.7,4.1m 32m(All dimensions in Meter)with the door of 0.86 x 2.06meters