IP Assignment FinalTerm

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Department of Computer Science

Faculty of Science and Technology


Introduction to Programming

Spring 2023-2024 Semester


Assignment No. 02 (Final-Term)
Marks: 100
Assignment On Pointer, Array, Function, Structure, and OOP

Part A- Structure [2 x 15=30]


1. Write a C++ program that will have a structure FlightTicket. Follow the given details to
create the structure.
Member variables and Methods Note
bookingID, ticketPrice,
Use proper data types for the attributes.
fromLocation, toLocation
Write parameterized method that will set values
Create a method to SetBooking
for bookingID and ticketPrice
Void setFlightPath(fromLocation, Use proper data types for the parameters. Set the
toLocation) values of Flight fromLocation and toLocation
void displayFlightInfo() Show all available information.

In main function create a variable of FlightTicket structure to book a flight using SetBooking
and use setFlightPath to set the locations. Finally, show the information of that flight ticket.
Note: Do not write any additional Setter and Getter Methods.

2. Create a structure named Student with the following member variables:


 Name (string): to store the student's name.
 ID (int): to store the student's roll number.
 Course_Name (String): to store the student's course.
 Mark (double): to store the student's marks for each course.

Create a method named inputStudentDetails() within the structure. This method should take
parameters to set the student's name, ID, Course_name, and mark. Create a method named
displayStudentDetails() within the structure. This method should display all the details of the
student. Print the student's name along with the unsatisfactory marks if the score is less than 55.
Write the student's name and an average mark if they received 55 to 79; otherwise, write an
outstanding mark and their name.
Part B: OOP [2 x 20=40]

1. Writea C++ Program that has a class named as Products and can store the
necessary information.
Member variables and
Instructions
Methods
productCode productName Use proper data types for member
price variables.
Create a Parameterized
Constructor
Create Setter and getter methods
void showProductsDetails() Display all the available information
Calculate and Return price with 15%
double getPriceWithVAT()
vat.
Write the main() function of the program. In the main(), create a product with
parameterized constructor and show the details of the product and price with VAT.

2. Output Tracing
#include<iostream>
using namespace std;
class Inventory{
private:
string ProductName;
double ProductPrice;
int quantity, flag = -1;
public:
static int ProductID;
static double InventoryPrice;
Inventory(){
cout<<"Current Price of Inventory: "<<InventoryPrice<<endl;}
Inventory(string PN, double pp, int qt){
flag=1; ProductName=PN;
ProductID+=10;
ProductPrice=pp; quantity=qt;
InventoryPrice=InventoryPrice+ProductPrice*qt;}
void RemoveProduct(int qt, double pp){
InventoryPrice=InventoryPrice-pp*qt; flag=0;}
void InventoryInfo(){
if(flag==0){
cout<<"Product Removed"<<endl;}
else if(flag>0){
cout<<"Product Added"<<endl;
cout<<"Product Name: "<<ProductName<<endl;
cout<<"Product ID: xY"<<ProductID<<endl;
cout<<"Product Price: "<<ProductPrice<<endl;
cout<<"Product Quantity: "<<quantity<<endl; }
}
~Inventory(){
if(InventoryPrice>2000){
cout<<"No Space Available"<<endl;}
else{
cout<<"Space Available"<<endl;} }
};
double Inventory::InventoryPrice=1200;
int Inventory::ProductID=101;
int main(){
Inventory P1; Inventory P2("Pringles",250,4);
P2.InventoryInfo();
Inventory P3;
P3.RemoveProduct(1,350);
P3.InventoryInfo();
}

Part-C Pointer & 1D Array [1 x 15 =15]


1. Output Tracing
#include <iostream>
using namespace std;
int main()
{
int arr[5] = {1, 2, 3, 4, 5}, sum=0;
int *p = arr;
for (int i = 0; i < 5; i++)
{

cout << *p << " ";


p++;
if (p == arr + 5)
{
p = arr;
cout<<endl;
}
}
for(int i = 0; i < 5; i++)
{
sum += *(arr+i);
}
cout<<"Sum value:"<<sum;
return 0;
}

Part-D: 2D Array & Function: [1 x 15=15]


Output Tracing
#include <iostream>
using namespace std;
int findMaxElement(int arr[][3], int rows, int cols) {
int maxElement = arr[0][0];
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
if (arr[i][j] > maxElement) {
maxElement = arr[i][j];
}
}
}
return maxElement;
}

int main() {
const int rows = 3;
const int cols = 3;
int array2D[rows][cols] = {{1, 2, 3},
{4, 5, 6},
{7, 8, 9}};
int maxElement = findMaxElement(array2D, rows, cols);
cout << "Maximum element in the 2D array: " << maxElement << endl;
return 0;
}

You might also like