Consider the scenorio in which a colleg\'s percent budget increase is determined
ID: 3586610 • Letter: C
Question
Consider the scenorio in which a colleg's percent budget increase is determined by the number of student who graduated the prior year. create a console application that prompts the user for the number of graduated students and old budget for specific college. use the number of graduated students to determine the annual budget percentage increase, then calculate the new budget in dollars. the program must run all of the lited test cases of number of graduated students and new budget in one execution. use an array to store the input values. assume that the maximum number of graduated students is 1500. the number of graduated students must be greater than or equal to zero. if less than zero, reprompt for that number again.
Run your application with the following data
#Students ____________old budget
250__________________$700,000
-300 replace with 501 ____$650,000
1001_________________ $850,000
1501 _________________$1,200,000
251 __________________$1,000,000
make sure it's in c#
Explanation / Answer
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace college
{
//
//int MAX_YEARS = 5;
//
class collegeBudget
{
//
int[] studentsGraduated = new int[5]; // this array shall hold number of students graduated for each of the 5 years, to increase number of years, change 5
//
double[] oldBudget = new double[5]; // array holds old budget for the 5 years
//
double[] newBudget = new double[5]; // array holds the new calculated budget based upon the increase/decrease in students graduated over last year
//
public collegeBudget()
{
// empty default constructor
}
//
// public method that fills up information for a particular year
public void fillCollegeData(int students, double oldbudget, int yearIndex)
{
//
studentsGraduated[yearIndex] = students;
//
oldBudget[yearIndex] = oldbudget;
}
//
public void calculateBudgetChange()
{
//
int i,oldstudentcount, presentstudentcount, riseFlag = 0, fallFlag = 0;
//
double oldbudget, newbudget, percentageChange;
//
// we start calculating from the second year as the first year does not have any prior student data
for(i = 1; i < 5; i++)
{
//
oldstudentcount = studentsGraduated[i - 1]; // get the number of students graduated last year
//
presentstudentcount = studentsGraduated[i]; // get number of students graduated this year
//
oldbudget = oldBudget[i]; // get this year's old budget to calculate new budget
//
if (presentstudentcount > oldstudentcount)
{
//
percentageChange = (((double)presentstudentcount - (double)oldstudentcount) / (double)oldstudentcount) * 100; // find by what percent have students graduated this year increased
//
newbudget = (double)oldbudget + ((double)percentageChange / 100) * (double)oldbudget; // calculate the new budget based on the pecent increase in students graduated this year
//
newBudget[i] = newbudget; // store the new budget for this year
}
//
else
{
//
percentageChange = (((double)oldstudentcount - (double)presentstudentcount) / (double)oldstudentcount) * 100;
//
newbudget = (double)oldbudget - ((double)percentageChange / 100) * (double)oldbudget;
//
newBudget[i] = newbudget;
}
}
}
//
public void printEstimateData()
{
int i;
//
Console.WriteLine("Year || Students || Old Budget || New Budget");
//
for(i = 0; i < 5; i++)
{
//
Console.WriteLine("{0} {1} {2} {3}", i, studentsGraduated[i], oldBudget[i], newBudget[i]);
}
}
}
class Program
{
static void Main(string[] args)
{
//
int i, students;
//
double oldbudget;
//
collegeBudget collegeData = new collegeBudget();
//
for (i = 0; i < 5; i++)
{
//
Console.WriteLine("Enter number of students graduated : ");
///
students = Convert.ToInt32(Console.ReadLine());
//
while(students <= 0)
{
//
Console.WriteLine("Enter number of students graduated : ");
///
students = Convert.ToInt32(Console.ReadLine());
}
//
Console.WriteLine("Enter old budget : ");
//
oldbudget = Convert.ToDouble(Console.ReadLine());
//
collegeData.fillCollegeData(students, oldbudget, i);
}
//
collegeData.calculateBudgetChange();
//
collegeData.printEstimateData();
}
}
}
//---------- OUTPUT -------------//