-
#include <algorithm>
-
#include <iomanip>
-
#include <ios>
-
#include <iostream>
-
#include <string>
-
#include <vector>
-
using namespace std;
-
int main ()
-
{
-
cout <<" plz enter your first name: ";
-
string name;
-
cin>>name;
-
cout<<"Hello, "<<name<<"!"<<endl;
-
cout<<plz enter ur midterm and final exam grades: ";
-
double midterm, final;
-
cin>>midterm>>final;
-
cout<<"enter all ur homeworks grades, :
-
"followed by end-of-file: ";
-
vector<double> homework;
-
double x;
-
while (cin>>x)
-
homework.push_back(x);
-
typedef vector<double>::size_type vec_sz;
-
vec_sz size= homework.size();
-
if(size==0) {
-
cout<<endl<<"u must enter ur grades. "
-
"plz try again."<<endl;
-
return1; // does that mean if this statement fail it restart the if statement or the whole app
-
sort(homework.begin(), homework.end() );
-
vec_sz mid=size/2
-
double median;
-
median=size %2 ==0 ? (homework[mid]+homework[mid-1] /2
-
:homework[mid];
-
//isn't homework[mid]= to homework homework[size/2] which is how many numbers are contain in homework
-
//just how does it works don't very get it
-
streamsize prec=cout.precison(3)
-
<<0.2+midterm+0.4 *final+0.4*median//isn't median =size%2
-
<<setprecison(prec)< <end;
-
return0;
-
}
-
I have read the book seven times, but still don't get it.
I know it sounds fishy, but I very need ur help.
Ur voice are super important to me.
Plz lend me a hand
20 1952
What problems are you having? are you getting an error message.? A little more information please.
no i just don't understand the script. Plz help
#
return1; // does that mean if this statement fail it restart the if statement
line 28
line 32-34
#
median=size %2 ==0 ? (homework[mid]+homework[mid-1] /2
#
:homework[mid];
#
//isn't homework[mid]= to homework homework[size/2] which is how many numbers
and line 37
<<0.2+midterm+0 .4 *final+0.4*medi an//isn't median =size%2
no i just don't understand the script. Plz help
return1; // does that mean if this statement fail it restart the if statement
no no. I means that if no homeworks were inputed, stop the program. The return will break out of main. Basically shutting down your program.
median=size %2 ==0 ? (homework[mid]+homework[mid-1] /2
:homework[mid];
To take the median, you need to find the middle test. However, if there is an even number of tests, which one is the middle. Here's a visual example:
1 2 3 4 5 < the median is 3
1 2 3 4 < the median is (2 + 3)/2
This checks the size, if the size is even, do first command (between question mark and colon), if not, do what is after the colon. Basically it is a boolean if statement.
Hope that helped.
median=size %2 ==0 ? (homework[mid]+homework[mid-1] /2
:homework[mid];
sorry i still don't get it.
I get the non-pc version how to compute median.
Like if it is even divide the size /2
for example
10/2
the median will be 5 number +6 number /2
And the odd number is size/2
then the number to that is the median.
But the problem is isn't
median=size %2 ==0 ? (homework[mid]+homework[mid-1] /2
:homework[mid];
only calculate where is the median located ,but not the median itself???????
wow i must be slow 2 replies before i finished.
median will equal the value located in the homework vector
or it will equal the average of the two middle values in the homework vector.
Err don't quite get what do u mean by that.
Sorry about that.
okay
homework is a vector that contains doubles
if (size % 2 == 0) //there are an even number of grades
median = (homework[mid] + homework[mid-1] / 2) // (double + double) / 2
else // there are an odd number of grades
median = homework[mid] //equals the double value located in the middle of the vector
JosAH 11,448
Recognized Expert MVP
Maybe it's because it's Sunday overhere but I find this thread very chaotic.
Suppose the homework[] array is sorted in ascendng or descending order. Let the
number of elements in that homework[] array be 'n'.
There are just two cases:
1) n is odd; the median is homework[n/2];
2) n is even; the median is (homework[n/2]+homework[n/2+1])/2;
if n&1 == 1 then n is an odd number; there's not much more to it.
kind regards,
Jos
o so because size is vector double
Which means it actually contain the number itself and not how many numbers there is right???
It is Sunday, I know I am sorry for bugging u in Sunday.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: dpackwood |
last post by:
Hello,
I have two different scripts that do pretty much the same thing. The main
perl script is on Windows. It runs and in the middle of it, it then calls
out another perl script that then should run on a Unix box I have. Both
scripts run ok, except for the part when Windows try's to call out the
Unix script. I have it set up where the Unix is mapped through a drive
letter and can drop stuff into the Unix box. It is going through another...
|
by: hupjack |
last post by:
I finally joined the millions of cell phone users out there. I'm the 2nd
phone on what is now a family share plan. (Our two cell phones use minutes
from a central 400 minute peak time pool.)
Looking at the verizon wireless website, minutes used are displayed only as
two different totals for our 2 phones. Dialing in from a phones to check
remaining minutes, the minutes are presented the same way, broken down by
each phone but not...
|
by: Akbar |
last post by:
Hey there,
Big-time curiosity issue here...
Here's the test code (it's not that long)... it's to display a large
number of image links with captions, ideally pulled in from an
external file (that part's not here -- spotlighting the problem code):
--------BEGIN CODE PAGE------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
by: Johnny Knoxville |
last post by:
I've added a favicon to my site (http://lazyape.filetap.com/) which works
fine if you add the site to favourites the normal way, but I have some
JavaScript code on a couple of pages with a link, which when you click it
bookmarks the site (much easier). The favicon is never saved if the site
is bookmarked this way. Does anyone have any ideas how to fix this??
This is the code:
<script language="JavaScript">
|
by: Derek |
last post by:
I have the following script in a page and it gets an error in IE 6. Says
something about an invalid
argument but the line number doesn't help since I can't see the javascript
code when viewing source.
I have this script in a popup page where the user selects a user ID (id) and
that value is then placed
into one of the parent window's form text field called "userId". This
script works fine in the latest
Mozilla and Mozilla Firefox but...
| |
by: ZMan |
last post by:
Scenario:
This is about debugging server side scripts that make calls to
middle-tier business DLLs. The server side scripts are legacy ASP 3.0
pages, and the DLLs are managed DLLs converted/developed with VB.NET.
What I want from debugging is to be able to step into the methods in
the DLLs called from ASP scripts using Visual Studio .NET.
Background:
For typical script debugging issues, you can read and follow the two
documents on...
|
by: Harry Smith |
last post by:
While reading the documentation on IsStartupScriptRegistered, there is a
reference to "client startup script" as "Determines if the client startup
script is registered with the Page object."
What is meant by "Client Start Script"?
Thanks,
Harry
|
by: Angus |
last post by:
I have a web page with a toolbar containing a Save button. The Save
button can change contextually to be a Search button in some cases.
Hence the button name searchsavechanges.
The snippet of html is:
<a class="searchsavechanges btn btn3d tbbtn" href="javascript:"
style="position:static">
<div id="TBsearchsavechanges">Search</div>
</a>
|
by: David |
last post by:
On Sun, May 4, 2008 at 4:43 AM, lev <levlozhkin@gmail.comwrote:
Hi, I started tidying up the script a bit, but there are some parts I
don't understand or look buggy. So I'm forwarding you the version I
have so far. Look for the comments with my e-mail address in them for
more information.
If I have time I'll tidy up the script some more when I have more info
about those issues.
|
by: KevinADC |
last post by:
Note: You may skip to the end of the article if all you want is the perl code.
Introduction
Many websites have a form or a link you can use to download a file. You click a form button or click on a link and after a moment or two a file download dialog box pops-up in your web browser and prompts you for some instructions, such as “open” or “save“. I’m going to show you how to do that using a perl script.
What You Need
Any recent...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |