-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpracticep11.cpp
More file actions
69 lines (60 loc) · 1.6 KB
/
practicep11.cpp
File metadata and controls
69 lines (60 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Problem Statement
// Preethi runs a small shop and wants to calculate the total cost of items based on their quantity.
// Write a program that helps Preethi by implementing a class Item with inline methods to
// set item details (number and cost) and to calculate the total cost.
// The program should read item details and quantity from the user, and then display the total cost.
#include <iostream>
using namespace std;
class Item{
public:
int inum=0;
float icost=0.0;
int q;
inline void setitem(int num,float cost,int qu){
inum=num;
icost=cost;
q=qu;
}
inline void tcost(){
float cc=0;
cc=q*icost;
printf("Total cost: %.2f",cc);
}
};
int main(){
Item i1;
int a,c;
float b;
cin>>a;
cin>>b;
cin>>c;
i1.setitem(a,b,c);
i1.tcost();
}
//2nd program
// Write a program that reads the number of participants and their details (ID and name) for an event.
// Implement a class Event to store participant information and keep track of the total number
// of participants using a static member variable.
// The program should display the total number of participants at the end.
#include <iostream>
using namespace std;
class Event{
public:
static int count;
int id=0;
string name="";
};
int Event::count;
int mainn(){
Event e1;
int k;
cin>>k;
for(int i=1;i<=k;++i){
int idd;
string namee;
cin>>idd;
cin>>namee;
e1.count++;//or make a separate function inside event for adding.
};
cout<<"Total Participants: "<<e1.count;
};