Help me obiwon kenobi you my only hope C C C simple code ho
Help me obi-won kenobi, you my only hope! C++ C++ C ++ simple code homework question Please provide code. I will give thumbs up!! **Feel FREE to be Creative with this question**
Please comment for question. Please exlpain code and provide output!
Please use C++ to code. Will give thumbs up. Please follow my post carefully. Please provide c++ code and screenshot of output. Please provide comments describing program at a entry level.
Our college is holding a fund-raiser. The Computer Science Dept., English Dept., Math Dept., and the Nursing Dept. will compete to see which department raises the most money.
Your program must be designed using a Struct Class, Pointers, and three functions. A user should be able to add, update, and search for their contribution amount, and which department they wish to apply it to. (i.e cs $100.00).
Have a unique way to stop the program. Display on the screen the total contribution(s) made toward each department.
Make sure properly documentation your program.
Solution
#include <iostream>
#include <string>
using namespace std;
//structure Declaration
struct Department
{
string name;
double contribution;
};
//function to add department details
int add(struct Department *dept[10],string name, double contribution, int count)
{
dept[count]=new struct Department;
dept[count]->name=name;
dept[count]->contribution=contribution;
return ++count;
}
//function to search department
int search(struct Department *dept[10],string name,int count)
{
int pos=-1;
for(int i=0;i<count;i++)
{
if(dept[i]->name.compare(name)==0)
{
pos=i;
break;
}
}
return pos;
}
//function to display all department details
void display(struct Department *dept[10],int count)
{
cout<<endl<<\"Department \\t Contribution\";
for(int i=0;i<count;i++)
{
cout<<endl<<dept[i]->name<<\"\\t \\t \"<<dept[i]->contribution;
}
}
int main()
{
//structure pointer
struct Department *dept[10];
int choice;
string name;
double contribution;
int count=0;
int id;
while(1)
{
//menu
cout<<endl<<\"1.Add department\";
cout<<endl<<\"2.Update department\";
cout<<endl<<\"3.Search department\";
cout<<endl<<\"4.Display\";
cout<<endl<<\"5.Quit\";
cout<<endl<<\"Enter your choice: \";
cin>>choice;
cin.ignore();
switch(choice){
case 1:
cout<<endl<<\"Enter department name: \";
getline(cin,name);
cout<<endl<<\"Enter contribution: \";
cin>>contribution;
count=add(dept,name,contribution,count);
cout<<endl<<\"Department details added successfully\";
break;
case 2:
cout<<endl<<\"Enter department name to update: \";
getline(cin,name);
id=search(dept,name,count);
if(id!=-1)
{
cout<<endl<<\"Enter a new name to update: \";
cin>>name;
cout<<endl<<\"Enter new contribution: \";
cin>>contribution;
dept[id]->name=name;
dept[id]->contribution=contribution;
cout<<endl<<\"Details updated successfully\";
}
else
cout<<endl<<\"Department \"<<name <<\" is not found\";
break;
case 3:
cout<<endl<<\"Enter department name to search: \";
getline(cin,name);
id=search(dept,name,count);
if(id!=-1)
cout<<endl<<name <<\" is found and its contribution is $\"<<dept[id]->contribution;
else
cout<<endl<<\"Department \"<<name <<\" is not found\";
break;
case 4:
display(dept,count);
break;
case 5: exit(0);
}
}
return 0;
}


