0% found this document useful (0 votes)
8 views

Assignment 1- C

assignment of C++- GIKI
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)
8 views

Assignment 1- C

assignment of C++- GIKI
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/ 3

CS101 PAGE 1

Computing and AI
Assignment # 1
(Deadline: 15/10/2024)

REG#: __________________ NAME: ____________________________________

COURSE CODE: CS101 INSTRUCTOR: MUHAMMAD TALHA


TOTAL MARKS: 84
--------------------------------------------------------------------------------------------------------------------------------------------------------------
Applications of C++ Programming in Computer Science

Objective

This assignment focuses on applying C++ programming skills to real-world problems in computer science. You will tackle
tasks involving date manipulation, volume calculations, temperature conversions, and cost estimations. Each task is
designed to enhance your coding abilities and problem-solving techniques. By completing this assignment, you will gain
valuable experience in using C++ effectively, preparing you for future challenges in the tech industry.

General Instructions:

• Create a different file for each question & assignment.


• The name of each file should contain your roll number, assignment number & question number in a specific format.
• For Example, if your roll number is 2022532 you are doing 2nd assignment and question no 5 then file name of
your C++ file should be written as ---> 2022532_2_5.cpp (similarly, create for each question)
• Submission: zip all files and upload to teams.

Task 1: Write a program that, given a date, three ints (for example, 11 27 1997), will print the number of that day within
its year: i.e. Jan 1st is always 1, Dec 31st is either 365 or 366. (CLO2, PLO1) (08 marks)
The months of the year have lengths according to the following rules:
1. The odd months up to and including month 7 have 31 days.
2. The even months from 8 upwards, have 31 days.
3. Month 2 has 28 days except in a leap year when it has 29 days.
4. The rest of the months have 30 days.

Task 2: Write a program in C++ that reads in a date (day, month, year) as three integers and prints the corresponding day
of the week (Monday, Tuesday, ..., Sunday). Consider the valid date range from January 1, 2000, to December 31, 2023. For
example, August 15, 2023, is a Tuesday. Use this information to ensure that your program correctly calculates the day of
the week for the input date. (CLO2, PLO1) (12 marks)

Task 3: Given the following rules, write a program to read a year (4-digit integer) and tell whether the given year is/was a
leap year. (CLO2, PLO1) (08 marks)
1. There were no leap years before 1752.
2. If the year divides by 400 then it is a leap year.
3. All other years that divide by 100 are not leap years.
4. All other years that divide by four are leap years.
For example, 1800,1900 were not leap years but 2000 will be; 1904, 1908, … ,1996 were/will be leap years.

Task 4: In construction projects, civil engineers often need to determine how much concrete is needed for a structure.
Write a C++ program that helps with this calculation and categorizes the project type based on the calculated volume. The
program should do the following. (CLO2, PLO1) (10 marks)

1. Ask the user to input the length, width, and height of a concrete structure in meters.
CS101 PAGE 2

2. Calculate and display the total volume of concrete required in cubic meters.
3. If the volume is less than or equal to 30 cubic meters, classify it as a "Small Project."
4. If the volume is between 30 and 100 cubic meters (inclusive), classify it as a "Medium Project."
5. If the volume exceeds 100 cubic meters, classify it as a "Large Project."
Sample Output

Enter the length of the concrete structure (in meters): 5


Enter the width of the concrete structure (in meters): 4
Enter the height of the concrete structure (in meters): 3

The total volume of concrete needed is 60 cubic meters.


This is a Medium Project.

Task 5: In structural engineering, one of the crucial tasks is to assess the load-bearing capacity of walls in construction
projects. Load-bearing walls support the structural integrity of a building. They must be able to safely bear the weight and
forces applied to them. As a structural engineer, you need to develop a C++ program to evaluate whether a given wall can
safely bear a specific load or if it requires reinforcement. (CLO2, PLO1) (10 marks)

Your program should perform the following steps:

6. Prompt the user to enter the applied load (in newtons) on the wall.
7. Prompt the user to provide the dimensions of the wall (length, width, and height).
8. Calculate the total wall area based on the provided dimensions.
9. Determine the load per unit area by dividing the applied load by the wall's total area.
10. Use a specific safety threshold (you can define this, e.g., 15 N/m²) to determine if the load per unit area is within
the safe range.
11. Display a message to inform the user whether the wall can safely bear the load or if it requires reinforcement based
on the calculated load per unit area.

Task 6: Temperature conversion is a common task in chemical engineering. Write a C++ program that converts a
temperature given by the user from Fahrenheit to Celsius and vice versa. Show appropriate error messages to user for
invalid inputs. Read this article to get a better understanding of temperature conversions and about valid, invalid inputs.
(CLO2, PLO3) (08 marks)

Task 7: Write a C++ program for cost estimation. This program takes user input for the quantity and unit price of a material
such as steel. Calculates the total cost for the steel and displays it to the user. Show appropriate error messages for valid
and invalid inputs (positive, negative values). (CLO2, PLO1) (05 marks)

Task 8: Write a program in C++ that takes age in years from the user and first shows the age of user in months and then
show the age in days separately. (CLO2, PLO1) (08 marks)

Hint: As we know that a year contains 12 months so if a child is 2 years, then his/her age will be 2 x 12 means 24 months. Similarly, you
can find days for the same child.

Task 9: Dream-Tech is an international organization which provides different kinds of allowances to its employees. Each
employee at Dream-Tech gets the following allowances as percentage of their basic salary: (CLO2, PLO1) (15 marks)

• House Allowance 30% of basic salary


• Transport Allowance 10% of basic salary
• Medical Allowance 25% of basic salary
CS101 PAGE 3

Your job is to create a C++ program that takes the employee's name (explore string data type) and basic salary as input
from the user. Then, calculate the allowances based on the provided percentages and display the total or gross salary by
adding the allowances to the basic salary. Also display the calculated allowances to the user. Your output should be
something like the following:
Sample Output

Welcome to the Employee Salary Calculator!

Please enter the employee's name: sajid ali


Please enter the basic salary of sajid ali: 50000

Calculating the allowances...


House Rent Allowance: 15000 Rs.
Transport Allowance: 5000 Rs.
Medical Allowance: 12500 Rs.

Calculating the gross salary...

Employee Name: sajid ali


Basic Salary: 50000 Rs.
Total Gross Salary: 82500 Rs.

Thank you for using the Employee Salary Calculator!


Submission

1. See general instructions section please.

You might also like