0% found this document useful (0 votes)
6 views10 pages

Csc201 Assignment Fcp

The document contains a series of C++ programming assignments, each requiring the creation of a specific program to perform various calculations or checks, such as summing numbers, calculating areas, and determining eligibility criteria. Each assignment includes a brief description followed by the corresponding C++ code. The tasks range from basic arithmetic operations to more complex logic involving loops and conditionals.

Uploaded by

fahatadam4u
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)
6 views10 pages

Csc201 Assignment Fcp

The document contains a series of C++ programming assignments, each requiring the creation of a specific program to perform various calculations or checks, such as summing numbers, calculating areas, and determining eligibility criteria. Each assignment includes a brief description followed by the corresponding C++ code. The tasks range from basic arithmetic operations to more complex logic involving loops and conditionals.

Uploaded by

fahatadam4u
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
You are on page 1/ 10

CSC201 ASSIGNMENT

Name: Abubakar Umar Faruq


Reg No: FCP/CSE/23/1026

Q1. Write a C++ program that calculates the sum of two numbers entered by the user and displays the
result.

#include <iostream>
using namespace std;
int main() {
int num1, num2, result;
cout << "--Sum of two numbers--" << endl;
cout << "Enter two numbers: ";
cin >> num1 >> num2;
result = num1 + num2;
cout << num1 << " + " << num2 << " = " << result << endl;

return 0;
}
Q2. Write a C++ program that calculates the area of a rectangle. Prompt the user to enter the length
and width, then display the area.

#include <iostream>
using namespace std;
int main() {
double length, width, result;
cout << "--Area of a rectangle calculator--" << endl;
cout << "Area = length x width" << endl;
cout << "Enter the length(m): ";
cin >> length;
cout << "Enter the width(m): ";
cin >> width;
result = length * width;
cout << "Area = " << result <<" square meter." <<endl;
return 0;
}
Q3. Create a C++ program that reads the radius of a circle from the user and calculates the
circumference.

#include <iostream>
using namespace std;
int main() {
cout << "--Circumference of a circle--" << endl;
double radius, circumference, pi = 3.142;

cout << "Enter radius(m): ";


cin >> radius;
circumference = 2 * pi * radius;
cout << "Circumference: " << circumference << endl;
return 0;
}

4. Write a C++ program to calculate and display the perimeter of a square given the side length
entered by the user.

#include <iostream>
using namespace std;
int main() {
double length, perimeter;
cout << "--Perimeter of a square--" << endl;
cout << "Enter the length(m): ";
cin >> length;
perimeter = 4 * length;
cout << "Perimeter = " << perimeter <<"m"<< endl;
return 0;
}

Q5. Develop a C++ program to find the simple interest. The user should input Principal, Rate, and
Time.

#include <iostream>
using namespace std;
int main() {
double principal, rate, time,sI;
cout << "--Simple interest calculator--" << endl;
cout << "Enter the principal amount($): ";
cin >> principal;
cout << "Enter the rate(%): ";
cin >> rate;
cout << "Enter the time(years): ";
cin >> time;
sI = (principal * rate * time) / 100;
cout << "Simple Interest = " << "$" << sI << endl;
return 0;

Q6. Create a C++ program to convert temperature from Celsius to Fahrenheit. Prompt the user for the
temperature in Celsius and display the equivalent in Fahrenheit.

#include <iostream>
using namespace std;
int main() {
double celcius, fahrenheit;
cout << "--Celcius to fahrenheit--" << endl;
cout << "Enter the celcius: ";
cin >> celcius;
fahrenheit = ((celcius * 9) / 5) + 32;
cout << "Fahrenheit = " << fahrenheit << endl;
return 0;
}

Q7. Write a C++ program to compute the average of three numbers entered by the user.

#include <iostream>
using namespace std;
int main()
{
double num1, num2, num3, result;
cout << "--Avarage of three numbers---"<<endl;
cout << "Enter three numbers: ";
cin >> num1 >> num2 >> num3;
result = (num1 + num2 + num3) / 3;
cout << "The avarage of " << num1 << " " << num2 << " " << num3 << " is " <<
result << endl;
return 0;
}

Q8. Write a C++ program to find the volume of a cube. Let the user enter the side length.

#include <iostream>
using namespace std;
int main() {
double length, volume;
cout << "--Volume of a cube--" << endl;
cout << "Enter the length(cm): ";
cin >> length;
volume = length * length * length;
cout << "Volume = " << volume << " centimeter cube" << endl;
return 0;
}

Q9. Write a C++ program that accepts the price of an item and a discount percentage, then calculates
and displays the final price after discount.

#include <iostream>
using namespace std;
int main() {
float price, dPercent, dAmount, fPrice;
cout << "--Discount Calculator--" << endl;
cout << "Enter the price of an Item: ";
cin >> price;
cout << "Enter the discount percentage: ";
cin >> dPercent;
dAmount = (dPercent / 100) * price;
fPrice = price - dAmount;
cout << "Final price after discount = " << fPrice << endl;
return 0;
}
Q10. Write a C++ program that accepts two integers and displays their sum, difference, product, and
quotient.

#include <iostream>
using namespace std;
int main() {
int num1, num2, sum, difference, product;
cout << "--Calculator--" << endl;
cout << "Enter two integers: ";
cin >> num1 >> num2;
sum = num1 + num2;
difference = num1 - num2;
product = num1 * num2;
cout << num1 << " + " << num2 << " = " << sum << endl;
cout << num1 << " - " << num2 << " = " << difference << endl;
cout << num1 << " x " << num2 << " = " << product << endl;

float quotient = (float)num1 / num2;


cout << num1 << " / " << num2 << " = " << quotient << endl;
return 0;
}

Q11. Write a C++ program that reads an integer from the user and determines if it is positive,
negative, or zero.

#include <iostream>
using namespace std;
int main() {
int num;
cout << "--Positive or Negetive Number--" << endl;
cout << "Enter a number: ";
cin >> num;
if (num > 0) {
cout << num << " is a positive number." << endl;
}
else if (num == 0) {
cout << num << " is a neutral number." << endl;
}
else {
cout << num << " is a negetive number." << endl;
}
return 0;
}

Q12. Write a C++ program that accepts a student's score and checks whether the student passed
(score ≥ 50) or failed.

#include <iostream>
using namespace std;
int main() {
int score;
cout << "--Grade calculator--" << endl;
cout << "<Enter your score. ";
cin >> score;
if (score >= 50) {
cout << "You have passed..." << endl;
}
else {
cout << "You have failed..." << endl;
}
return 0;
}

Q13. Create a C++ program to check if a number entered by the user is even or odd.

#include <iostream>
using namespace std;
int main() {
int num;
cout << "--Even or Odd--" << endl;
cout << "Enter a number: ";
cin >> num;
if (num % 2 == 0) {
cout << num << " is an even number." << endl;
}
else {
cout << num << " is an odd number." << endl;
}
return 0;
}

Q14. Develop a C++ program that asks for a user's age and checks if the user is eligible to vote (age ≥
18).

#include <iostream>
using namespace std;
int main() {
int age;
cout << "--Vote eligibility--" << endl;
cout << "Enter your age: ";
cin >> age;

if (age >= 18) {


cout << "You are eligible to vote." << endl;
}
else {
cout << "You are not eligible to vote." << endl;
}
return 0;
}

15. Write a C++ program to find the largest of two numbers entered by the user.

#include <iostream>
using namespace std;
int main(){
int num1, num2;
cout << "--Largest of two numbers--" << endl;
cout << "Enter two numbers: ";
cin >> num1 >> num2;
if (num1 > num2) {
cout << num1 << " is greater than " << num2 << endl;
}
else if (num2 > num1) {
cout << num2 << " is greater than " << num1 << endl;
}
else {
cout << "The numbers are equal." << endl;
}
}

Q16. Create a C++ program that reads a temperature value and prints whether it is hot (above 30°C) or
not hot.

#include <iostream>
using namespace std;
int main() {
int temp;
cout << "--Tempreture--" << endl;
cout << "Enter the tempreture: ";
cin >> temp;
if (temp > 30) {
cout << "The tempreture is high!!!" << endl;
}
else {
cout << "The tempreture is low!!!" << endl;

}
return 0;
}

Q17. Write a C++ program that accepts the marks of a student and prints 'Distinction' if marks are
above 75.

#include <iostream>
using namespace std;
int main() {
int mark;
cout << "Enter your score: ";
cin >> mark;
if (mark >= 75) {
cout << "Distinction." << endl;
}
else {
cout << "You passed." << endl;
}
return 0;
}

Q18. Write a C++ program that asks for a number and checks whether it is a multiple of 5.

#include <iostream>
using namespace std;
int main()
{
int num;
cout << "--Multiple of 5--" << endl;
cout << "Enter a number: ";
cin >> num;
if (num % 5 == 0) {
cout << num << " is a multiple of 5." << endl;
}
else {
cout << num << " is not a multiple of 5." << endl;
}
}

Q19. Create a C++ program that accepts two integers and checks if they are equal.

#include <iostream>
using namespace std;
int main() {
int num1, num2;
cout << "--Number equality--" << endl;
cout << "Enter two numbers: ";
cin >> num1 >> num2;
if (num1 == num2) {
cout << "The number are equal." << endl;
}
else {
cout << "The number are not equal." << endl;
}
}

Q20. Write a C++ program to check if a year entered by the user is a leap year or not (simplified, year
divisible by 4).

#include <iostream>
using namespace std;
int main() {
int year;
cout << "Enter a year: ";
cin >> year;
if (year % 4 == 0) {
cout << year << " is a leap year." << endl;
}
else {
cout << year << " is not a leap year." << endl;
}
return 0;
}

Q21. Write a C++ program that prints all even numbers between 1 and 20 using a loop.

#include <iostream>
using namespace std;
int main() {
for (int i = 2; i <= 20; i += 2) {
cout << i << endl;
}
}
Q22. Write a C++ program that reads 10 numbers from the user and counts how many of them are
positive.

#include <iostream>
using namespace std;
int main() {
int num, pNumber=0;
cout << "Enter 10 numbers." << endl;
for (int i = 1; i <= 10; i++) {
cout << "Number " << i << ": ";
cin >> num;

if (num > 0) {
pNumber++;
}
}
cout << "You entered " << pNumber << " positive numbers." << endl;
return 0;
}

Q23. Create a C++ program to find and display the factorial of a number entered by the user.

#include <iostream>
using namespace std;
int main() {
int num;
long factorial = 1;
cout << "Enter a number: ";
cin >> num;
for (int i = 1; i <= num; i++) {
factorial *= i;
}
cout << "The factorial of " << num << " is " << factorial << endl;
return 0;
}

Q24. Write a C++ program that asks the user to enter 5 integers and displays the maximum number
among them.

#include <iostream>
using namespace std;
int main() {
int num, maxNumber = 0;
cout << "Enter 5 numbers..." << endl;
for (int i = 1; i <= 5; i++) {
cout << i << " number: ";
cin >> num;
if (num > maxNumber) {
maxNumber = num;
}
}
cout << "The maximum number is: " << maxNumber << endl;
return 0;
}
25. Develop a C++ program that continuously asks the user to enter numbers until the user enters -1.
Then, display the sum of all entered numbers (excluding -1).

#include <iostream>
using namespace std;
int main() {
int num, sum = 0;
cout << "Enters numbers(enter -1 to stop)" << endl;
while (true) {
cin >> num;
if (num == -1) {
break;
}
sum += num;
}
cout << "The sum of all numbers entered is: " << sum << endl;
return 0;
}

Q26. Write a C++ program that accepts 5 numbers from the user and displays only the odd numbers
among them.

#include <iostream>
using namespace std;
int main() {
int num;
cout << "Enter 5 numbers." << endl;
for (int i = 1; i <= 5; i++) {
cin >> num;
if (num % 2 != 0) {
cout << "Odd numbers = " << num<<endl;
}
}
}

Q27. Write a C++ program that prints the multiplication table of a number entered by the user (up to
12).

#include <iostream>
using namespace std;
int main() {
int num;
cout << "Enter a number: ";
cin >> num;
for (int i = 1; i <= 12; i++) {
cout << num << " x " << i << " = " << num * i << endl;
}
}
28. Create a C++ program to find the sum of all odd numbers between 1 and 50 using a loop.

#include <iostream>
using namespace std;
int main() {
int sum = 0;
for (int i = 1; i <= 50; i++) {
if (i % 2 != 0) {
sum += i;
}
}
cout << sum;
}

Q29. Develop a C++ program that reads numbers until the user enters zero, and then displays the
number of even numbers entered.

#include <iostream>
using namespace std;
int main() {
int num;
int addNum = 0;
cout << "Enter numbers(enter 0 to stop)." << endl;
while (true) {
cin >> num;
if (num == 0) {
break;
}
if (num % 2 == 0) {
addNum += num;
}
}
cout << "The sum of even number entered is: " << addNum << endl;
return 0;
}

30. Write a C++ program that asks the user to enter 5 scores and then displays how many of them are
greater than or equal to 50.

#include <iostream>
using namespace std;
int main()
{
int score, count = 0;
for (int i = 1; i <= 5; i++) {
cout << "Enter score " << i << ": ";
cin >> score;
if (score >= 50) {
count ++;
}
}
cout << count;
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy