Q1.
A small bookstore wants to keep a simple record of a book.
Write a program that stores the details of a book - its title, author name, price and category (a predefined set of categories such as Fiction, Non-Fiction, Science, History etc.). Once the book details are stored, display them on the screen.
Expected Output:
--- Book Details ---
Title : Awareness
Author : JAnthony De Mello
Price : 599.00
Category : SpiritualityQ2.
What will be the output of the following programs?
You have to predict the output yourself without running/executing the code.
I.
#include <iostream> struct Employee { int id; int age; double wage; }; int main() { Employee joe; std::cout << "ID: " << joe.id << '\n'; return 0; }II.
#include <iostream> struct Employee { int id; int age; double wage; }; int main() { Employee joe {}; std::cout << "ID: " << joe.id << '\n'; return 0; }III.
#include <iostream> struct Employee { int id {}; int age {}; double wage {}; }; int main() { Employee joe; std::cout << "ID: " << joe.id << '\n'; return 0; }IV.
#include <iostream> struct Foo { int a; int b {}; int c { 2 }; }; int main() { Foo foo1; std::cout << foo1.a << ' ' << foo1.b << ' ' << foo1.c << '\n'; return 0; }V.
#include <iostream> struct Foo { int a; int b {}; int c { 2 }; }; int main() { Foo foo1 { 5, 7, 8 }; std::cout << foo1.a << ' ' << foo1.b << ' ' << foo1.c << '\n'; return 0; }VI.
#include <iostream> struct Foo { int a; int b {}; int c { 2 }; }; int main() { Foo foo1 {}; std::cout << foo1.a << ' ' << foo1.b << ' ' << foo1.c << '\n'; return 0; }
Q3.
What will be the output of the following programs?
You have to predict the output yourself without running/executing the code.
I.
#include <iostream> struct Foo { int a { }; int b { }; int c { }; }; int main() { Foo foo { .b{ 2 }, .a{ 1 } }; std::cout << "a: " << foo.a << ", b: " << foo.b << ", c: " << foo.c << '\n'; return 0; }II.
#include <iostream> struct Foo { int a {}; int b {}; int c {}; }; int main() { Foo foo1{ 1, 2, 3}; Foo foo2 = foo1; std::cout << foo1.a << ' ' << foo1.b << ' ' << foo1.c << '\n'; std::cout << foo2.a << ' ' << foo2.b << ' ' << foo2.c << '\n'; return 0; }III.
#include <iostream> struct Employee { int id {}; int age {}; double wage {}; }; int main() { Employee joe {1, 32, 60000.0}; std::cout << "ID: " << joe.id << ", age: " << joe.age << ", wage: " << joe.wage << '\n'; joe = {.id = joe.id, .age = 33, .wage = 66000.0}; std::cout << "ID: " << joe.id << ", age: " << joe.age << ", wage: " << joe.wage << '\n'; return 0; }
Q4.
You’re building a small calculator that helps users multiply two fractions.
The program should ask the user to enter two fractions one by one (numerator and denominator separately for each). Once both fractions are entered, the program should multiply them and display the result in the form numerator/denominator.
Expected Output:
Enter a value for the numerator: 1
Enter a value for the denominator: 2
Enter a value for the numerator: 3
Enter a value for the denominator: 4
Your fractions multiplied together: 3/8Q5.
What will be the output of the following programs?
You have to predict the output yourself without running/executing the code.
I.
#include <iostream> struct Employee { int id {}; int age {}; double wage {}; }; void printEmployee(const Employee& employee) { std::cout << "ID: " << employee.id << '\n'; std::cout << "Age: " << employee.age << '\n'; std::cout << "Wage: " << employee.wage << '\n'; } int main() { printEmployee({ 15, 28, 18.27 }); return 0; }II.
#include <iostream> struct Employee { int id {}; int age {}; double wage {}; }; Employee& getEmployee() { Employee employee; std::cout << "Enter id: "; std::cin >> employee.id; std::cout << "Enter age: "; std::cin >> employee.age; std::cout << "Enter wage: "; std::cin >> employee.wage; return employee; } void printEmployee(const Employee& employee) { std::cout << "ID: " << employee.id << '\n'; std::cout << "Age: " << employee.age << '\n'; std::cout << "Wage: " << employee.wage << '\n'; } int main() { Employee employee = getEmployee(); printEmployee(employee); return 0; }
Q6.
You run a website that earns money through advertisements. Create a small tool that helps you calculate your daily earnings from ads.
The program should ask for:
- The total number of ads that were watched.
- The percentage of users who clicked on an ad.
- The average money earned from each clicked ad.
Once the inputs are taken, the program should display all the entered values clearly. It should also show the total money earned that day by multiplying all three values.
Expected Output:
Enter the number of ads watched: 1000
Enter the percentage of users who clicked on an ad: 12.5
Enter the average earnings per clicked ad: 0.75
Ads watched: 1000
Click-through rate: 12.5%
Earnings per clicked ad: 0.75
Total earnings today: 93.75