0% found this document useful (0 votes)
26 views5 pages

Assignment 3 F22 - Update1

Uploaded by

Ayesha Urooj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views5 pages

Assignment 3 F22 - Update1

Uploaded by

Ayesha Urooj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Department of Computer Science,

Faculty of Computer Science & Information Technology,


The Superior University Gold Campus, Lahore.

Programming Fundamentals-CS-1104
Fall 2022
Assignment 03

Name : Ayesha Urooj


Roll no.: su92-bscsm-f22-107
Section: BSCS-1C
Instructor: DR. IRFAN UD DIN

Question 1. Develop C++ programs for the following


1.1 a. Write a C++ program that ask the user to enter the marks 5 courses for a class consists of
50 students; the program calculates and display the average marks individual student as well as
the class average.
1.1 b. Modify the above program such that number of courses and class size is not fixed, a
student can enter marks for 1 to 5 courses, and the class maximum size can be 50.
1.1 c. Modify the program such that a student can enroll a minimum of 3 courses and maximum
5, the class sizes can varies from 1 to 50.
Modifications 1: Modify question 1 as follow and save as Q1v1
a. Use an array to store average marks of each student of the class, display the data
stored in array.
b. Find the deviation of each student from the class average, for example class average is
65 and a student average is 70, the deviation will be +5.
#include<iostream> }
using namespace std; while(ch=='Y' && c<=50);
int main() cout<<"No. of students:"<<c<<endl;
{ c_avg=c_sum/c;
int sum,m,c=0,c_sum=0; cout<<"Class Average="<<c_avg<<endl;
float avg[50],c_avg; cout<<"*****************************
char ch; *******\n";
do cout<<"Student averages "<<endl;
{ cout<<"*****************************
sum=0; *******\n";
for(int i=1;i<=5;i++) for(int k=0;k<c;k++)
{ {cout<<"Student = "<<avg[k]<<endl;
cout<<"Enter "<<i<<" the subject int deviation=c_avg-avg[k];
marks:"; cout<<"Deviation(class avg - student
cin>>m; avg)="<<deviation<<endl;
sum=sum+m; cout<<"*****************************
} *******\n";
avg[c]=sum/5; }
c_sum=c_sum+avg[c]; cout<<"\n\n(Name=Ayesha Urooj\nRoll
cout<<"Student Average="<<avg[c]<<endl; no.=su92-bscsm-f22-107\nQuestion
cout<<"Do you want to find avg of another no.1v1(1.1 b))"<<endl;
student"<<endl<<"Press 'Y' for yes & 'N' for return 0;
No:"; }
cin>>ch;
c++;
#include<iostream> c_sum=c_sum+avg[c];
using namespace std; cout<<"Student
int main() Average"<<"="<<avg[c]<<endl;
{ cout<<"Do you want to find avg of another
int sum,m,c=0,c_sum=0; student"<<endl<<"Press 'Y' for yes & 'N' for
float avg[50],c_avg; No:";
char ch,ch_course; cin>>ch;
do c++;
{ int i; }
sum=0; while(ch=='Y' && c<=50);
for(i=1;i<=2;i++) cout<<"No. of students:"<<endl;
{ c_avg=c_sum/c;
cout<<"Enter "<<i<<" the subject cout<<"Class Average="<<c_avg<<endl;
marks:"; cout<<"*****************************
cin>>m; *******\n";
sum=sum+m; cout<<"Student averages "<<endl;
} cout<<"*****************************
do *******\n";
{ for(int k=0;k<c;k++)
cout<<"Enter "<<i<<" the subject {cout<<"Student = "<<avg[k]<<endl;
marks:"; int deviation=c_avg-avg[k];
cin>>m; cout<<"Deviation(class avg - student
sum=sum+m; avg)="<<deviation<<endl;
cout<<"Bhai koi dusra no add krna cout<<"*****************************
hai agr nahi to Press 'N' agr haan bhai to *******\n";
Press 'Y':"; }
cin>>ch_course; cout<<"\n\n(Name=Ayesha Urooj\nRoll
i++; no.=su92-bscsm-f22-107\nQuestion
} no.1v1)"<<endl;
while(ch_course=='Y' && i<6); return 0;
cout<<"No. of course : "<<--i<<endl; }
avg[c]=sum/i;
2.1 a. A store deals in 3 products namely TV, AC and Refrigerator; the store has an initial
amount of PKR 500000 in its account and zero stock for products. You are required to develop a
C++ application for the operations of the store. The operations includes the following
Write separate function for each operation,
1. Purchase: purchasing products from company;
Prototype: void purchase(int quantity, int price, int product_type)
Product type (TV, AC or Refrigerator)
-- A product can be purchased if there is enough money available in account for the
particular purchase operation, otherwise a message “You don’t have enough amount for
this operation” shall be displayed.
-- Product stock (for each product type) and account amount need to be updated after
each purchase
2. Sell: selling the product
Prototype: void(int quantity, int proce, int product_type)
-- Sell operation can be performed if there is enough quantity of the product available,
otherwise a message “Quantity not enough” shall display
-- Product stock (for each product type) and account amount need to be updated after
each purchase and sale
3. Display Stock; This function displays stock of each product
Prototype: void display_stock()
4. Business summary: this function displays the summary of the business including the
following
a. Current amount in account
b. Current product in stock value (purchasing value)
c. Profit/loss product wise (for each product)
Profit/loss can be calculated from the amount invested for total purchase and
total sale of each product category
d. Total Profit/loss of the company
Sum of profit/loss of all product category

Use appropriate variable (global, static etc.) and default arguments if needed
Call these functions in main with different values and validate.
Modification 1: modify the above program as follow and save as version Q2v1
a. Use global only if it is constant used in multiple functions or in case of variable if
access is required in all functions, otherwise use local variables (static if needed)
b. If a certain value need to be modified in a function, use call by reference

You might also like