Hello, I need to divide my code in this different parts.
Use a standard approach to source files in this assignment: a .cpp for each function (you have at least two – main and ageCalc) a header file for the student struct, properly guarded
Code:
#include <iostream>
#include <string>
#include <fstream>
#include <algorithm>
#include <vector>
#include <iomanip>
using namespace std;
#define nullptr NULL
#define MAX_SIZE 100
struct Student
{
string firstName;
char middleName;
string lastName;
char collegeCode;
int locCode;
int seqCode;
int age;
};
struct sort_by_age
{
inline bool operator()(const Student *s1, const Student *s2)
{
return (s1->age < s2->age);
}
};
int ageCalc(Student *studs[], Student *&youngest);
int main()
{
Student *students[MAX_SIZE] = {nullptr};
ifstream Myfile;
Myfile.open("a2data.txt");
if (!Myfile.is_open())
{
cout << "Could not open the file!";
return 1;
}
vector<string> words;
string line;
while (!Myfile.eof())
{
getline(Myfile, line);
line.c_str();
int i = 0;
string word = "";
while (line[i] != '\0')
{
if (line[i] != ' ')
{
word = word + line[i];
i++;
}
else
{
if (word != "")
words.push_back(word);
word = "";
i++;
}
}
words.push_back(word);
}
Myfile.close();
int count = 0;
string fname = words.at(count);
count++;
int n = 0;
while (count < words.size() - 2)
{
Student *s = new Student;
s->firstName = fname;
string mname = words.at(count);
s->middleName = mname[0];
count++;
s->lastName = words.at(count);
if (words.at(count).size() >= 12)
{
if (words.at(count)[1] >= '0' && words.at(count)[1] <= '9')
{
count--;
s->middleName = ' ';
s->lastName = words.at(count);
}
}
count++;
string id = words.at(count);
count++;
s->collegeCode = id[0];
string loc = "";
loc = loc + id[1];
loc = loc + id[2];
s->locCode = stoi(loc);
string seq = "";
for (int j = 3; j < 9; j++)
{
seq = seq + id[j];
}
s->seqCode = stoi(seq);
string age = "";
age = age + id[9];
age = age + id[10];
age = age + id[11];
s->age = stoi(age);
fname = id.erase(0, 12);
students[n] = s;
n++;
}
words.clear();
sort(students, students + n, sort_by_age());
cout << setw(15) << left << "Last Name";
cout << setw(15) << left << "Midlle Name";
cout << setw(15) << left << "First Name";
cout << setw(15) << left << "College Code";
cout << setw(12) << left << "Location";
cout << setw(12) << left << "Sequence";
cout << setw(12) << left << "Age" << endl;
cout << "=======================================================================================" << endl;
for (int i = 0; i < n; i++)
{
cout << setw(15) << left << students[i]->lastName;
cout << setw(15) << left << students[i]->middleName;
cout << setw(20) << left << students[i]->firstName;
cout << setw(13) << left << students[i]->collegeCode;
cout << setw(10) << left << students[i]->locCode;
cout << setw(12) << left << students[i]->seqCode;
cout << students[i]->age << endl;
}
cout << endl;
Student *youngest = NULL;
int avg_age = ageCalc(students, youngest);
cout << "Average age is: " << avg_age << endl;
cout << "Youngest student is " << youngest->firstName << " " << youngest->middleName << " " << youngest->lastName << endl;
return 0;
}
int ageCalc(Student *studs[], Student *&youngest)
{
youngest = studs[0];
int i = 0;
int avg_age = 0;
while (studs[i] != NULL)
{
avg_age += studs[i]->age;
if (youngest->age > studs[i]->age)
youngest = studs[i];
i++;
}
return avg_age / i;
}
File needed:
https://drive.google.com/file/d/15_CxuGnFdnyIj6zhSC11oSgKEYrosHck/view?usp=sharing
In: Computer Science
Describe the matrices and formulae used to determine centralization or distribution of data. In the absence of subjective reasoning, would the matrices and formulae lead to a rational decision? Why or why not?
Develop all of the distribution matrices and subjective reasoning for/against distribution, for the problem chosen in Unit 3 (from Appendix). Develop recommendations and explain your reasoning for each choice
In: Computer Science
Make a python code.
Write a function named max that accepts two integer values as arguments and returns the value that is the greater of the two. For example, if 7 and 12 are passed as arguments to the function, the function should return 12. Use the function in a program that prompts the user to enter two integer values. The program should display the value that is the greater of the two. Write the program as a loop that continues to prompt for two numbers, outputs the maximum, and then goes back and prompts again
Here’s an example of program use
Input the first number: 10
Input the second number: 5
The maximum value is 10
Run again? yes
Input the first number: -10
Input the second number: -5
The maximum value is -5
Run again? no
Function max():
Obtain two numbers as input parameters: max(num1, num2):
if num1 > num2 max_val = num1, else max_val = num2
return max_val
Main Program:
Initialize loop control variable (continue = ‘y’)
While continue == ‘y’
Prompt for first number
Prompt for second number
Call function “max,” sending it the values of the two numbers, capture result in an assignment statement:
max_value = max (n1, n2)
Display the maximum value returned by the function
print(‘Max =’, max_val)
Ask user for if she/he wants to continue (continue = input(‘Go again? y if yes’)
In: Computer Science
IST 411
In: Computer Science
>>> flipSwitches( ['A','A','a','B'] )
{'B'}
>>> flipSwitches( 'ABCba')
{'C'}
>>> flipSwitches( 'sdfjSDSDFasjjfdjldsSDF' )=={'S', 'D', 'F'}
True
use python 3.7
In: Computer Science
Q1) What is the difference between IP address and MAC address for a computer?
Q2) What is the difference between Internet (with I capital letter) and internet (with i small letter)?
Q3) What is the difference between network and internet in general?
In: Computer Science
Given the code segment:
def f1(a, b = 2):
if a :
print(1)
f1(1)
what is the result of executing the code segment?
a) Syntax error
b) Runtime error
c) No error
d) Logic error
in which scenario(s) is using a dictionary useful?
a) To store the dates of lesson that each student is absent for so that warning letters may be issued to student exceeding a limit.
b) To store the student numbers for students who sat for an exam
c) To retrieve email of students who are absent for an exam. The student numbers will be entered into the recipient field and the system should display the student email.
d) The marks should be entered into the exam system. The exam system displays rows of student number, and the marks can be entered against the student number. The grade will be computed and reflected in the student row .
which expression returns True when a number, x is not and odd number between 1 (inclusive) and 100 (inclusive), and returns False otherwise?
a) x not in range(100) and x % 2 !=0
b) x not in range(1,101) and x % 2 !=0
c) not( x in range(1,101) and x % 2 1=0
d) x not in range(1,101) or x % 2 !=0
In: Computer Science
Hi, i'm creating a c++ program with a linked list of Employees, i'm running into issues as far as displaying programmers only portion and the average salary of all the employees. Please make any changes or comments !
Employee.h file:
#ifndef EMPLOYEE_H
#define EMPLOYEE_H
#include
using namespace std;
enum Role {programmer, manager, director};
struct Employee
{
std::string firstName;
std::string lastName;
int SSN;
std::string department;
double salary;
Role role;
};
#endif
#ifndef NODE_H
#define NODE_H
Node.h file:
#include "Employee.h"
typedef Employee EMP;
struct Node
{
EMP e;
Node * next;
Node();
Node(EMP);
Node(EMP,Node* next);
};
Node::Node()
{
next=NULL;
}
Node::Node(EMP e_data)
{
e=e_data;
}
Node::Node(EMP e_data, Node* next)
{
e=e_data;
this->next= next;
}
#endif
Main cpp file:
#include <iostream>
#include <cstdlib>
#include <ctime>
#include "Employee.h"
#include "Node.h"
using namespace std;
void setSalary (Employee& emp)
{
emp.salary= 45000+rand() %20000; // generates salary for employee
}
void setRoles(Employee& emp)
{
emp.role = static_cast(rand()%3); // gives employee job title
}
void setSSN (Employee& emp)
{
// int y = x;
emp.SSN =rand()%499999999+400000000; // sets employee SSN
}
void setFirst( Employee& emp, string* name)
{
int y = rand()%5;
emp.firstName = name[y]; //gives random first name
}
void setLast(Employee& emp, string* name)
{
int y = rand()%5;
emp.lastName = name[y]; // gives random last name
}
void setDepartment(Employee& emp, string * dep)
{
int y = rand()%3;
emp.department= dep[y]; //gives employee random department
}
int main()
{
srand(time(NULL)); // random number generator
double avgSalary; // initialize Average Salary
Node* head= NULL; // starting node
Node* prev= NULL; // node next to the last one
Employee e; // object instance
// array of names, roles(job titles), and departments
string roleType [3] = {"programmer", "manager", "director"};
string firstName[5] = {"John", "James", "Joe", "Jessica", "Juno" };
string lastName[5] = {"Smith", "Williams", "Jackson", "Jones", "Johnson" };
string department[5]= {"Accounting", "IT", "Sales" };
// Create linked list of employees
for (int i = 0; i<10; i++)
{
Employee e;
// function calls (roles, salary ...etc)
setFirst(e, firstName);
setLast(e, lastName);
setSSN(e);
setSalary(e);
setRoles(e);
setDepartment(e, department);
// creates nodes for employees
Node*temp = new Node(e);
if (i ==0)
{
head=temp;
prev= temp;
}
else
{
prev->next= temp;
prev = temp; // links the nodes together
}
}
// Display information of all Employees
cout<<"======== Employee Data======="<
prev = head; // starting at the first node
while(prev !=NULL)
{
cout<<(prev->e).firstName<< " ";
cout<<(prev->e).lastName<< " ";
cout<<(prev->e).SSN<< " ";
cout<<(prev->e).salary<< " ";
cout<<(prev->e).department<< " ";
cout
prev= prev->next;
}
cout<<" \n \n";
//
cout<<"======== Programmer Only Data======="<
prev = head; // starts at beginning of linked list
while(prev !=NULL)
{
if (prev->e.role == 0) // checks to see if role is 0 or programmer
cout<<(prev->e).firstName<< " ";
cout<<(prev->e).lastName<< " ";
cout<<(prev->e).SSN<< " ";
cout<<(prev->e).salary<< " ";
cout<<(prev->e).department<< " ";
cout
prev= prev->next; // moves on to next node
// else {
// break;
// }
}
//Computes Average Salary
prev = head; // starts at the first node
while ( prev !=NULL)
{
avgSalary += (prev->e).salary;
prev = prev->next;
}
// Display Average Salary
cout<< "Average Salary: "<< (avgSalary)/5 << "\n";
// Deallocate memory
Node* temp = head;
Node* tail;
while (temp !=NULL)
{
tail=temp->next;
delete temp;
temp = tail;
}
head=NULL;
if (head == NULL )
{
cout<<" List Deleted \n";
}
}
In: Computer Science
In: Computer Science
Please follow the instructions carefully and complete the code given below.
Language: Java
Instructions from your teacher:
(This is a version of an interview question I once saw.) In this problem, we will write a program that, given an integer k, an integer n, and a list of integers, outputs the number of pairs in in the list that add to k.
To receive full credit for design, your algorithm must have a runtime in O(n) , where n is the length of the list of integers. Hint: you can assume that the contains in a HashSet is O(1). Your program should take as input a number k on its own line, followed by a number n on its own line, followed by a space-separated list of n integers. It should then output the number of pairs in the list that add to k. Order does not matter when considering a pair (in other words, in the list [2,1] there is one distinct pair that sums to 3, not two). You may assume that all numbers in the input are distinct. For example, if our file input.txt is:
1
6
1 2 3 4 -2 -3
then we should print 2 since there are two pairs that sum to 1: 3 + (-2) and 4 + (-3).
As another example, if input.txt is:
3
4
1 2 3 4
then we should print 1since there is one pair that sums to 1: 1+2.
The problem PairFinder provides starter code for reading and printing; your task is to fill in thefindPairs()method.
.......................................................................................................................
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Read in the value of k
int k = Integer.parseInt(sc.nextLine());
// Read in the value of n
int n = Integer.parseInt(sc.nextLine());
// Read in the list of numbers
int[] numbers = new int[n];
String input = sc.nextLine();
if (input.equals("")) {
numbers = new int[0];
} else {
String[] numberStrings = input.split(" ");
for (int i = 0; i < n; i++) {
numbers[i] = Integer.parseInt(numberStrings[i]);
}
}
System.out.println(findPairs(numbers, k));
}
private static int findPairs(int[] numbers, int k) {
// TODO fill in this function
throw new UnsupportedOperationException();
}
}
In: Computer Science
1.Sage 50 is an integrated system give examples?
2. Enumerate the capacities of sage 50.
In: Computer Science
I have to modify the following code to:
1. Use the unique algorithm to reduce the array to unique values
2. Use the copy algorithm to display the unique results.
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
//creating an array of 20 integers
int array[20];
//creating an empty vector
vector<int> vec;
//input from end user to get 20 ints and a for loop to interate through 20
cout << "Enter 20 integers:" << endl;
for (int i = 0; i < 20; i++) {
cin >> array[i];
}
//sorting them
sort(array, array + 20);
//using unique_copy algorithm and a back_inserter, copying and adding each
//unique value from the array to vector
unique_copy(array, array + 20, back_inserter(vec));
//displaying the unique values.
cout << "The unique values are: " << endl;
for (int i = 0; i < vec.size(); i++) {
cout << vec[i] << " ";
}
cout << endl;
return 0;
In: Computer Science
Do the problems found week 4 - Programs 1,2,3,4,5,6 and 7.
* Be sure to add your name as a cout in the first lines of each program - else 0 credit.
* Add constructors - a default and parameterized constructor to each.
* Write an .h interface and a .cpp implementation for each class
* Write an Drive/Test file that tests the constructors and functions
* Write a UML class diagram for each class\!!!!!!
Program 6
#include<iostream>
using namespace std;
class Box
{
public:
Box() {
Length = 0;
Width = 0;
Height = 0;
}
double Length;
double Width;
double Height;
double Volume();
double SurfaceArea();
void setWidth ( double n ) {Width = n;}
void setDepth ( double n ) {Length = n;}
void setHeight ( double n ) {Height = n;}
double getWidth () {return Width;}
double getHeight () {return Height;}
double getDepth () {return Length;}
double calcArea () {return 2*(Length*(Width+Height)+Width*Height);}
double calcVolume () {return Length*Width*Height;}
};
int main() {
cout<<"-------- ";
Box B1;
B1.setWidth(2);
B1.setDepth(4);
B1.setHeight(9);
cout << "Height = " << B1.getHeight() << endl;
cout << "Area = " << B1.calcArea() << endl;
cout << "Volume = " << B1.calcVolume() << endl;
Box B2;
B2.setWidth(3);
B2.setDepth(5);
B2.setHeight(10);
cout << "Height = " << B1.getHeight() << endl;
cout << "Area = " << B1. calcArea() << endl;
cout << "Volume = " << B1.calcVolume() << endl;
}
program 7
#include <iostream>
using namespace std;
int main() {
/*
* Circumference = π × diameter = 2 × π × radius
* Area : π r²
* Diameter : 2r
*/
cout<< "Name: "<< endl;
double radius = 0;
cout << "Enter radius of circle: ";
cin >> radius;
if (radius <= 0) {
cout << "Please Enter radius greater than zero" << endl;
return 0;
}
double pie = 22/7.0;
double circumference = 2 * pie * radius;
double area = pie * radius * radius;
double diameter = 2 * radius;
cout << "Circumference of Circle:" << circumference << endl;
cout << "Area of Circle:" << area << endl;
cout << "Diameter of Circle:" << diameter << endl;
cout << "Radius of Circle:" << radius << endl;
return 0;
}
program 2
#include <iostream>
#include <string>
using namespace std;
class myClass{
public:
void setName(string x){
name = x ;
}
string getName(){
return name;
}
private:
string name;
};
int main()
{
cout<<"----";
myClass to;
to.setName("stuff are cool ");
cout << to.getName();
return 0;
}
In: Computer Science
Write a code on C++ to find prime number series.
In: Computer Science
1. What is a Python script?
2. Explain what goes on behind the scenes when your computer runs a Python program.
In: Computer Science